--- a/src/pyams_skin/resources/js/myams.js Wed Dec 12 10:13:00 2018 +0100
+++ b/src/pyams_skin/resources/js/myams.js Wed Dec 12 10:13:38 2018 +0100
@@ -238,7 +238,9 @@
* Copyright Andrew Davy: https://forrst.com/posts/Get_the_URL_of_the_current_javascript_file-Dst
*/
MyAMS.baseURL = (function () {
- var script = $('script[src*="/myams.js"], script[src*="/myams.min.js"], script[src*="/myams-core.js"], script[src*="/myams-core.min.js"]');
+ var script = $('script[src*="/myams.js"], script[src*="/myams.min.js"], ' +
+ 'script[src*="/myams-core.js"], script[src*="/myams-core.min.js"], ' +
+ 'script[src*="/myams-require.js"], script[src*="/myams-require.min.js"]');
var src = script.attr("src");
ams.devmode = src.indexOf('.min.js') < 0;
ams.devext = ams.devmode ? '' : '.min';
@@ -397,9 +399,11 @@
* @param url: script URL
* @param callback: a callback to be called after script loading
* @param options: a set of options to be added to AJAX call
+ * @param onerror: an error callback to be called instead of generic callback
*/
- MyAMS.getScript = function (url, callback, options) {
+ MyAMS.getScript = function (url, callback, options, onerror) {
if (typeof(callback) === 'object') {
+ onerror = options;
options = callback;
callback = null;
}
@@ -410,7 +414,7 @@
dataType: 'script',
url: ams.getSource(url),
success: callback,
- error: ams.error.show,
+ error: onerror || ams.error.show,
cache: !ams.devmode,
async: options.async === undefined ? typeof(callback) === 'function' : options.async
};
@@ -532,8 +536,7 @@
*/
(function($, globals) {
- var MyAMS = globals.MyAMS,
- ams = MyAMS;
+ var ams = globals.MyAMS;
$.fn.extend({
@@ -697,10 +700,9 @@
*/
(function($, globals) {
- var MyAMS = globals.MyAMS,
- ams = MyAMS;
-
- MyAMS.event = {
+ var ams = globals.MyAMS;
+
+ ams.event = {
/**
* Stop current event propagation
@@ -728,10 +730,9 @@
*/
(function($, globals) {
- var MyAMS = globals.MyAMS,
- ams = MyAMS;
-
- MyAMS.browser = {
+ var ams = globals.MyAMS;
+
+ ams.browser = {
/**
* Get IE version
@@ -825,7 +826,7 @@
timeout: 3000
});
} else if (globals.prompt) {
- globals.prompt(MyAMS.i18n.CLIPBOARD_COPY, text);
+ globals.prompt(ams.i18n.CLIPBOARD_COPY, text);
}
}
@@ -849,10 +850,9 @@
*/
(function($, globals) {
- var MyAMS = globals.MyAMS,
- ams = MyAMS;
-
- MyAMS.error = {
+ var ams = globals.MyAMS;
+
+ ams.error = {
/**
* Default JQuery AJAX error handler
@@ -916,10 +916,9 @@
*/
(function($, globals) {
- var MyAMS = globals.MyAMS,
- ams = MyAMS;
-
- MyAMS.ajax = {
+ var ams = globals.MyAMS;
+
+ ams.ajax = {
/**
* Check for given feature and download script if necessary
@@ -1378,10 +1377,9 @@
*/
(function($, globals) {
- var MyAMS = globals.MyAMS,
- ams = MyAMS;
-
- MyAMS.jsonrpc = {
+ var ams = globals.MyAMS;
+
+ ams.jsonrpc = {
/**
* Get address relative to current page
@@ -1506,10 +1504,9 @@
*/
(function($, globals) {
- var MyAMS = globals.MyAMS,
- ams = MyAMS;
-
- MyAMS.xmlrpc = {
+ var ams = globals.MyAMS;
+
+ ams.xmlrpc = {
/**
* Get address relative to current page
@@ -1572,10 +1569,9 @@
*/
(function($, globals) {
- var MyAMS = globals.MyAMS,
- ams = MyAMS;
-
- MyAMS.form = {
+ var ams = globals.MyAMS;
+
+ ams.form = {
/**
* Init forms to activate form change listeners
@@ -2319,10 +2315,9 @@
*/
(function($, globals) {
- var MyAMS = globals.MyAMS,
- ams = MyAMS;
-
- MyAMS.dialog = {
+ var ams = globals.MyAMS;
+
+ ams.dialog = {
/**
* List of registered 'shown' callbacks
@@ -2622,10 +2617,9 @@
*/
(function($, globals) {
- var MyAMS = globals.MyAMS,
- ams = MyAMS;
-
- MyAMS.helpers = {
+ var ams = globals.MyAMS;
+
+ ams.helpers = {
/** Sort DOM elements into selected container */
sort: function(container, attribute) {
@@ -2875,10 +2869,9 @@
*/
(function($, globals) {
- var MyAMS = globals.MyAMS,
- ams = MyAMS;
-
- MyAMS.plugins = {
+ var ams = globals.MyAMS;
+
+ ams.plugins = {
/**
* Container of enabled plug-ins
@@ -3152,8 +3145,7 @@
*/
(function($, globals) {
- var MyAMS = globals.MyAMS,
- ams = MyAMS;
+ var ams = globals.MyAMS;
/**
* Map of enabled plug-ins
@@ -4853,10 +4845,9 @@
*/
(function($, globals) {
- var MyAMS = globals.MyAMS,
- ams = MyAMS;
-
- MyAMS.callbacks = {
+ var ams = globals.MyAMS;
+
+ ams.callbacks = {
/**
* Initialize list of callbacks
@@ -5019,10 +5010,9 @@
*/
(function($, globals) {
- var MyAMS = globals.MyAMS,
- ams = MyAMS;
-
- MyAMS.events = {
+ var ams = globals.MyAMS;
+
+ ams.events = {
/**
* Initialize events listeners
@@ -5054,10 +5044,9 @@
*/
(function($, globals) {
- var MyAMS = globals.MyAMS,
- ams = MyAMS;
-
- MyAMS.container = {
+ var ams = globals.MyAMS;
+
+ ams.container = {
/**
* Change container elements order
@@ -5080,7 +5069,7 @@
deleteElement: function() {
return function() {
var link = $(this);
- MyAMS.skin.bigBox({
+ ams.skin.bigBox({
title: ams.i18n.WARNING,
content: '<i class="text-danger fa fa-fw fa-bell"></i> ' + ams.i18n.DELETE_WARNING,
status: 'info',
@@ -5095,7 +5084,7 @@
}
var deleteTarget = tr.data('ams-delete-target') || table.data('ams-delete-target') || 'delete-element.json';
var objectName = tr.data('ams-element-name');
- MyAMS.ajax.post(location + deleteTarget, {'object_name': objectName}, function(result, status) {
+ ams.ajax.post(location + deleteTarget, {'object_name': objectName}, function(result, status) {
if (result.status === 'success') {
if (table.hasClass('datatable')) {
table.dataTable().fnDeleteRow(tr[0]);
@@ -5103,10 +5092,10 @@
tr.remove();
}
if (result.handle_json) {
- MyAMS.ajax.handleJSON(result);
+ ams.ajax.handleJSON(result);
}
} else {
- MyAMS.ajax.handleJSON(result);
+ ams.ajax.handleJSON(result);
}
});
}
@@ -5169,10 +5158,9 @@
*/
(function($, globals) {
- var MyAMS = globals.MyAMS,
- ams = MyAMS;
-
- MyAMS.tree = {
+ var ams = globals.MyAMS;
+
+ ams.tree = {
/**
* Open close tree node inside a table
@@ -5201,7 +5189,7 @@
var sourceName = tr.data('ams-element-name');
switcher.removeClass('fa-plus-square-o')
.addClass('fa-cog fa-spin');
- MyAMS.ajax.post(location + '/' + sourceName + '/' + treeNodesTarget, {
+ ams.ajax.post(location + '/' + sourceName + '/' + treeNodesTarget, {
can_sort: !$('td.sorter', tr).is(':empty')
}, function(result, status) {
if (result.length > 0) {
@@ -5241,7 +5229,7 @@
var target = table.data('ams-tree-nodes-target') || 'get-tree.json';
switcher.removeClass('fa-plus-square-o')
.addClass('fa-cog fa-spin');
- MyAMS.ajax.post(location + '/' + target, {
+ ams.ajax.post(location + '/' + target, {
can_sort: !$('td.sorter', tr).is(':empty')
}, function(result, status) {
$('tr[data-ams-tree-node-id]', table).remove();
@@ -5399,10 +5387,9 @@
*/
(function($, globals) {
- var MyAMS = globals.MyAMS,
- ams = MyAMS;
-
- MyAMS.skin = {
+ var ams = globals.MyAMS;
+
+ ams.skin = {
/**
* Compute navigation page height
@@ -5478,7 +5465,7 @@
var target = $('[id="' + options.object_id + '"]');
target.replaceWith($(options.content));
target = $('[id="' + options.object_id + '"]');
- MyAMS.initContent(target);
+ ams.initContent(target);
return target;
},
@@ -5500,7 +5487,7 @@
}
var label = widget.parents('.input').last();
label.html(options.content);
- MyAMS.initContent(label);
+ ams.initContent(label);
return label;
},
@@ -5511,7 +5498,7 @@
var widget = $('[id="' + options.object_id + '"]').parents('.ams-widget:first');
widget.replaceWith($(options.table));
widget = $('[id="' + options.object_id + '"]').parents('.ams-widget:first');
- MyAMS.initContent(widget);
+ ams.initContent(widget);
return widget;
},
@@ -5535,7 +5522,7 @@
var table = tr.parents('table').first();
var new_tr = $(options.row);
tr.replaceWith(new_tr);
- MyAMS.initContent(new_tr);
+ ams.initContent(new_tr);
if (table.hasClass('table-dnd')) {
new_tr.addClass('no-drag-handle');
table.tableDnDUpdate();
@@ -5555,7 +5542,7 @@
if (index > -1) {
var cell = $($('td', tr).get(index));
cell.html(options.cell);
- MyAMS.initContent(cell);
+ ams.initContent(cell);
}
},
@@ -5568,18 +5555,18 @@
if (switcher.hasClass('fa-plus-square-o')) {
var container = datatype.parents('table');
innerdiv.html('<h1 class="loading"><i class="fa fa-gear fa-spin"></i></h1>');
- MyAMS.ajax.post(container.data('ams-location') + '/' + source.data('ams-switch-handler'),
- {object_name: datatype.data('ams-element-name')},
- function(result) {
- innerdiv.html(result);
- if (result) {
- MyAMS.initContent(innerdiv);
- switcher.removeClass('fa-plus-square-o')
- .addClass('fa-minus-square-o');
- }
- });
+ ams.ajax.post(container.data('ams-location') + '/' + source.data('ams-switch-handler'),
+ {object_name: datatype.data('ams-element-name')},
+ function (result) {
+ innerdiv.html(result);
+ if (result) {
+ ams.initContent(innerdiv);
+ switcher.removeClass('fa-plus-square-o')
+ .addClass('fa-minus-square-o');
+ }
+ });
} else {
- MyAMS.skin.cleanContainer(innerdiv);
+ ams.skin.cleanContainer(innerdiv);
innerdiv.empty();
switcher.removeClass('fa-minus-square-o')
.addClass('fa-plus-square-o');
@@ -5996,10 +5983,9 @@
*/
(function($, globals) {
- var MyAMS = globals.MyAMS,
- ams = MyAMS;
-
- MyAMS.stats = {
+ var ams = globals.MyAMS;
+
+ ams.stats = {
/**
* Log current or specified page load
@@ -6040,10 +6026,9 @@
*/
(function($, globals) {
- var MyAMS = globals.MyAMS,
- ams = MyAMS;
-
- MyAMS.initPage = function() {
+ var ams = globals.MyAMS;
+
+ ams.initPage = function() {
var body = $('body');
@@ -6595,7 +6580,7 @@
// Enable custom MyAMS refresh events
$(document).on('myams.refresh', function(event, options) {
- MyAMS.executeFunctionByName(options.handler || MyAMS.skin.refreshContent, event.target, options);
+ ams.executeFunctionByName(options.handler || ams.skin.refreshContent, event.target, options);
});
// Init page content
@@ -6616,7 +6601,7 @@
* This code is called to initialize plugins, callbacks and events listeners each time an HTML content
* is loaded dynamically from remote server.
*/
- MyAMS.initContent = function(element) {
+ ams.initContent = function(element) {
// Remove left tips
$('.tipsy').remove();
@@ -6650,7 +6635,7 @@
/**
* MyAMS locale strings
*/
- MyAMS.i18n = {
+ ams.i18n = {
INFO: "Information",
WARNING: "!! WARNING !!",
@@ -6710,7 +6695,7 @@
DT_COLUMNS: "Columns"
}
- MyAMS.plugins.i18n = {
+ ams.plugins.i18n = {
widgets: {},
validate: {},
datatables: {},
@@ -6743,12 +6728,12 @@
.addClass('js');
var lang = html.attr('lang') || html.attr('xml:lang');
if (lang && !lang.startsWith('en')) {
- MyAMS.lang = lang;
- MyAMS.getScript(MyAMS.baseURL + 'i18n/myams_' + lang.substr(0, 2) + MyAMS.devext + '.js', function () {
- MyAMS.initPage();
+ ams.lang = lang;
+ ams.getScript(ams.baseURL + 'i18n/myams_' + lang.substr(0, 2) + ams.devext + '.js', function () {
+ ams.initPage();
});
} else {
- MyAMS.initPage();
+ ams.initPage();
}
});