mirror of
https://github.com/e107inc/e107.git
synced 2025-08-17 20:01:47 +02:00
JS API - minor fixes & improvements
This commit is contained in:
@@ -1219,14 +1219,14 @@ e107Utils.LoadingStatus = Class.create(e107WidgetAbstract, {
|
|||||||
|
|
||||||
startObserving: function() {
|
startObserving: function() {
|
||||||
Event.observe(window,"resize", this.re_center);
|
Event.observe(window,"resize", this.re_center);
|
||||||
if(Prototype.Browser.IE && Prototype.Browser.IE <= 6)
|
if(Prototype.Browser.IE && Prototype.Browser.IE <= 7)
|
||||||
Event.observe(window,"scroll", this.re_center);
|
Event.observe(window,"scroll", this.re_center);
|
||||||
return this;
|
return this;
|
||||||
},
|
},
|
||||||
|
|
||||||
stopObserving: function() {
|
stopObserving: function() {
|
||||||
Event.stopObserving(window, "resize", this.re_center);
|
Event.stopObserving(window, "resize", this.re_center);
|
||||||
if(Prototype.Browser.IE && Prototype.Browser.IE <= 6)
|
if(Prototype.Browser.IE && Prototype.Browser.IE <= 7)
|
||||||
Event.stopObserving(window, "scroll", this.re_center);
|
Event.stopObserving(window, "scroll", this.re_center);
|
||||||
return this;
|
return this;
|
||||||
},
|
},
|
||||||
@@ -1286,8 +1286,9 @@ e107Utils.LoadingStatus = Class.create(e107WidgetAbstract, {
|
|||||||
return this;
|
return this;
|
||||||
},
|
},
|
||||||
|
|
||||||
iecenter: function() {
|
iecenter: function() {
|
||||||
if(Prototype.Browser.IE && Prototype.Browser.IE <= 6) {
|
//TODO - actually ie7 should work without this - investigate
|
||||||
|
if(Prototype.Browser.IE && Prototype.Browser.IE <= 7) {
|
||||||
//The 'freezing' problem solved (opacity = 1 ?!)
|
//The 'freezing' problem solved (opacity = 1 ?!)
|
||||||
this.loading_mask.show();
|
this.loading_mask.show();
|
||||||
var offset = document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop;
|
var offset = document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop;
|
||||||
@@ -2058,9 +2059,9 @@ Ajax.Updater = Class.create(Ajax.Updater, {
|
|||||||
*/
|
*/
|
||||||
var e107AjaxAbstract = Class.create ({
|
var e107AjaxAbstract = Class.create ({
|
||||||
_processResponse: function(transport) {
|
_processResponse: function(transport) {
|
||||||
if(transport.responseXML) {
|
if(null !== transport.responseXML) {
|
||||||
this._handleXMLResponse(transport.responseXML);
|
this._handleXMLResponse(transport.responseXML);
|
||||||
} else if(transport.responseJSON) {
|
} else if(null !== transport.responseJSON) {
|
||||||
this._handleJSONResponse(transport.responseJSON);
|
this._handleJSONResponse(transport.responseJSON);
|
||||||
} else {
|
} else {
|
||||||
this._handleTextResponse(transport.responseText);
|
this._handleTextResponse(transport.responseText);
|
||||||
@@ -2071,6 +2072,7 @@ var e107AjaxAbstract = Class.create ({
|
|||||||
_handleXMLResponse: function (response) {
|
_handleXMLResponse: function (response) {
|
||||||
var xfields = $A(response.childNodes[0].childNodes);
|
var xfields = $A(response.childNodes[0].childNodes);
|
||||||
//getElementsByTagName('e107response')[0]
|
//getElementsByTagName('e107response')[0]
|
||||||
|
|
||||||
var parsed = {};
|
var parsed = {};
|
||||||
xfields.each( function(el) {
|
xfields.each( function(el) {
|
||||||
if (el.nodeType == 1 && el.nodeName == 'e107action' && el.getAttribute('name') && el.childNodes) {
|
if (el.nodeType == 1 && el.nodeName == 'e107action' && el.getAttribute('name') && el.childNodes) {
|
||||||
@@ -2121,25 +2123,57 @@ var e107AjaxAbstract = Class.create ({
|
|||||||
|
|
||||||
_processResponseAuto: function(response) {
|
_processResponseAuto: function(response) {
|
||||||
//find by keys as IDs & update
|
//find by keys as IDs & update
|
||||||
|
Object.keys(response).each(function(key) {
|
||||||
|
this._updateElement(key, response[key]);
|
||||||
|
}.bind(this));
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reset checked property of form elements by selector (checkbox, radio)
|
||||||
|
*/
|
||||||
|
_processResponseResetChecked: function(response) {
|
||||||
|
Object.keys(response).each(function(key) {
|
||||||
|
var checked = parseInt(response[key]) ? true : false;
|
||||||
|
$$('input[name^=' + key + ']').each( function(felement) {
|
||||||
|
var itype = String(felement.type);
|
||||||
|
if('checkbox radio'.include(itype.toLowerCase()))
|
||||||
|
felement.checked = checked;
|
||||||
|
});
|
||||||
|
}.bind(this));
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update element by type
|
||||||
|
*/
|
||||||
_updateElement: function(el, data) {
|
_updateElement: function(el, data) {
|
||||||
el = $(el); if(!el) return;
|
el = $(el); if(!el) return;
|
||||||
var type = el.nodeName.toLowerCase();
|
var type = el.nodeName.toLowerCase(), itype = el.type;
|
||||||
if(type == 'input' || type == 'textarea') {
|
if(type == 'input' || type == 'textarea') {
|
||||||
//FIXME checkbox, radio
|
//FIXME checkbox, radio
|
||||||
el.value = data;
|
if(itype) itype = itype.toLowerCase();
|
||||||
|
|
||||||
|
switch (itype) {
|
||||||
|
case 'checkbox':
|
||||||
|
case 'radio':
|
||||||
|
el.checked = (el.value == data);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
el.value = data;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
} else if(type == 'select') {
|
} else if(type == 'select') {
|
||||||
if(el.options) {
|
if(el.options) {
|
||||||
var opt = $A(el.options).find( function(opt, ind) {
|
var opt = $A(el.options).find( function(op, ind) {
|
||||||
return opt.value == data;
|
return op.value == data;
|
||||||
});
|
});
|
||||||
el.selectedIndex = opt.index;
|
if(opt)
|
||||||
|
el.selectedIndex = opt.index;
|
||||||
}
|
}
|
||||||
} else if(type == 'img') {
|
} else if(type == 'img') {
|
||||||
el.writeAttribute('src', data).show(); //show if hidden
|
el.writeAttribute('src', data).show(); //show if hidden
|
||||||
}else {
|
}else if(el.nodeType == 1) {
|
||||||
elupdate(data);
|
el.update(data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -2196,6 +2230,7 @@ e107Ajax.Updater = Class.create({
|
|||||||
initialize: function(container, url, options) {
|
initialize: function(container, url, options) {
|
||||||
|
|
||||||
this.options = {};
|
this.options = {};
|
||||||
|
if(!options.parameters) options.parameters = {};
|
||||||
|
|
||||||
Object.extend(this.options, options || {});
|
Object.extend(this.options, options || {});
|
||||||
if(!this.options['parameters'] || !this.options.parameters['ajax_used'])
|
if(!this.options['parameters'] || !this.options.parameters['ajax_used'])
|
||||||
@@ -2254,7 +2289,7 @@ Object.extend(e107Ajax, {
|
|||||||
if(container)
|
if(container)
|
||||||
return new e107Ajax.Updater(container, url, opt);
|
return new e107Ajax.Updater(container, url, opt);
|
||||||
|
|
||||||
return new e107Ajax.Request(url, opt);
|
return new e107Ajax.Request(url, opt);
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -2297,11 +2332,11 @@ e107Ajax.fillForm = Class.create(e107AjaxAbstract, {
|
|||||||
|
|
||||||
history: false,
|
history: false,
|
||||||
|
|
||||||
onSuccess: function(transport) {
|
onSuccess: function(transport) {
|
||||||
try {
|
try {
|
||||||
this._processResponse(transport);
|
this._processResponse(transport);
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
var err_obj = { message: 'callback_error', extended: 'callback_error', code: -1 }
|
var err_obj = { message: 'Callback Error!', extended: e, code: -1 }
|
||||||
e107Event.trigger("ajax_fillForm_error", {form: this.form, error: err_obj});
|
e107Event.trigger("ajax_fillForm_error", {form: this.form, error: err_obj});
|
||||||
}
|
}
|
||||||
}.bind(C),
|
}.bind(C),
|
||||||
@@ -2309,35 +2344,42 @@ e107Ajax.fillForm = Class.create(e107AjaxAbstract, {
|
|||||||
onFailure: function(transport) {
|
onFailure: function(transport) {
|
||||||
//We don't use transport.statusText only because of Safari!!!
|
//We don't use transport.statusText only because of Safari!!!
|
||||||
var err = transport.getHeader('e107ErrorMessage') || '';
|
var err = transport.getHeader('e107ErrorMessage') || '';
|
||||||
//TODO - move error messages to the ajax responder object, convert it to an 'error' object (text, code,
|
//TODO - move error messages to the ajax responder object, convert it to an 'error' object (message, extended, code)
|
||||||
//Add Ajax option e.g. printErrors (true|false)
|
//Add Ajax option e.g. printErrors (true|false)
|
||||||
var err_obj = { message: err, extended: transport.responseText, code: transport.status }
|
var err_obj = { message: err, extended: transport.responseText, code: transport.status }
|
||||||
e107Event.trigger("ajax_fillForm_error", {form: this.form, error: err_obj });
|
e107Event.trigger("ajax_fillForm_error", {form: this.form, error: err_obj });
|
||||||
}.bind(C)
|
}.bind(C)
|
||||||
}
|
}
|
||||||
|
Object.extend(options, this.options.request || {}); //update - allow passing request options
|
||||||
|
|
||||||
this.form.submitForm(null, options, this.options.handler);
|
this.form.submitForm(null, options, this.options.handler);
|
||||||
},
|
},
|
||||||
|
|
||||||
_processResponseFillForm: function(response) {
|
_processResponseFillForm: function(response) {
|
||||||
if(!response || !this.form) return;
|
if(!response || !this.form) return;
|
||||||
var C = this;
|
var C = this, left_response = Object.clone(response);
|
||||||
this.form.getElements().each(function(el) {
|
this.form.getElements().each(function(el) {
|
||||||
var elid = el.identify(), elname = el.readAttribute('name'), data;
|
var elid = el.identify(), elname = el.readAttribute('name'), data, elnameid = String(elname).gsub(/[\[\]\_]/, '-');
|
||||||
if(isset(response[elid])) {
|
|
||||||
data = response[elid];
|
if(isset(response[elname])) {
|
||||||
delete response[elid];
|
data = response[elname];
|
||||||
} else if(isset(response[elname])) {
|
if(left_response[elname]) delete left_response[elname];
|
||||||
data = response[elname];
|
} else if(isset(response[elnameid])) {
|
||||||
delete response[elname];
|
data = response[elnameid];
|
||||||
|
if(left_response[elnameid]) delete left_response[elnameid];
|
||||||
|
} else if(isset(response[elid])) {
|
||||||
|
data = response[elid];
|
||||||
|
if(left_response[elid]) delete left_response[elid];
|
||||||
} else {
|
} else {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this._updateElement(el, data);
|
this._updateElement(el, data);
|
||||||
}.bind(C));
|
}.bind(C));
|
||||||
if(response) { //update non-form elements (by id)
|
|
||||||
Object.keys(response).each( function(el) {
|
if(left_response) { //update non-form elements (by id)
|
||||||
this._updateElement(el, response[el]);
|
Object.keys(left_response).each( function(el) {
|
||||||
|
|
||||||
|
this._updateElement(el, left_response[el]);
|
||||||
}.bind(C));
|
}.bind(C));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user