refactor profile modules

remotes/origin/1203
pavel 11 years ago
parent 719b30f844
commit f68ca8ddf7
  1. 2
      templates/client/static_client/js/_modules/block.common.js
  2. 127
      templates/client/static_client/js/_modules/page.company.js
  3. 78
      templates/client/static_client/js/_modules/page.profile.js
  4. 2
      templates/client/static_client/js_min/_modules/block.common.min.js
  5. 2
      templates/client/static_client/js_min/_modules/page.company.min.js
  6. 2
      templates/client/static_client/js_min/_modules/page.profile.min.js

@ -493,7 +493,7 @@ if (EXPO.common){
* @param {string} selector
* @public
*/
pullData: function (selector) {
afterSubmit: function (selector) {
this.id = selector.substr(1);
$(selector).show().siblings().hide();
this.refresh();

@ -42,7 +42,7 @@ if (EXPO.company){
// methods to perform ajax responses to send and receive data from the server
Forms.prototype = {
// ajax request realization
getajax: function (dataToSend) {
submit: function (dataToSend) {
var self = this;
if(!dataToSend){
dataToSend = '';
@ -54,7 +54,7 @@ if (EXPO.company){
processData: false,
contentType: false,
success: function(data) {
self.pullHandler(data);
self.afterSubmit(data);
if(data.success){
EXPO.company.rating.refresh(data.rating);
}
@ -64,8 +64,8 @@ if (EXPO.company){
},
// check if there exists custom data manipulation handler and evaluate it
pushData: function (data, formName) {
var handler = this.pushHandler,
beforeSubmit: function (data, formName) {
var handler = this.beforeSubmitHandler,
formData = data;
if(typeof formData != "string"){
this.formData =formData;
@ -77,16 +77,16 @@ if (EXPO.company){
if(typeof handler == 'function'){
// if particular data change required
this.formData = handler(data, formName);
this.getajax(data);
this.submit(data);
$('#wait-ajax').show();
} else{
this.getajax(data);
this.submit(data);
$('#wait-ajax').show();
}
},
pullData: function (data) {
var handler = this.pullHandler;
afterSubmit: function (data) {
var handler = this.afterSubmitHandler;
if(typeof handler == 'function'){
handler(data);
} else{
@ -103,7 +103,7 @@ if (EXPO.company){
* @function
* @public
*/
refreshState: function () {
refreshHTML: function () {
var pureText = $.trim( this.$staticValue.text()).replace(/[^0-9a-zA-Zа-я\s]/g,'').replace( /(\d)\s/, '' ).replace(/\s+/g,'');
if(($.trim( this.$staticValue.text()) == '' || pureText == 'NoneNone') && this.$wrapper.length && this.refrashable){
this.$editable.addClass('hidden');
@ -116,6 +116,11 @@ if (EXPO.company){
}
}
};
/**
* factory object directly
* @param {String} type - type of fabricated object
* @param {String} ajaxpath - attribute action from each form html element
*/
Forms.factory = function (type, ajaxpath) {
var constr = type,
newForm;
@ -125,20 +130,23 @@ if (EXPO.company){
message: constr + "doesen't exist"
};
}
if(typeof Forms[constr].prototype.pushData !== "function"){
if(typeof Forms[constr].prototype.beforeSubmit !== "function"){
Forms[constr].prototype = new Forms();
}
newForm = new Forms[constr](ajaxpath);
return newForm;
};
/**
* set of child objects that will override the factory default
*/
Forms.name_form = function (path) {
this.pullHandler = function (data) {
var self = this;
this.afterSubmitHandler = function (data) {
if (data.success){
$('#static-name-value').text($('#id_name').val());
$('.p-editable').removeClass('pe-current');
this.refreshState();
self.refreshHTML();
}else{
this.$editable.addClass('err');
@ -148,11 +156,12 @@ if (EXPO.company){
};
Forms.spec_form = function (path) {
this.pullHandler = function (data) {
var self = this;
this.afterSubmitHandler = function (data) {
if (data.success){
$('#static-spec-value').html(com.nl2br($('#id_specialization').val()));
$('.p-editable').removeClass('pe-current');
this.refreshState();
self.refreshHTML();
}else{
this.$editable.addClass('err');
@ -162,11 +171,13 @@ if (EXPO.company){
};
Forms.address_form = function (path) {
this.pullHandler = function (data) {
var self = this;
this.afterSubmitHandler = function (data) {
if (data.success){
$('#static-address-value').text($('#id_address_inf').val());
$('.p-editable').removeClass('pe-current');
this.refreshState();
self.refreshHTML();
}else{
this.$editable.addClass('err');
@ -178,7 +189,7 @@ if (EXPO.company){
Forms.social_form = function (path) {
var self = this,
$img, imgSrc, $input, inputValue,item;
this.pullHandler = function (data) {
this.afterSubmitHandler = function (data) {
if (data.success){
for (item in self.formData) {
@ -221,10 +232,10 @@ if (EXPO.company){
});
}
}
this.refreshState();
self.refreshHTML();
};
this.pushHandler = function (data, formName){
this.beforeSubmitHandler = function (data, formName){
var formData = $('#'+formName).serialize();
return JSON.parse('{"' + decodeURI(formData).replace(/"/g, '\\"').replace(/&/g, '","').replace(/=/g,'":"') + '"}');
@ -233,7 +244,7 @@ if (EXPO.company){
};
this.refreshState = function () {
this.refreshHTML = function () {
console.log(this);
var fullComplete = true;
$('input:text',this.$form).each(function () {
@ -253,11 +264,13 @@ if (EXPO.company){
};
Forms.phone_form = function (path) {
this.pullHandler = function (data) {
var self = this;
this.afterSubmitHandler = function (data) {
if (data.success){
$('#static-phone-value').text($('#id_phone')[0].value);
$('.p-editable').removeClass('pe-current');
this.refreshState();
self.refreshHTML();
}
};
this.ajaxPath = path;
@ -265,12 +278,14 @@ if (EXPO.company){
};
Forms.email_form = function (path) {
var mailValue;
this.pullHandler = function (data) {
var self = this;
this.afterSubmitHandler = function (data) {
if (data.success){
mailValue = $('#id_email').val();
$('#static-email-value').attr('href', 'mailto:'+mailValue).text(mailValue);
$('.p-editable').removeClass('pe-current');
this.refreshState();
self.refreshHTML();
}else{
this.$editable.addClass('err');
}
@ -280,12 +295,14 @@ if (EXPO.company){
};
Forms.web_page_form = function (path) {
var userLink;
this.pullHandler = function (data) {
var self = this;
this.afterSubmitHandler = function (data) {
if (data.success){
userLink = $('#id_web_page').val();
$('#static-web-page-value').attr('href',userLink).text(userLink);
$('.p-editable').removeClass('pe-current');
this.refreshState();
self.refreshHTML();
}
};
@ -294,14 +311,16 @@ if (EXPO.company){
};
Forms.home_form = function (path) {
this.pullHandler = function (data) {
var self = this;
this.afterSubmitHandler = function (data) {
if (data.success){
var country = $('#s2id_id_country').find('.select2-chosen').text(),
city = $('#s2id_id_city').find('.select2-chosen').text();
$('#static-home-country').text(country);
$('#static-home-city').text(city);
$('.p-editable').removeClass('pe-current');
this.refreshState();
self.refreshHTML();
}
};
@ -311,7 +330,9 @@ if (EXPO.company){
Forms.found_form = function (path) {
var currValue,
$input;
this.pullHandler = function (data) {
var self = this;
this.afterSubmitHandler = function (data) {
if (data.success){
var $fullComplete = $('.full-complete',this.$staticValue);
@ -321,13 +342,13 @@ if (EXPO.company){
$fullComplete.text(currValue);
$('.p-editable').removeClass('pe-current');
this.refreshState();
self.refreshHTML();
}
};
this.ajaxPath = path;
this.refreshState = function () {
this.refreshHTML = function () {
var $fullComplete = $('.full-complete',this.$staticValue),
$notComplete = $('.not-complete',this.$staticValue);
if($.trim($fullComplete.text()) == ''){
@ -345,19 +366,21 @@ if (EXPO.company){
Forms.staff_form = function (path) {
var currValue,
$input;
this.pullHandler = function (data) {
var self = this;
this.afterSubmitHandler = function (data) {
if (data.success){
var $fullComplete = $('.full-complete',this.$staticValue);
$input = $('#id_staff_number');
currValue = $.trim($input.val());
$fullComplete.text(currValue);
$('.p-editable').removeClass('pe-current');
this.refreshState();
self.refreshHTML();
}
};
this.ajaxPath = path;
this.refreshState = function () {
this.refreshHTML = function () {
var $fullComplete = $('.full-complete',this.$staticValue),
$notComplete = $('.not-complete',this.$staticValue);
if($.trim($fullComplete.text()) == ''){
@ -375,7 +398,9 @@ if (EXPO.company){
Forms.description_form = function (path) {
var currValue,
$input = $('#id_description');
this.pullHandler = function (data) {
var self = this;
this.afterSubmitHandler = function (data) {
if (data.success){
var $fullComplete = $('.full-complete',this.$staticValue);
@ -383,12 +408,12 @@ if (EXPO.company){
$fullComplete.html(com.nl2br(currValue));
$('.p-editable').removeClass('pe-current');
this.refreshState();
self.refreshHTML();
}
};
this.ajaxPath = path;
this.refreshState = function () {
this.refreshHTML = function () {
var $fullComplete = $('.full-complete',this.$staticValue),
$notComplete = $('.not-complete',this.$staticValue);
if($.trim($fullComplete.text()) == ''){
@ -414,20 +439,20 @@ if (EXPO.company){
* callback after successful request to the server
* @param data -data object recieved from server
*/
this.pullHandler = function (data) {
this.afterSubmitHandler = function (data) {
if (data.success){
if($avatar.length){
$avatar.attr('src', data.url);
this.refreshState();
self.refreshHTML();
}
}
};
this.pushHandler = function(data){
this.beforeSubmitHandsler = function(data){
if(typeof data != 'string'){
self.getajax(data);
self.submit(data);
$('#wait-ajax').show();
}else{
$form = $('#'+self.formId);
@ -440,7 +465,7 @@ if (EXPO.company){
});
this.ajaxPath = path;
this.refreshState = function () {
this.refreshHTML = function () {
if($.trim(this.$image.attr('src')) == this.noImageSrc){
this.$editable.addClass('hidden');
this.$description.removeClass('hidden');
@ -458,7 +483,7 @@ if (EXPO.company){
* callback after successful request to the server
* @param data -data object recieved from server
*/
this.pullHandler = function (data) {
this.afterSubmitHandler = function (data) {
var divider ='<span>, </span>';
if (data.success){
@ -469,7 +494,7 @@ if (EXPO.company){
this.$staticValue.append($(divider));
}
}
this.refreshState();
self.refreshHTML();
}
};
@ -477,7 +502,7 @@ if (EXPO.company){
this.$input = $('#id_tag');
this.refreshState = function () {
this.refreshHTML = function () {
this.$label = $('.label', this.$editable);
this.$initial = $(".initial-position",this.$wrapper);
this.formId = this.$form.attr("id");
@ -808,17 +833,17 @@ if (EXPO.company){
$waiter.show();
if ( window.FormData && ("upload" in ($.ajaxSettings.xhr())) ){
inputData = new FormData(this);
self.forms[formName].pushData(inputData, formName);
self.forms[formName].beforeSubmit(inputData, formName);
} else {
inputData = $(this).serialize();
self.forms[formName].pushData(inputData, formName);
self.forms[formName].beforeSubmit(inputData, formName);
}
return false;
});
$closeButton.on('click', function() {
$editable.removeClass(self.opt.formCurrentClass);
self.forms[formName].refreshState();
self.forms[formName].refreshHTML();
return false;
});
@ -850,7 +875,7 @@ if (EXPO.company){
if($(this).hasClass(self.opt.formCurrentClass)){
if(self.forms[formId].refrashable){
self.forms[formId].refreshState();
self.forms[formId].refreshHTML();
$editable.removeClass(EXPO.company.opt.formCurrentClass);
}else{
$editable.removeClass(self.opt.formCurrentClass);
@ -870,7 +895,7 @@ if (EXPO.company){
var targetObj = $(event.target);
if (targetObj.parents().filter('.e-form').length < 1) {
$editable.removeClass(self.opt.formCurrentClass);
self.forms[formName].refreshState();
self.forms[formName].refreshHTML();
$(document).off('click.form');
}
});

@ -45,7 +45,7 @@ if (EXPO.profile){
// factory for on page form objects
Forms.prototype = {
// ajax request realization
getajax: function (dataToSend) {
submit: function (dataToSend) {
var self = this;
if(!dataToSend){
dataToSend = '';
@ -57,7 +57,7 @@ if (EXPO.profile){
processData: false,
contentType: false,
success: function(data) {
self.pullHandler(data);
self.afterSubmitHandler(data);
if(data.success){
EXPO.profile.rating.refresh(data.rating);
}
@ -67,8 +67,8 @@ if (EXPO.profile){
},
// check if there exists custom data manipulation handler and evaluate it
pushData: function (data, formName) {
var handler = this.pushHandler,
beforeSubmit: function (data, formName) {
var handler = this.beforeSubmitHandler,
formData = data;
if(typeof formData != "string"){
this.formData =formData;
@ -80,10 +80,10 @@ if (EXPO.profile){
if(typeof handler == 'function'){
// if particular data change required
this.formData = handler(data, formName);
this.getajax(data);
this.submit(data);
$('#wait-ajax').show();
} else{
this.getajax(data);
this.submit(data);
$('#wait-ajax').show();
}
@ -91,8 +91,8 @@ if (EXPO.profile){
},
pullData: function (data) {
var handler = this.pullHandler;
afterSubmit: function (data) {
var handler = this.afterSubmitHandler;
if(typeof handler == 'function'){
handler(data);
} else{
@ -122,7 +122,7 @@ if (EXPO.profile){
* @function
* @public
*/
refreshState: function () {
refreshHTML: function () {
var pureText = $.trim( this.$staticValue.text()).replace(/[^0-9a-zA-Zа-я\s]/g,'').replace( /(\d)\s/, '' ).replace(/\s+/g,'');
if(($.trim( this.$staticValue.text()) == '' || pureText == 'NoneNone') && this.$wrapper.length && this.refrashable){
this.$editable.addClass('hidden');
@ -145,7 +145,7 @@ if (EXPO.profile){
message: constr + "doesen't exist"
};
}
if(typeof Forms[constr].prototype.pushData !== "function"){
if(typeof Forms[constr].prototype.beforeSubmit !== "function"){
Forms[constr].prototype = new Forms();
}
newForm = new Forms[constr](ajaxpath);
@ -154,7 +154,7 @@ if (EXPO.profile){
//# constructors for each indivivdual form
// please add functionality for new profile forms here
// pushHandler is for ajax to server, pullHandler for ajax from it. Data is the response information from server
// beforeSubmitHandler is for ajax to server, pullHandler for ajax from it. Data is the response information from server
// name of each method is equal 'id' attribute of <form/> element on the page.
Forms.home_form = function (path) {
@ -163,14 +163,14 @@ if (EXPO.profile){
* callback after successful request to the server
* @param data -data object recieved from server
*/
this.pullHandler = function (data) {
this.afterSubmitHandler = function (data) {
if (data.success){
var country = $('#s2id_id_country').find('.select2-chosen').text(),
city = $('#s2id_id_city').find('.select2-chosen').text();
$('#static-home-country').text(country);
$('#static-home-city').text(city);
$('.p-editable').removeClass('pe-current');
this.refreshState();
this.refreshHTML();
}
};
this.ajaxPath = path;
@ -182,11 +182,11 @@ if (EXPO.profile){
* callback after successful request to the server
* @param data -data object recieved from server
*/
this.pullHandler = function (data) {
this.afterSubmitHandler = function (data) {
if (data.success){
$('#static-name-value').text($('#id_last_name').val()+' '+$('#id_first_name').val());
$('.p-editable').removeClass('pe-current');
this.refreshState();
this.refreshHTML();
}
};
@ -199,7 +199,7 @@ if (EXPO.profile){
* callback after successful request to the server
* @param data -data object recieved from server
*/
this.pullHandler = function (data) {
this.afterSubmitHandler = function (data) {
var staticText,
work_fieldValue = $.trim($('#s2id_id_company').text());
if (data.success ){
@ -209,7 +209,7 @@ if (EXPO.profile){
}
$('#static-work-value').text(staticText);
$('.p-editable').removeClass('pe-current');
this.refreshState();
this.refreshHTML();
}
};
@ -222,12 +222,12 @@ if (EXPO.profile){
* callback after successful request to the server
* @param data -data object recieved from server
*/
this.pullHandler = function (data) {
this.afterSubmitHandler = function (data) {
if (data.success){
$('#static-phone-value').text($('#id_phone')[0].value);
$('.p-editable').removeClass('pe-current');
this.refreshState();
this.refreshHTML();
}
};
@ -240,12 +240,12 @@ if (EXPO.profile){
* callback after successful request to the server
* @param data -data object recieved from server
*/
this.pullHandler = function (data) {
this.afterSubmitHandler = function (data) {
if (data.success){
var userLink = $('#id_web_page').val();
$('#static-web-page-value').attr('href',userLink).text(userLink);
$('.p-editable').removeClass('pe-current');
this.refreshState();
this.refreshHTML();
}
};
@ -259,11 +259,11 @@ if (EXPO.profile){
* callback after successful request to the server
* @param data -data object recieved from server
*/
this.pullHandler = function (data) {
this.afterSubmitHandler = function (data) {
if (data.success){
$('#static-about-value').html(com.nl2br($('#id_about').val()));
$('.p-editable').removeClass('pe-current');
this.refreshState();
this.refreshHTML();
}
};
@ -277,7 +277,7 @@ if (EXPO.profile){
* callback after successful request to the server
* @param data -data object recieved from server
*/
this.pullHandler = function (data) {
this.afterSubmitHandler = function (data) {
if (data.success){
for (item in self.formData) {
@ -310,7 +310,7 @@ if (EXPO.profile){
}
$('.p-editable').removeClass('pe-current');
this.refreshState();
this.refreshHTML();
}else {
for (item in data.errors) {
@ -323,7 +323,7 @@ if (EXPO.profile){
}
}
};
this.pushHandler = function (data, formName){
this.beforeSubmitHandler = function (data, formName){
var formData = $('#'+formName).serialize();
return JSON.parse('{"' + decodeURI(formData).replace(/"/g, '\\"').replace(/&/g, '","').replace(/=/g,'":"') + '"}');
@ -332,7 +332,7 @@ if (EXPO.profile){
};
this.refreshState = function () {
this.refreshHTML = function () {
console.log(this);
var fullComplete = true;
$('input:text',this.$form).each(function () {
@ -362,20 +362,20 @@ if (EXPO.profile){
* callback after successful request to the server
* @param data -data object recieved from server
*/
this.pullHandler = function (data) {
this.afterSubmitHandler = function (data) {
if (data.success){
if($avatar.length){
$avatar.attr('src', data.url);
this.refreshState();
this.refreshHTML();
}
}
};
this.pushHandler = function(data){
this.beforeSubmitHandler = function(data){
if(typeof data != 'string'){
self.getajax(data);
self.submit(data);
$('#wait-ajax').show();
}else{
$form = $('#'+self.formId);
@ -389,7 +389,7 @@ if (EXPO.profile){
this.ajaxPath = path;
this.refreshState = function () {
this.refreshHTML = function () {
if($.trim(this.$image.attr('src')) == this.noImageSrc){
this.$editable.addClass('hidden');
this.$description.removeClass('hidden');
@ -411,7 +411,7 @@ if (EXPO.profile){
* callback after successful request to the server
* @param data -data object recieved from server
*/
this.pullHandler = function (data) {
this.afterSubmitHandler = function (data) {
if (data.success){
location.reload();
@ -610,7 +610,7 @@ if (EXPO.profile){
}
// todo:временно отключил
//self.forms[formName].refreshState();
//self.forms[formName].refreshHTML();
// submit events handler
$(this).off('submit');
@ -619,17 +619,17 @@ if (EXPO.profile){
$waiter.show();
if ( window.FormData && ("upload" in ($.ajaxSettings.xhr())) ){
inputData = new FormData(this);
self.forms[formName].pushData(inputData, formName);
self.forms[formName].beforeSubmit(inputData, formName);
} else {
inputData = $(this).serialize();
self.forms[formName].pushData(inputData, formName);
self.forms[formName].beforeSubmit(inputData, formName);
}
return false;
});
$closeButton.on('click', function() {
$editable.removeClass(self.opt.formCurrentClass);
self.forms[formName].refreshState();
self.forms[formName].refreshHTML();
return false;
});
if($('.'+self.opt.avatarButtonClass, $wrapper).length){
@ -660,7 +660,7 @@ if (EXPO.profile){
if($(this).hasClass(self.opt.formCurrentClass)){
if(self.forms[formId].refrashable){
self.forms[formId].refreshState();
self.forms[formId].refreshHTML();
$editable.removeClass(EXPO.profile.opt.formCurrentClass);
}else{
$editable.removeClass(self.opt.formCurrentClass);
@ -680,7 +680,7 @@ if (EXPO.profile){
var targetObj = $(event.target);
if (targetObj.parents().filter('.e-form').length < 1) {
$editable.removeClass(self.opt.formCurrentClass);
self.forms[formName].refreshState();
self.forms[formName].refreshHTML();
$(document).off('click.form');
}
});

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long
Loading…
Cancel
Save