|
|
|
|
@ -30,6 +30,8 @@ if (EXPO.company){ |
|
|
|
|
type: 'POST', |
|
|
|
|
url: self.ajaxPath, |
|
|
|
|
data:dataToSend, |
|
|
|
|
processData: false, |
|
|
|
|
contentType: false, |
|
|
|
|
success: function(data) { |
|
|
|
|
self.pullHandler(data); |
|
|
|
|
$('#wait-ajax').fadeOut(); |
|
|
|
|
@ -40,19 +42,23 @@ if (EXPO.company){ |
|
|
|
|
// check if there exists custom data manipulation handler and evaluate it
|
|
|
|
|
pushData: function (data, formName) { |
|
|
|
|
var handler = this.pushHandler, |
|
|
|
|
formDataString, |
|
|
|
|
formData = data; |
|
|
|
|
if(typeof formData != "string"){ |
|
|
|
|
this.formData =formData; |
|
|
|
|
}else{ |
|
|
|
|
this.formData = JSON.parse('{"' + decodeURI(formData).replace(/"/g, '\\"').replace(/&/g, '","').replace(/=/g,'":"') + '"}'); |
|
|
|
|
} |
|
|
|
|
this.formId = formName; |
|
|
|
|
|
|
|
|
|
if(typeof handler == 'function'){ |
|
|
|
|
// if particular data change required
|
|
|
|
|
this.formData = handler(data, formName); |
|
|
|
|
this.getajax(data); |
|
|
|
|
$('#wait-ajax').show(); |
|
|
|
|
handler(data); |
|
|
|
|
} else{ |
|
|
|
|
$('#wait-ajax').show(); |
|
|
|
|
this.getajax(data); |
|
|
|
|
$('#wait-ajax').show(); |
|
|
|
|
} |
|
|
|
|
formDataString = decodeURI(formData).replace(/"/g, '\\"').replace(/&/g, '","').replace(/=/g,'":"').replace(/\//ig, '\\/').replace(/\\n/g, '\\n'); |
|
|
|
|
this.formData = JSON.parse('{"' + formDataString + '"}'); |
|
|
|
|
this.formId = formName; |
|
|
|
|
|
|
|
|
|
}, |
|
|
|
|
pullData: function (data) { |
|
|
|
|
@ -108,6 +114,8 @@ if (EXPO.company){ |
|
|
|
|
$('.p-editable').removeClass('pe-current'); |
|
|
|
|
this.refreshState(); |
|
|
|
|
|
|
|
|
|
}else{ |
|
|
|
|
this.$editable.addClass('err'); |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
this.ajaxPath = path; |
|
|
|
|
@ -120,6 +128,8 @@ if (EXPO.company){ |
|
|
|
|
$('.p-editable').removeClass('pe-current'); |
|
|
|
|
this.refreshState(); |
|
|
|
|
|
|
|
|
|
}else{ |
|
|
|
|
this.$editable.addClass('err'); |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
this.ajaxPath = path; |
|
|
|
|
@ -132,18 +142,8 @@ if (EXPO.company){ |
|
|
|
|
$('.p-editable').removeClass('pe-current'); |
|
|
|
|
this.refreshState(); |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
this.ajaxPath = path; |
|
|
|
|
|
|
|
|
|
}; |
|
|
|
|
Forms.address_form = function (path) { |
|
|
|
|
this.pullHandler = function (data) { |
|
|
|
|
if (data.success){ |
|
|
|
|
$('#static-address-value').text($('#id_address_inf').val()); |
|
|
|
|
$('.p-editable').removeClass('pe-current'); |
|
|
|
|
this.refreshState(); |
|
|
|
|
|
|
|
|
|
}else{ |
|
|
|
|
this.$editable.addClass('err'); |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
this.ajaxPath = path; |
|
|
|
|
@ -154,8 +154,10 @@ if (EXPO.company){ |
|
|
|
|
$img, imgSrc, $input, inputValue,item; |
|
|
|
|
this.pullHandler = function (data) { |
|
|
|
|
if (data.success){ |
|
|
|
|
|
|
|
|
|
for (item in self.formData) { |
|
|
|
|
$input = $('#id_'+item); |
|
|
|
|
$input.parent('.required').removeClass('err'); |
|
|
|
|
if($.trim(self.formData[item]) != '' && $input.length){ |
|
|
|
|
$img = $('#img-'+item); |
|
|
|
|
if($img.length){ |
|
|
|
|
@ -182,7 +184,22 @@ if (EXPO.company){ |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
$('.p-editable').removeClass('pe-current'); |
|
|
|
|
|
|
|
|
|
}else { |
|
|
|
|
for (item in data.errors) { |
|
|
|
|
$input = $('#id_' + item); |
|
|
|
|
$input.parent('.required').addClass('err'); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
this.pushHandler = function (data, formName){ |
|
|
|
|
var formData = $('#'+formName).serialize(); |
|
|
|
|
|
|
|
|
|
return JSON.parse('{"' + decodeURI(formData).replace(/"/g, '\\"').replace(/&/g, '","').replace(/=/g,'":"') + '"}'); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}; |
|
|
|
|
this.ajaxPath = path; |
|
|
|
|
|
|
|
|
|
@ -206,8 +223,8 @@ if (EXPO.company){ |
|
|
|
|
$('#static-email-value').attr('href', 'mailto:'+mailValue).text(mailValue); |
|
|
|
|
$('.p-editable').removeClass('pe-current'); |
|
|
|
|
this.refreshState(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}else{ |
|
|
|
|
this.$editable.addClass('err'); |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
this.ajaxPath = path; |
|
|
|
|
@ -245,28 +262,14 @@ if (EXPO.company){ |
|
|
|
|
}; |
|
|
|
|
Forms.found_form = function (path) { |
|
|
|
|
var currValue, |
|
|
|
|
$input, |
|
|
|
|
$container, |
|
|
|
|
$staticValue, |
|
|
|
|
$staticBox, |
|
|
|
|
$editButton; |
|
|
|
|
$input; |
|
|
|
|
this.pullHandler = function (data) { |
|
|
|
|
if (data.success){ |
|
|
|
|
$input = $('#id_foundation'); |
|
|
|
|
currValue = $.trim($input.val()); |
|
|
|
|
$container = $input.parents('.p-editable'); |
|
|
|
|
$editButton = $input.parents('.edit-wrap').children('e-btn'); |
|
|
|
|
$staticValue = $('#static-found-value'); |
|
|
|
|
$staticBox = $('#static-foundation'); |
|
|
|
|
if(currValue == ''){ |
|
|
|
|
$container.removeClass('ic-tel').addClass('add_link_text add_link_text_medium'); |
|
|
|
|
$staticValue.hide().children('span').text(''); |
|
|
|
|
$staticBox.show(); |
|
|
|
|
}else{ |
|
|
|
|
$container.removeClass('add_link_text add_link_text_medium').addClass('ic-tel'); |
|
|
|
|
$staticValue.show().children('span').text(currValue); |
|
|
|
|
$staticBox.hide(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
this.$staticValue.text(currValue); |
|
|
|
|
|
|
|
|
|
$('.p-editable').removeClass('pe-current'); |
|
|
|
|
this.refreshState(); |
|
|
|
|
} |
|
|
|
|
@ -277,28 +280,12 @@ if (EXPO.company){ |
|
|
|
|
}; |
|
|
|
|
Forms.staff_form = function (path) { |
|
|
|
|
var currValue, |
|
|
|
|
$input, |
|
|
|
|
$container, |
|
|
|
|
$staticValue, |
|
|
|
|
$staticBox, |
|
|
|
|
$editButton; |
|
|
|
|
$input; |
|
|
|
|
this.pullHandler = function (data) { |
|
|
|
|
if (data.success){ |
|
|
|
|
$input = $('#id_staff_number'); |
|
|
|
|
currValue = $.trim($input.val()); |
|
|
|
|
$container = $input.parents('.p-editable'); |
|
|
|
|
$editButton = $input.parents('.edit-wrap').children('e-btn'); |
|
|
|
|
$staticValue = $('#static-staff_number-value'); |
|
|
|
|
$staticBox = $('#static-staff_number'); |
|
|
|
|
if(currValue == ''){ |
|
|
|
|
$container.removeClass('ic-tel').addClass('add_link_text add_link_text_medium'); |
|
|
|
|
$staticValue.hide().children('span').text(''); |
|
|
|
|
$staticBox.show(); |
|
|
|
|
}else{ |
|
|
|
|
$container.removeClass('add_link_text add_link_text_medium').addClass('ic-tel'); |
|
|
|
|
$staticValue.show().children('span').text(currValue); |
|
|
|
|
$staticBox.hide(); |
|
|
|
|
} |
|
|
|
|
this.$staticValue.text(currValue); |
|
|
|
|
$('.p-editable').removeClass('pe-current'); |
|
|
|
|
this.refreshState(); |
|
|
|
|
} |
|
|
|
|
@ -309,27 +296,12 @@ if (EXPO.company){ |
|
|
|
|
}; |
|
|
|
|
Forms.description_form = function (path) { |
|
|
|
|
var currValue, |
|
|
|
|
$input = $('#id_description'), |
|
|
|
|
$container, |
|
|
|
|
$staticValue, |
|
|
|
|
$staticBox, |
|
|
|
|
$editButton; |
|
|
|
|
$input = $('#id_description'); |
|
|
|
|
this.pullHandler = function (data) { |
|
|
|
|
if (data.success){ |
|
|
|
|
currValue = $.trim($input.val()); |
|
|
|
|
$container = $input.parents('.p-editable'); |
|
|
|
|
$editButton = $input.parents('.edit-wrap').children('e-btn'); |
|
|
|
|
$staticValue = $('#static-description-value'); |
|
|
|
|
$staticBox = $('#static-description'); |
|
|
|
|
if(currValue == ''){ |
|
|
|
|
$container.removeClass('ic-tel').addClass('add_link_text add_link_text_medium'); |
|
|
|
|
$staticValue.hide().children('span').text(''); |
|
|
|
|
$staticBox.show(); |
|
|
|
|
}else{ |
|
|
|
|
$container.removeClass('add_link_text add_link_text_medium').addClass('ic-tel'); |
|
|
|
|
$staticValue.show().text(currValue); |
|
|
|
|
$staticBox.hide(); |
|
|
|
|
} |
|
|
|
|
this.$staticValue.text(currValue); |
|
|
|
|
|
|
|
|
|
$('.p-editable').removeClass('pe-current'); |
|
|
|
|
this.refreshState(); |
|
|
|
|
} |
|
|
|
|
@ -345,7 +317,53 @@ if (EXPO.company){ |
|
|
|
|
this.ajaxPath = path; |
|
|
|
|
|
|
|
|
|
}; |
|
|
|
|
Forms.avatar_form = function (path) { |
|
|
|
|
var self = this, |
|
|
|
|
$input = $('#id_avatar'), |
|
|
|
|
$editPhoto = $('#pic-edit-photo'), |
|
|
|
|
$pickBlock = $('#pick-block'), |
|
|
|
|
$form, |
|
|
|
|
$avatar = $('img',$pickBlock); |
|
|
|
|
/** |
|
|
|
|
* callback after successful request to the server |
|
|
|
|
* @param data -data object recieved from server |
|
|
|
|
*/ |
|
|
|
|
this.pullHandler = function (data) { |
|
|
|
|
if (data.success){ |
|
|
|
|
|
|
|
|
|
if($avatar.length){ |
|
|
|
|
$avatar.attr('src', data.url); |
|
|
|
|
} |
|
|
|
|
$('.p-editable').removeClass('pe-current'); |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
this.pushHandler = function(data){ |
|
|
|
|
if(typeof data != 'string'){ |
|
|
|
|
self.getajax(data); |
|
|
|
|
$('#wait-ajax').show(); |
|
|
|
|
}else{ |
|
|
|
|
$form = $('#'+self.formId); |
|
|
|
|
$form.off('submit'); |
|
|
|
|
$form.trigger('submit'); |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
$input.on('change', function () { |
|
|
|
|
$(this).parents('form').submit(); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
this.ajaxPath = path; |
|
|
|
|
this.refreshState = function () { |
|
|
|
|
if($.trim(this.$image.attr('src')) == this.noImageSrc){ |
|
|
|
|
this.$editable.addClass('hidden'); |
|
|
|
|
this.$description.removeClass('hidden'); |
|
|
|
|
}else{ |
|
|
|
|
this.$editable.removeClass('hidden'); |
|
|
|
|
this.$description.addClass('hidden'); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
// methods
|
|
|
|
|
//инициализация общих свойств
|
|
|
|
|
@ -384,6 +402,7 @@ if (EXPO.company){ |
|
|
|
|
}; |
|
|
|
|
this.forms = {}; |
|
|
|
|
$(function () { |
|
|
|
|
var $editables = $('.'+self.opt.editableClass); |
|
|
|
|
//start of document.ready
|
|
|
|
|
$waiter = $('#wait-ajax').css({'z-index': '8012'}); |
|
|
|
|
/** |
|
|
|
|
@ -429,7 +448,8 @@ if (EXPO.company){ |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
// предазгрузка активных тегов
|
|
|
|
|
//$('#'+self.opt.selectBox[2].id).attr('data-predifined','[{"id":"1128","text":"тег1"},{"id":"3365","text":"тег2"}]');
|
|
|
|
|
$('#'+self.opt.selectBox[2].id).select2({ |
|
|
|
|
placeholder: self.opt.selectBox[2].placeholder, |
|
|
|
|
width: '368px', |
|
|
|
|
@ -463,6 +483,11 @@ if (EXPO.company){ |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
initSelection : function(element, callback) { |
|
|
|
|
console.log(element); |
|
|
|
|
var data = [], |
|
|
|
|
dataObjArr = JSON.parse(element.attr('data-predifined')); |
|
|
|
|
callback(dataObjArr); |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
}); |
|
|
|
|
@ -478,7 +503,8 @@ if (EXPO.company){ |
|
|
|
|
$staticValue = $('.'+self.opt.staticValueClass, $wrapper), |
|
|
|
|
$description = $('.'+self.opt.descriptionClass, $wrapper), |
|
|
|
|
$editable = $('.'+self.opt.editableClass, $wrapper), |
|
|
|
|
$closeButton = $('.'+self.opt.closeButtonClass, $wrapper); |
|
|
|
|
$closeButton = $('.'+self.opt.closeButtonClass, $wrapper), |
|
|
|
|
$image = $('.'+self.opt.avatarImageClass, $wrapper); |
|
|
|
|
|
|
|
|
|
//make and initialize form objects
|
|
|
|
|
|
|
|
|
|
@ -494,7 +520,14 @@ if (EXPO.company){ |
|
|
|
|
self.forms[formName].$staticValue = $staticValue; |
|
|
|
|
self.forms[formName].$description = $description; |
|
|
|
|
self.forms[formName].$editable = $editable; |
|
|
|
|
/** |
|
|
|
|
* Send proper information if there is image. mainly for avatar editing |
|
|
|
|
*/ |
|
|
|
|
if($image.length){ |
|
|
|
|
|
|
|
|
|
self.forms[formName].$image = $image; |
|
|
|
|
self.forms[formName].noImageSrc = self.opt.noImageSrc; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
self.forms[formName].refreshState(); |
|
|
|
|
|
|
|
|
|
@ -521,7 +554,9 @@ if (EXPO.company){ |
|
|
|
|
/** |
|
|
|
|
* edit button |
|
|
|
|
*/ |
|
|
|
|
$('.'+self.opt.editButtonClass, $wrapper).on('click', function () { |
|
|
|
|
$('.'+self.opt.editButtonClass+', .'+self.opt.avatarButtonClass, $wrapper).on('click', function () { |
|
|
|
|
$editables.removeClass(self.opt.formCurrentClass); |
|
|
|
|
|
|
|
|
|
if(self.forms[formName].refrashable){ |
|
|
|
|
$editable.removeClass('hidden'); |
|
|
|
|
$description.addClass('hidden'); |
|
|
|
|
|