This commit is contained in:
parent
f0cef17ac9
commit
41587c0b69
|
@ -1,113 +1,113 @@
|
|||
var Iliad = {
|
||||
|
||||
/* Public */
|
||||
|
||||
evaluateAnchorAction: function(anchor) {
|
||||
var actionUrl = jQuery(anchor).attr('href');
|
||||
this.evaluateAction(actionUrl);
|
||||
},
|
||||
/* Public */
|
||||
|
||||
evaluateAnchorAction: function(anchor) {
|
||||
var actionUrl = jQuery(anchor).attr('href');
|
||||
this.evaluateAction(actionUrl);
|
||||
},
|
||||
|
||||
evaluateFormAction: function(form) {
|
||||
var actionUrl = this._getFormActionUrl(form);
|
||||
var data = jQuery(form).serialize();
|
||||
this.evaluateAction(actionUrl, "post", data);
|
||||
},
|
||||
|
||||
enableSubmitAction: function(button) {
|
||||
var name = jQuery(button).attr("name");
|
||||
if(name) {
|
||||
var hidden = "<input type='hidden' name='" + name + "'></input>";
|
||||
var form = jQuery(button).closest("form");
|
||||
jQuery(form).append(hidden);
|
||||
}
|
||||
},
|
||||
evaluateFormAction: function(form) {
|
||||
var actionUrl = this._getFormActionUrl(form);
|
||||
var data = jQuery(form).serialize();
|
||||
this.evaluateAction(actionUrl, "post", data);
|
||||
},
|
||||
|
||||
enableSubmitAction: function(button) {
|
||||
var name = jQuery(button).attr("name");
|
||||
if(name) {
|
||||
var hidden = "<input type='hidden' name='" + name + "'></input>";
|
||||
var form = jQuery(button).closest("form");
|
||||
jQuery(form).append(hidden);
|
||||
}
|
||||
},
|
||||
|
||||
evaluateAction:function(actionUrl, method, data) {
|
||||
if(!method) {method = 'get'};
|
||||
var that = this;
|
||||
jQuery.ajax({
|
||||
url: actionUrl,
|
||||
type: method,
|
||||
processUpdates: true,
|
||||
dataType: 'json',
|
||||
data: data,
|
||||
beforeSend: function(xhr) {
|
||||
xhr.setRequestHeader("X-Requested-With", "");
|
||||
Iliad._insertAjaxLoader()},
|
||||
success: function(json) {
|
||||
that._processUpdates(json);
|
||||
that._removeAjaxLoader();
|
||||
},
|
||||
error: function(err) {
|
||||
that._showError(actionUrl);
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
evaluateAction:function(actionUrl, method, data) {
|
||||
if(!method) {method = 'get'};
|
||||
var that = this;
|
||||
jQuery.ajax({
|
||||
url: actionUrl,
|
||||
type: method,
|
||||
processUpdates: true,
|
||||
dataType: 'json',
|
||||
data: data,
|
||||
beforeSend: function(xhr) {
|
||||
xhr.setRequestHeader("X-Requested-With", "");
|
||||
Iliad._insertAjaxLoader()},
|
||||
success: function(json) {
|
||||
that._processUpdates(json);
|
||||
that._removeAjaxLoader();
|
||||
},
|
||||
error: function(err) {
|
||||
that._showError(actionUrl);
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
|
||||
/* Private */
|
||||
|
||||
_hasActionUrl:function(anchor) {
|
||||
if(anchor && jQuery(anchor).attr('href')) {
|
||||
return /action?=(.*)$/.test(jQuery(anchor).attr('href'));
|
||||
}
|
||||
},
|
||||
|
||||
_getFormActionUrl:function(form) {
|
||||
return jQuery(form).attr('action')
|
||||
},
|
||||
/* Private */
|
||||
|
||||
_hasActionUrl:function(anchor) {
|
||||
if(anchor && jQuery(anchor).attr('href')) {
|
||||
return /action?=(.*)$/.test(jQuery(anchor).attr('href'));
|
||||
}
|
||||
},
|
||||
|
||||
_getFormActionUrl:function(form) {
|
||||
return jQuery(form).attr('action')
|
||||
},
|
||||
|
||||
_processUpdates:function(json) {
|
||||
/* handle redirect if any */
|
||||
if(json.redirect) {
|
||||
return window.location.href = json.redirect
|
||||
}
|
||||
|
||||
/* Refresh if there is no widget to update
|
||||
(session expired or the action is invalid) */
|
||||
if(this.sizeOf(json.widgets) == 0) {
|
||||
return location.reload()
|
||||
}
|
||||
|
||||
/* else update dirty widgets */
|
||||
var dirtyWidgets = json.widgets;
|
||||
for(var i in dirtyWidgets) {
|
||||
this._updateWidget(i, dirtyWidgets[i]);
|
||||
}
|
||||
_processUpdates:function(json) {
|
||||
/* handle redirect if any */
|
||||
if(json.redirect) {
|
||||
return window.location.href = json.redirect
|
||||
}
|
||||
|
||||
/* Refresh if there is no widget to update
|
||||
(session expired or the action is invalid) */
|
||||
if(this.sizeOf(json.widgets) == 0) {
|
||||
return location.reload()
|
||||
}
|
||||
|
||||
/* else update dirty widgets */
|
||||
var dirtyWidgets = json.widgets;
|
||||
for(var i in dirtyWidgets) {
|
||||
this._updateWidget(i, dirtyWidgets[i]);
|
||||
}
|
||||
|
||||
/* evaluate scripts */
|
||||
var scripts = json.scripts;
|
||||
for(var i in scripts) {
|
||||
this._evalScript(scripts[i]);
|
||||
}
|
||||
},
|
||||
|
||||
_updateWidget:function(widget, contents) {
|
||||
jQuery("#"+widget).replaceWith(contents)
|
||||
},
|
||||
/* evaluate scripts */
|
||||
var scripts = json.scripts;
|
||||
for(var i in scripts) {
|
||||
this._evalScript(scripts[i]);
|
||||
}
|
||||
},
|
||||
|
||||
_updateWidget:function(widget, contents) {
|
||||
jQuery("#"+widget).replaceWith(contents)
|
||||
},
|
||||
|
||||
_evalScript:function(script) {
|
||||
try {eval(jQuery(script).html())}
|
||||
catch(e){}
|
||||
_evalScript:function(script) {
|
||||
try {eval(jQuery(script).html())}
|
||||
catch(e){}
|
||||
},
|
||||
|
||||
_insertAjaxLoader:function() {
|
||||
jQuery('body').append('<div class="ajax_loader" style="position: fixed; top: 10px; right: 10px; z-index: 9999"><img src="/images/ajax_loader.gif"/></div>')
|
||||
},
|
||||
_insertAjaxLoader:function() {
|
||||
jQuery('body').append('<div class="ajax_loader" style="position: fixed; top: 10px; right: 10px; z-index: 9999"><img src="/images/ajax_loader.gif"/></div>')
|
||||
},
|
||||
|
||||
_showError:function(actionUrl){
|
||||
jQuery("body").html("<h1>Error 500: Internal server error</h1>")
|
||||
},
|
||||
_showError:function(actionUrl){
|
||||
jQuery("body").html("<h1>Error 500: Internal server error</h1>")
|
||||
},
|
||||
|
||||
_removeAjaxLoader:function() {
|
||||
jQuery(".ajax_loader").replaceWith("");
|
||||
},
|
||||
|
||||
sizeOf:function(obj) {
|
||||
var size = 0, key;
|
||||
_removeAjaxLoader:function() {
|
||||
jQuery(".ajax_loader").replaceWith("");
|
||||
},
|
||||
|
||||
sizeOf:function(obj) {
|
||||
var size = 0, key;
|
||||
for (key in obj) {
|
||||
if (obj.hasOwnProperty(key)) size++;
|
||||
}
|
||||
return size;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Reference in New Issue