You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
489 lines
14 KiB
489 lines
14 KiB
function postPhoto(data){
|
|
if (data.success){
|
|
window.location.reload();
|
|
}
|
|
else{
|
|
console.log(data);
|
|
}
|
|
|
|
}
|
|
|
|
function postHall(data){
|
|
if (data.success){
|
|
window.location.reload()
|
|
}
|
|
else{
|
|
console.log(data);
|
|
}
|
|
}
|
|
|
|
function deleteHall(data){
|
|
if (data.success){
|
|
window.location.reload();
|
|
}
|
|
else{
|
|
console.log(data);
|
|
}
|
|
}
|
|
|
|
function deletePhoto(data){
|
|
if (data.success){
|
|
window.location.reload();
|
|
}
|
|
else{
|
|
console.log(data);
|
|
}
|
|
}
|
|
function postSuccess(data, textStatus, jqXHR){
|
|
|
|
console.log(data);
|
|
//$('#close').click();
|
|
|
|
if (data.indexOf("<form")+1){
|
|
$('#form_body').html(data);
|
|
}
|
|
else
|
|
{
|
|
$('#file_list table tbody').html(data);
|
|
$('#close').click();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//function for progress bar
|
|
function progressHandlingFunction(e){
|
|
if(e.lengthComputable){
|
|
$('progress').attr({value:e.loaded,max:e.total});
|
|
}
|
|
}
|
|
|
|
function removeTimeTable(data, obj){
|
|
console.log(data);
|
|
console.log(obj);
|
|
obj.parent().remove();
|
|
if ('id' in data){
|
|
console.log('success')
|
|
}
|
|
else{
|
|
console.log('error')
|
|
}
|
|
}
|
|
|
|
function postTimetable(data, textStatus){
|
|
|
|
if (data instanceof Object){
|
|
console.log(data);
|
|
$.each(data, function(field_name, errors){
|
|
$('#id_'+field_name).parent().parent().addClass('error');
|
|
})
|
|
}
|
|
else{
|
|
$('#timetable_wrap table tbody').html(data);
|
|
$('#timetable_form')[0].reset();
|
|
$('#timetable_form .control-group').removeClass('error');
|
|
$('#close_timetable').click();
|
|
}
|
|
}
|
|
|
|
function postStat(data, textStatus){
|
|
if(data.success){
|
|
location.reload;
|
|
}
|
|
else{
|
|
$.each(data.errors, function(field_name, errors){
|
|
$('#id_'+field_name).parent().parent().addClass('error');
|
|
})
|
|
}
|
|
/*
|
|
if (data instanceof Object){
|
|
$.each(data, function(field_name, errors){
|
|
$('#id_'+field_name).parent().parent().addClass('error');
|
|
})
|
|
}
|
|
else{
|
|
$('#stat_modal table tbody').html(data);
|
|
$('#stat_form')[0].reset();
|
|
$('#stat_form .control-group').removeClass('error');
|
|
$('#close_stat').click();
|
|
}
|
|
*/
|
|
}
|
|
|
|
|
|
$(document).ready(function(){
|
|
|
|
$('#photo_form').on('submit', function(e){
|
|
e.preventDefault();
|
|
var url = $(this).attr('action');
|
|
var fileData = new FormData($(this)[0]);//file (request.FILES)
|
|
var formData = $(this).serialize();// another data (request.POST)
|
|
$.ajax({
|
|
url: url, //server script to process data
|
|
type: 'POST',
|
|
|
|
//Ajax events
|
|
success: postPhoto,
|
|
error: function(){ alert('error'); },
|
|
// Form data
|
|
data: (formData, fileData),
|
|
//Options to tell JQuery not to process data or worry about content-type
|
|
cache: false,
|
|
contentType: false,
|
|
processData: false
|
|
});//end ajax
|
|
});
|
|
|
|
|
|
$('#hall_form').on('submit', function(e){
|
|
e.preventDefault();
|
|
var url = $(this).attr('action');
|
|
var formData = $(this).serialize();
|
|
$.post(url, formData, postHall);
|
|
});
|
|
$('.delete-hall').on('click', function(e){
|
|
e.preventDefault();
|
|
var url = $(this).attr('href');
|
|
$.get(url, deleteHall);
|
|
});
|
|
$('.delete-photo').on('click', function(e){
|
|
e.preventDefault();
|
|
var url = $(this).attr('href');
|
|
$.get(url, deletePhoto);
|
|
});
|
|
|
|
$('.delete_file').click(function(e){
|
|
e.preventDefault()
|
|
var url = '/admin/ajax_delete_file/';
|
|
$this = $(this);
|
|
$.get(
|
|
url, {'id': $(this).attr("value")}, function(j){
|
|
if (j = 'success'){
|
|
$this.parent().parent().remove();
|
|
}
|
|
else{
|
|
console.log('error');
|
|
}
|
|
});//end get
|
|
});//end delete
|
|
|
|
$('#file_form').submit(function(e){
|
|
e.preventDefault();
|
|
console.log('123');
|
|
|
|
var fileData = new FormData($(this)[0]);//file (request.FILES)
|
|
var formData = $(this).serialize();// another data (request.POST)
|
|
var url = '/admin/ajax_post_file/'+$('#obj_id').val()+'/';
|
|
|
|
console.log(url);
|
|
|
|
$.ajax({
|
|
url: url, //server script to process data
|
|
type: 'POST',
|
|
xhr: function() { // custom xhr
|
|
var myXhr = $.ajaxSettings.xhr();
|
|
if(myXhr.upload){ // check if upload property exists
|
|
myXhr.upload.addEventListener('progress',progressHandlingFunction, false); // for handling the progress of the upload
|
|
}
|
|
return myXhr;
|
|
},
|
|
//Ajax events
|
|
success: postSuccess,
|
|
error: function(){ alert('error'); },
|
|
// Form data
|
|
data: (formData, fileData),
|
|
//Options to tell JQuery not to process data or worry about content-type
|
|
cache: false,
|
|
contentType: false,
|
|
processData: false
|
|
});//end ajax
|
|
|
|
|
|
});//end submit
|
|
|
|
//------------------on of events----------------
|
|
$('.on').click(function(){
|
|
var url = $(this).attr('href')
|
|
var $this = $(this)
|
|
$.get(
|
|
url, function(data){
|
|
if (data == 'on'){
|
|
$this.hide();
|
|
$this.siblings('.off').show();
|
|
}
|
|
});//end get
|
|
return false;
|
|
});
|
|
|
|
$('.off').click(function(){
|
|
var url = $(this).attr('href')
|
|
var $this = $(this)
|
|
$.get(
|
|
url, function(data){
|
|
if (data == 'off'){
|
|
$this.hide();
|
|
$this.siblings('.on').show();
|
|
}
|
|
}
|
|
)
|
|
return false;
|
|
});
|
|
// end on-of events
|
|
|
|
$('select').select2({
|
|
width: 'element',
|
|
allowClear: true
|
|
|
|
});//end select
|
|
|
|
|
|
|
|
$('#id_city').select2({
|
|
placeholder: "Город",
|
|
width: 'element',
|
|
ajax: {
|
|
|
|
url: "/admin/city/search/",
|
|
dataType: "json",
|
|
quietMillis: 200,
|
|
|
|
data: function(term, page, country){
|
|
var country = $('#id_country').val()
|
|
return {term: term,
|
|
page: page,
|
|
country: country};
|
|
},
|
|
|
|
results: function (data) {
|
|
var results = [];
|
|
$.each(data, function(index, item){
|
|
results.push({
|
|
id: item.id,
|
|
text: item.label
|
|
});
|
|
});
|
|
return {results: results};
|
|
}
|
|
},
|
|
initSelection : function(element, callback) {
|
|
var id= $(element).val();
|
|
var text = $(element).attr('data-init-text');
|
|
callback({id: id, text:text});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
$('#id_main_page_news').select2({
|
|
placeholder: "Новости",
|
|
multiple: true,
|
|
width: '100%',
|
|
ajax: {
|
|
|
|
url: "/admin/ajax/get-news/",
|
|
dataType: "json",
|
|
quietMillis: 200,
|
|
data: function(term, page){
|
|
|
|
return {term: term,
|
|
page: page};
|
|
},
|
|
|
|
results: function (data) {
|
|
var results = [];
|
|
$.each(data, function(index, item){
|
|
results.push({
|
|
id: item.id,
|
|
text: item.label
|
|
});
|
|
});
|
|
return {results: results};
|
|
}
|
|
},
|
|
initSelection : function(element, callback) {
|
|
var text = $(element).attr('data-init-text');
|
|
var data = $.parseJSON(text);
|
|
console.log(data);
|
|
/*
|
|
var data = [];
|
|
$(element.val().split(",")).each(function(i) {
|
|
var item = this.split(':');
|
|
data.push({
|
|
id: item[0],
|
|
text: item[1]
|
|
});
|
|
});
|
|
console.log(data)
|
|
*/
|
|
callback(data);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
// selects
|
|
$('#id_tag').select2({
|
|
placeholder: "Теги",
|
|
width: '550px',
|
|
multiple: true,
|
|
ajax: {
|
|
|
|
url: "/admin/theme/tag/search/",
|
|
dataType: "json",
|
|
quietMillis: 200,
|
|
multiple: true,
|
|
|
|
data: function(term, page, theme){
|
|
var theme = $('#id_theme').serialize();
|
|
return {term: term,
|
|
page: page,
|
|
theme: theme};
|
|
},
|
|
|
|
results: function (data) {
|
|
var results = [];
|
|
$.each(data, function(index, item){
|
|
results.push({
|
|
id: item.id,
|
|
text: item.label
|
|
});
|
|
});
|
|
return {results: results};
|
|
}
|
|
},
|
|
initSelection : function(element, callback) {
|
|
var data = [];
|
|
$(element.val().split(",")).each(function(i) {
|
|
var item = this.split(':');
|
|
data.push({
|
|
id: item[0],
|
|
text: item[1]
|
|
});
|
|
});
|
|
callback(data);
|
|
|
|
}
|
|
|
|
});
|
|
// end selects
|
|
/*
|
|
*/
|
|
// theme change
|
|
$('#id_theme').change(function(){
|
|
$.get(
|
|
"/admin/ajax_tag/", {'id': $(this).serialize()}, function(data){
|
|
var optionValues = [];
|
|
var getValues = [];
|
|
var selectedValues = []
|
|
//push values sended from server in array
|
|
$.each(data, function(i, elem){
|
|
getValues.push(elem[0].toString())
|
|
});
|
|
//delete options if they aren't in getvalues
|
|
//otherwise push it in array
|
|
//also push in array already selected values
|
|
$('#id_tag option').each(function() {
|
|
var check = $.inArray($(this), getValues);
|
|
if ($(this).is(':selected') ){
|
|
selectedValues.push($(this).val())
|
|
}
|
|
if (check == -1){
|
|
$(this).remove()
|
|
}
|
|
else{
|
|
optionValues.push($(this).val());
|
|
}
|
|
});
|
|
//generate new options
|
|
//old options unchanged
|
|
var html = ''
|
|
$.each(data, function(i, elem){
|
|
var check = $.inArray(elem[0].toString(), optionValues);
|
|
|
|
if (check == -1){
|
|
html += '<option value="';
|
|
html += elem[0];
|
|
html += '">';
|
|
html += elem[1];
|
|
html += '</option>';
|
|
}
|
|
});
|
|
$('#id_tag').append(html);
|
|
//select previous selected values
|
|
$('#id_tag option').each(function() {
|
|
var check = $.inArray($(this).val(), selectedValues)
|
|
if (check != -1){
|
|
$(this).attr('selected', 'selected');
|
|
}
|
|
});
|
|
});//end get
|
|
});//end change
|
|
|
|
$('#stat_form').on('submit', function(e){//submit(function(){
|
|
e.preventDefault();
|
|
var url = '/admin/ajax_post_stat/' + $('#obj_id').val() + '/';
|
|
console.log(url)
|
|
var formData = $(this).serialize();
|
|
|
|
$.ajax({
|
|
url: url, //server script to process data
|
|
type: 'GET',
|
|
|
|
//Ajax events
|
|
success: postStat,
|
|
error: function(){ alert('error'); },
|
|
// Form data
|
|
data: formData,
|
|
//Options to tell JQuery not to process data or worry about content-type
|
|
cache: false,
|
|
contentType: false,
|
|
processData: false
|
|
});//end ajax
|
|
|
|
}); // end submit
|
|
|
|
$('#timetable_form').on('submit', function(e){//submit(function(){
|
|
e.preventDefault();
|
|
tinyMCE.triggerSave();
|
|
var formData = $(this).serialize();
|
|
if ($('#obj_id').val() != '') {
|
|
var url = '/admin/ajax_post_timetable/'+$('#obj_id').val()+'/';
|
|
}
|
|
else {
|
|
var url = '/admin/ajax_post_timetable/'
|
|
}
|
|
|
|
$.ajax({
|
|
url: url, //server script to process data
|
|
type: 'GET',
|
|
|
|
//Ajax events
|
|
success: postTimetable,
|
|
error: function(){ alert('error'); },
|
|
// Form data
|
|
data: formData,
|
|
//Options to tell JQuery not to process data or worry about content-type
|
|
cache: false,
|
|
contentType: false,
|
|
processData: false
|
|
});//end ajax
|
|
|
|
|
|
return false;
|
|
}); // end submit
|
|
|
|
$('.remove_timetable').on('click', function(e){
|
|
e.preventDefault();
|
|
$this = $(this);
|
|
console.log('111');
|
|
var url = '/admin/ajax_delete_timetable/'
|
|
var id = $(this).val();
|
|
$.get(url, {'id': id}, function(data){
|
|
if ('id' in data){
|
|
$this.parent().parent().remove();
|
|
}
|
|
});
|
|
});
|
|
|
|
|
|
});
|
|
|