236 /** |
236 /** |
237 * Get MyAMS base URL |
237 * Get MyAMS base URL |
238 * Copyright Andrew Davy: https://forrst.com/posts/Get_the_URL_of_the_current_javascript_file-Dst |
238 * Copyright Andrew Davy: https://forrst.com/posts/Get_the_URL_of_the_current_javascript_file-Dst |
239 */ |
239 */ |
240 MyAMS.baseURL = (function () { |
240 MyAMS.baseURL = (function () { |
241 var script = $('script[src*="/myams.js"], script[src*="/myams.min.js"], script[src*="/myams-core.js"], script[src*="/myams-core.min.js"]'); |
241 var script = $('script[src*="/myams.js"], script[src*="/myams.min.js"], ' + |
|
242 'script[src*="/myams-core.js"], script[src*="/myams-core.min.js"], ' + |
|
243 'script[src*="/myams-require.js"], script[src*="/myams-require.min.js"]'); |
242 var src = script.attr("src"); |
244 var src = script.attr("src"); |
243 ams.devmode = src.indexOf('.min.js') < 0; |
245 ams.devmode = src.indexOf('.min.js') < 0; |
244 ams.devext = ams.devmode ? '' : '.min'; |
246 ams.devext = ams.devmode ? '' : '.min'; |
245 return src.substring(0, src.lastIndexOf('/') + 1); |
247 return src.substring(0, src.lastIndexOf('/') + 1); |
246 })(); |
248 })(); |
395 * Script loader function |
397 * Script loader function |
396 * |
398 * |
397 * @param url: script URL |
399 * @param url: script URL |
398 * @param callback: a callback to be called after script loading |
400 * @param callback: a callback to be called after script loading |
399 * @param options: a set of options to be added to AJAX call |
401 * @param options: a set of options to be added to AJAX call |
|
402 * @param onerror: an error callback to be called instead of generic callback |
400 */ |
403 */ |
401 MyAMS.getScript = function (url, callback, options) { |
404 MyAMS.getScript = function (url, callback, options, onerror) { |
402 if (typeof(callback) === 'object') { |
405 if (typeof(callback) === 'object') { |
|
406 onerror = options; |
403 options = callback; |
407 options = callback; |
404 callback = null; |
408 callback = null; |
405 } |
409 } |
406 if (options === undefined) { |
410 if (options === undefined) { |
407 options = {}; |
411 options = {}; |
408 } |
412 } |
409 var defaults = { |
413 var defaults = { |
410 dataType: 'script', |
414 dataType: 'script', |
411 url: ams.getSource(url), |
415 url: ams.getSource(url), |
412 success: callback, |
416 success: callback, |
413 error: ams.error.show, |
417 error: onerror || ams.error.show, |
414 cache: !ams.devmode, |
418 cache: !ams.devmode, |
415 async: options.async === undefined ? typeof(callback) === 'function' : options.async |
419 async: options.async === undefined ? typeof(callback) === 'function' : options.async |
416 }; |
420 }; |
417 var settings = $.extend({}, defaults, options); |
421 var settings = $.extend({}, defaults, options); |
418 return $.ajax(settings); |
422 return $.ajax(settings); |
695 /** |
698 /** |
696 * MyAMS events management |
699 * MyAMS events management |
697 */ |
700 */ |
698 (function($, globals) { |
701 (function($, globals) { |
699 |
702 |
700 var MyAMS = globals.MyAMS, |
703 var ams = globals.MyAMS; |
701 ams = MyAMS; |
704 |
702 |
705 ams.event = { |
703 MyAMS.event = { |
|
704 |
706 |
705 /** |
707 /** |
706 * Stop current event propagation |
708 * Stop current event propagation |
707 */ |
709 */ |
708 stop: function(event) { |
710 stop: function(event) { |
823 : ams.i18n.CLIPBOARD_CHARACTER_COPY_OK, |
824 : ams.i18n.CLIPBOARD_CHARACTER_COPY_OK, |
824 icon: 'fa fa-fw fa-info-circle font-xs align-top margin-top-10', |
825 icon: 'fa fa-fw fa-info-circle font-xs align-top margin-top-10', |
825 timeout: 3000 |
826 timeout: 3000 |
826 }); |
827 }); |
827 } else if (globals.prompt) { |
828 } else if (globals.prompt) { |
828 globals.prompt(MyAMS.i18n.CLIPBOARD_COPY, text); |
829 globals.prompt(ams.i18n.CLIPBOARD_COPY, text); |
829 } |
830 } |
830 } |
831 } |
831 |
832 |
832 if (text === undefined) { |
833 if (text === undefined) { |
833 return function() { |
834 return function() { |
847 /** |
848 /** |
848 * MyAMS errors management |
849 * MyAMS errors management |
849 */ |
850 */ |
850 (function($, globals) { |
851 (function($, globals) { |
851 |
852 |
852 var MyAMS = globals.MyAMS, |
853 var ams = globals.MyAMS; |
853 ams = MyAMS; |
854 |
854 |
855 ams.error = { |
855 MyAMS.error = { |
|
856 |
856 |
857 /** |
857 /** |
858 * Default JQuery AJAX error handler |
858 * Default JQuery AJAX error handler |
859 */ |
859 */ |
860 ajax: function(event, response, request, error) { |
860 ajax: function(event, response, request, error) { |
914 /** |
914 /** |
915 * MyAMS AJAX features |
915 * MyAMS AJAX features |
916 */ |
916 */ |
917 (function($, globals) { |
917 (function($, globals) { |
918 |
918 |
919 var MyAMS = globals.MyAMS, |
919 var ams = globals.MyAMS; |
920 ams = MyAMS; |
920 |
921 |
921 ams.ajax = { |
922 MyAMS.ajax = { |
|
923 |
922 |
924 /** |
923 /** |
925 * Check for given feature and download script if necessary |
924 * Check for given feature and download script if necessary |
926 * |
925 * |
927 * @param checker: pointer to a javascript object which will be downloaded in undefined |
926 * @param checker: pointer to a javascript object which will be downloaded in undefined |
1376 /** |
1375 /** |
1377 * MyAMS JSON-RPC features |
1376 * MyAMS JSON-RPC features |
1378 */ |
1377 */ |
1379 (function($, globals) { |
1378 (function($, globals) { |
1380 |
1379 |
1381 var MyAMS = globals.MyAMS, |
1380 var ams = globals.MyAMS; |
1382 ams = MyAMS; |
1381 |
1383 |
1382 ams.jsonrpc = { |
1384 MyAMS.jsonrpc = { |
|
1385 |
1383 |
1386 /** |
1384 /** |
1387 * Get address relative to current page |
1385 * Get address relative to current page |
1388 */ |
1386 */ |
1389 getAddr: function(addr) { |
1387 getAddr: function(addr) { |
1504 /** |
1502 /** |
1505 * MyAMS XML-RPC features |
1503 * MyAMS XML-RPC features |
1506 */ |
1504 */ |
1507 (function($, globals) { |
1505 (function($, globals) { |
1508 |
1506 |
1509 var MyAMS = globals.MyAMS, |
1507 var ams = globals.MyAMS; |
1510 ams = MyAMS; |
1508 |
1511 |
1509 ams.xmlrpc = { |
1512 MyAMS.xmlrpc = { |
|
1513 |
1510 |
1514 /** |
1511 /** |
1515 * Get address relative to current page |
1512 * Get address relative to current page |
1516 */ |
1513 */ |
1517 getAddr: function(addr) { |
1514 getAddr: function(addr) { |
1570 /** |
1567 /** |
1571 * MyAMS forms management |
1568 * MyAMS forms management |
1572 */ |
1569 */ |
1573 (function($, globals) { |
1570 (function($, globals) { |
1574 |
1571 |
1575 var MyAMS = globals.MyAMS, |
1572 var ams = globals.MyAMS; |
1576 ams = MyAMS; |
1573 |
1577 |
1574 ams.form = { |
1578 MyAMS.form = { |
|
1579 |
1575 |
1580 /** |
1576 /** |
1581 * Init forms to activate form change listeners |
1577 * Init forms to activate form change listeners |
1582 * |
1578 * |
1583 * @param element: the parent element |
1579 * @param element: the parent element |
2317 /** |
2313 /** |
2318 * MyAMS modal dialogs management |
2314 * MyAMS modal dialogs management |
2319 */ |
2315 */ |
2320 (function($, globals) { |
2316 (function($, globals) { |
2321 |
2317 |
2322 var MyAMS = globals.MyAMS, |
2318 var ams = globals.MyAMS; |
2323 ams = MyAMS; |
2319 |
2324 |
2320 ams.dialog = { |
2325 MyAMS.dialog = { |
|
2326 |
2321 |
2327 /** |
2322 /** |
2328 * List of registered 'shown' callbacks |
2323 * List of registered 'shown' callbacks |
2329 */ |
2324 */ |
2330 _shown_callbacks: [], |
2325 _shown_callbacks: [], |
2620 * They have been extracted from these extensions management code to reuse them more easily into |
2615 * They have been extracted from these extensions management code to reuse them more easily into |
2621 * application specific callbacks. |
2616 * application specific callbacks. |
2622 */ |
2617 */ |
2623 (function($, globals) { |
2618 (function($, globals) { |
2624 |
2619 |
2625 var MyAMS = globals.MyAMS, |
2620 var ams = globals.MyAMS; |
2626 ams = MyAMS; |
2621 |
2627 |
2622 ams.helpers = { |
2628 MyAMS.helpers = { |
|
2629 |
2623 |
2630 /** Sort DOM elements into selected container */ |
2624 /** Sort DOM elements into selected container */ |
2631 sort: function(container, attribute) { |
2625 sort: function(container, attribute) { |
2632 if (!attribute) { |
2626 if (!attribute) { |
2633 attribute = 'weight'; |
2627 attribute = 'weight'; |
2873 * dynamic hidden input fields created by JQuery-validate plug-in will be removed from the form |
2867 * dynamic hidden input fields created by JQuery-validate plug-in will be removed from the form |
2874 * before the form is submitted! |
2868 * before the form is submitted! |
2875 */ |
2869 */ |
2876 (function($, globals) { |
2870 (function($, globals) { |
2877 |
2871 |
2878 var MyAMS = globals.MyAMS, |
2872 var ams = globals.MyAMS; |
2879 ams = MyAMS; |
2873 |
2880 |
2874 ams.plugins = { |
2881 MyAMS.plugins = { |
|
2882 |
2875 |
2883 /** |
2876 /** |
2884 * Container of enabled plug-ins |
2877 * Container of enabled plug-ins |
2885 */ |
2878 */ |
2886 enabled: {}, |
2879 enabled: {}, |
3150 * dynamic hidden input fields created by JQuery-validate plug-in will be removed from the form |
3143 * dynamic hidden input fields created by JQuery-validate plug-in will be removed from the form |
3151 * before the form is submitted! |
3144 * before the form is submitted! |
3152 */ |
3145 */ |
3153 (function($, globals) { |
3146 (function($, globals) { |
3154 |
3147 |
3155 var MyAMS = globals.MyAMS, |
3148 var ams = globals.MyAMS; |
3156 ams = MyAMS; |
|
3157 |
3149 |
3158 /** |
3150 /** |
3159 * Map of enabled plug-ins |
3151 * Map of enabled plug-ins |
3160 * This map can be extended by external plug-ins. |
3152 * This map can be extended by external plug-ins. |
3161 * |
3153 * |
4851 /** |
4843 /** |
4852 * MyAMS callbacks management |
4844 * MyAMS callbacks management |
4853 */ |
4845 */ |
4854 (function($, globals) { |
4846 (function($, globals) { |
4855 |
4847 |
4856 var MyAMS = globals.MyAMS, |
4848 var ams = globals.MyAMS; |
4857 ams = MyAMS; |
4849 |
4858 |
4850 ams.callbacks = { |
4859 MyAMS.callbacks = { |
|
4860 |
4851 |
4861 /** |
4852 /** |
4862 * Initialize list of callbacks |
4853 * Initialize list of callbacks |
4863 * |
4854 * |
4864 * Callbacks are initialized each time a page content is loaded and integrated into page's DOM. |
4855 * Callbacks are initialized each time a page content is loaded and integrated into page's DOM. |
5017 /** |
5008 /** |
5018 * MyAMS events management |
5009 * MyAMS events management |
5019 */ |
5010 */ |
5020 (function($, globals) { |
5011 (function($, globals) { |
5021 |
5012 |
5022 var MyAMS = globals.MyAMS, |
5013 var ams = globals.MyAMS; |
5023 ams = MyAMS; |
5014 |
5024 |
5015 ams.events = { |
5025 MyAMS.events = { |
|
5026 |
5016 |
5027 /** |
5017 /** |
5028 * Initialize events listeners |
5018 * Initialize events listeners |
5029 * |
5019 * |
5030 * "data-ams-events-handlers" is a data attribute containing a JSON object where: |
5020 * "data-ams-events-handlers" is a data attribute containing a JSON object where: |
5052 /** |
5042 /** |
5053 * MyAMS containers management |
5043 * MyAMS containers management |
5054 */ |
5044 */ |
5055 (function($, globals) { |
5045 (function($, globals) { |
5056 |
5046 |
5057 var MyAMS = globals.MyAMS, |
5047 var ams = globals.MyAMS; |
5058 ams = MyAMS; |
5048 |
5059 |
5049 ams.container = { |
5060 MyAMS.container = { |
|
5061 |
5050 |
5062 /** |
5051 /** |
5063 * Change container elements order |
5052 * Change container elements order |
5064 * |
5053 * |
5065 * This is a callback which may be used with TableDnD plug-in which allows you to |
5054 * This is a callback which may be used with TableDnD plug-in which allows you to |
5078 * @returns {Function} |
5067 * @returns {Function} |
5079 */ |
5068 */ |
5080 deleteElement: function() { |
5069 deleteElement: function() { |
5081 return function() { |
5070 return function() { |
5082 var link = $(this); |
5071 var link = $(this); |
5083 MyAMS.skin.bigBox({ |
5072 ams.skin.bigBox({ |
5084 title: ams.i18n.WARNING, |
5073 title: ams.i18n.WARNING, |
5085 content: '<i class="text-danger fa fa-fw fa-bell"></i> ' + ams.i18n.DELETE_WARNING, |
5074 content: '<i class="text-danger fa fa-fw fa-bell"></i> ' + ams.i18n.DELETE_WARNING, |
5086 status: 'info', |
5075 status: 'info', |
5087 buttons: ams.i18n.BTN_OK_CANCEL |
5076 buttons: ams.i18n.BTN_OK_CANCEL |
5088 }, function(button) { |
5077 }, function(button) { |
5093 if (location) { |
5082 if (location) { |
5094 location += '/'; |
5083 location += '/'; |
5095 } |
5084 } |
5096 var deleteTarget = tr.data('ams-delete-target') || table.data('ams-delete-target') || 'delete-element.json'; |
5085 var deleteTarget = tr.data('ams-delete-target') || table.data('ams-delete-target') || 'delete-element.json'; |
5097 var objectName = tr.data('ams-element-name'); |
5086 var objectName = tr.data('ams-element-name'); |
5098 MyAMS.ajax.post(location + deleteTarget, {'object_name': objectName}, function(result, status) { |
5087 ams.ajax.post(location + deleteTarget, {'object_name': objectName}, function(result, status) { |
5099 if (result.status === 'success') { |
5088 if (result.status === 'success') { |
5100 if (table.hasClass('datatable')) { |
5089 if (table.hasClass('datatable')) { |
5101 table.dataTable().fnDeleteRow(tr[0]); |
5090 table.dataTable().fnDeleteRow(tr[0]); |
5102 } else { |
5091 } else { |
5103 tr.remove(); |
5092 tr.remove(); |
5104 } |
5093 } |
5105 if (result.handle_json) { |
5094 if (result.handle_json) { |
5106 MyAMS.ajax.handleJSON(result); |
5095 ams.ajax.handleJSON(result); |
5107 } |
5096 } |
5108 } else { |
5097 } else { |
5109 MyAMS.ajax.handleJSON(result); |
5098 ams.ajax.handleJSON(result); |
5110 } |
5099 } |
5111 }); |
5100 }); |
5112 } |
5101 } |
5113 }); |
5102 }); |
5114 }; |
5103 }; |
5167 /** |
5156 /** |
5168 * MyAMS tree management |
5157 * MyAMS tree management |
5169 */ |
5158 */ |
5170 (function($, globals) { |
5159 (function($, globals) { |
5171 |
5160 |
5172 var MyAMS = globals.MyAMS, |
5161 var ams = globals.MyAMS; |
5173 ams = MyAMS; |
5162 |
5174 |
5163 ams.tree = { |
5175 MyAMS.tree = { |
|
5176 |
5164 |
5177 /** |
5165 /** |
5178 * Open close tree node inside a table |
5166 * Open close tree node inside a table |
5179 */ |
5167 */ |
5180 switchTableNode: function() { |
5168 switchTableNode: function() { |
5199 var location = tr.data('ams-location') || table.data('ams-location') || ''; |
5187 var location = tr.data('ams-location') || table.data('ams-location') || ''; |
5200 var treeNodesTarget = tr.data('ams-tree-nodes-target') || table.data('ams-tree-nodes-target') || 'get-tree-nodes.json'; |
5188 var treeNodesTarget = tr.data('ams-tree-nodes-target') || table.data('ams-tree-nodes-target') || 'get-tree-nodes.json'; |
5201 var sourceName = tr.data('ams-element-name'); |
5189 var sourceName = tr.data('ams-element-name'); |
5202 switcher.removeClass('fa-plus-square-o') |
5190 switcher.removeClass('fa-plus-square-o') |
5203 .addClass('fa-cog fa-spin'); |
5191 .addClass('fa-cog fa-spin'); |
5204 MyAMS.ajax.post(location + '/' + sourceName + '/' + treeNodesTarget, { |
5192 ams.ajax.post(location + '/' + sourceName + '/' + treeNodesTarget, { |
5205 can_sort: !$('td.sorter', tr).is(':empty') |
5193 can_sort: !$('td.sorter', tr).is(':empty') |
5206 }, function(result, status) { |
5194 }, function(result, status) { |
5207 if (result.length > 0) { |
5195 if (result.length > 0) { |
5208 var old_row = tr; |
5196 var old_row = tr; |
5209 for (var index = 0; index < result.length; index++) { |
5197 for (var index = 0; index < result.length; index++) { |
5239 var tr = $('tbody tr', table).first(); |
5227 var tr = $('tbody tr', table).first(); |
5240 var location = table.data('ams-location') || ''; |
5228 var location = table.data('ams-location') || ''; |
5241 var target = table.data('ams-tree-nodes-target') || 'get-tree.json'; |
5229 var target = table.data('ams-tree-nodes-target') || 'get-tree.json'; |
5242 switcher.removeClass('fa-plus-square-o') |
5230 switcher.removeClass('fa-plus-square-o') |
5243 .addClass('fa-cog fa-spin'); |
5231 .addClass('fa-cog fa-spin'); |
5244 MyAMS.ajax.post(location + '/' + target, { |
5232 ams.ajax.post(location + '/' + target, { |
5245 can_sort: !$('td.sorter', tr).is(':empty') |
5233 can_sort: !$('td.sorter', tr).is(':empty') |
5246 }, function(result, status) { |
5234 }, function(result, status) { |
5247 $('tr[data-ams-tree-node-id]', table).remove(); |
5235 $('tr[data-ams-tree-node-id]', table).remove(); |
5248 var old_row = null; |
5236 var old_row = null; |
5249 for (var index = 0; index < result.length; index++) { |
5237 for (var index = 0; index < result.length; index++) { |
5397 /** |
5385 /** |
5398 * MyAMS skin management |
5386 * MyAMS skin management |
5399 */ |
5387 */ |
5400 (function($, globals) { |
5388 (function($, globals) { |
5401 |
5389 |
5402 var MyAMS = globals.MyAMS, |
5390 var ams = globals.MyAMS; |
5403 ams = MyAMS; |
5391 |
5404 |
5392 ams.skin = { |
5405 MyAMS.skin = { |
|
5406 |
5393 |
5407 /** |
5394 /** |
5408 * Compute navigation page height |
5395 * Compute navigation page height |
5409 */ |
5396 */ |
5410 _setPageHeight: function() { |
5397 _setPageHeight: function() { |
5476 */ |
5463 */ |
5477 refreshContent: function(options) { |
5464 refreshContent: function(options) { |
5478 var target = $('[id="' + options.object_id + '"]'); |
5465 var target = $('[id="' + options.object_id + '"]'); |
5479 target.replaceWith($(options.content)); |
5466 target.replaceWith($(options.content)); |
5480 target = $('[id="' + options.object_id + '"]'); |
5467 target = $('[id="' + options.object_id + '"]'); |
5481 MyAMS.initContent(target); |
5468 ams.initContent(target); |
5482 return target; |
5469 return target; |
5483 }, |
5470 }, |
5484 |
5471 |
5485 /** |
5472 /** |
5486 * Replace given image from updated source |
5473 * Replace given image from updated source |
5498 if (!widget.exists()) { |
5485 if (!widget.exists()) { |
5499 widget = $('[name="' + options.widget_name + ':list"]', target); |
5486 widget = $('[name="' + options.widget_name + ':list"]', target); |
5500 } |
5487 } |
5501 var label = widget.parents('.input').last(); |
5488 var label = widget.parents('.input').last(); |
5502 label.html(options.content); |
5489 label.html(options.content); |
5503 MyAMS.initContent(label); |
5490 ams.initContent(label); |
5504 return label; |
5491 return label; |
5505 }, |
5492 }, |
5506 |
5493 |
5507 /** |
5494 /** |
5508 * Replace given table with new content |
5495 * Replace given table with new content |
5509 */ |
5496 */ |
5510 refreshTable: function(options) { |
5497 refreshTable: function(options) { |
5511 var widget = $('[id="' + options.object_id + '"]').parents('.ams-widget:first'); |
5498 var widget = $('[id="' + options.object_id + '"]').parents('.ams-widget:first'); |
5512 widget.replaceWith($(options.table)); |
5499 widget.replaceWith($(options.table)); |
5513 widget = $('[id="' + options.object_id + '"]').parents('.ams-widget:first'); |
5500 widget = $('[id="' + options.object_id + '"]').parents('.ams-widget:first'); |
5514 MyAMS.initContent(widget); |
5501 ams.initContent(widget); |
5515 return widget; |
5502 return widget; |
5516 }, |
5503 }, |
5517 |
5504 |
5518 /** |
5505 /** |
5519 * Replace given table with new content |
5506 * Replace given table with new content |
5533 refreshRow: function(options) { |
5520 refreshRow: function(options) { |
5534 var tr = $('tr[id="' + options.object_id + '"]'); |
5521 var tr = $('tr[id="' + options.object_id + '"]'); |
5535 var table = tr.parents('table').first(); |
5522 var table = tr.parents('table').first(); |
5536 var new_tr = $(options.row); |
5523 var new_tr = $(options.row); |
5537 tr.replaceWith(new_tr); |
5524 tr.replaceWith(new_tr); |
5538 MyAMS.initContent(new_tr); |
5525 ams.initContent(new_tr); |
5539 if (table.hasClass('table-dnd')) { |
5526 if (table.hasClass('table-dnd')) { |
5540 new_tr.addClass('no-drag-handle'); |
5527 new_tr.addClass('no-drag-handle'); |
5541 table.tableDnDUpdate(); |
5528 table.tableDnDUpdate(); |
5542 } |
5529 } |
5543 return new_tr; |
5530 return new_tr; |
5553 var headCell = $('th[data-ams-column-name="' + options.col_name + '"]', headRow); |
5540 var headCell = $('th[data-ams-column-name="' + options.col_name + '"]', headRow); |
5554 var index = $('th', headRow).index(headCell); |
5541 var index = $('th', headRow).index(headCell); |
5555 if (index > -1) { |
5542 if (index > -1) { |
5556 var cell = $($('td', tr).get(index)); |
5543 var cell = $($('td', tr).get(index)); |
5557 cell.html(options.cell); |
5544 cell.html(options.cell); |
5558 MyAMS.initContent(cell); |
5545 ams.initContent(cell); |
5559 } |
5546 } |
5560 }, |
5547 }, |
5561 |
5548 |
5562 switchCellContent: function(element) { |
5549 switchCellContent: function(element) { |
5563 var source = $(this); |
5550 var source = $(this); |
5566 var innerdiv = $(source.data('ams-switch-target') || '.inner-table-form', td); |
5553 var innerdiv = $(source.data('ams-switch-target') || '.inner-table-form', td); |
5567 var datatype = source.parents('tr'); |
5554 var datatype = source.parents('tr'); |
5568 if (switcher.hasClass('fa-plus-square-o')) { |
5555 if (switcher.hasClass('fa-plus-square-o')) { |
5569 var container = datatype.parents('table'); |
5556 var container = datatype.parents('table'); |
5570 innerdiv.html('<h1 class="loading"><i class="fa fa-gear fa-spin"></i></h1>'); |
5557 innerdiv.html('<h1 class="loading"><i class="fa fa-gear fa-spin"></i></h1>'); |
5571 MyAMS.ajax.post(container.data('ams-location') + '/' + source.data('ams-switch-handler'), |
5558 ams.ajax.post(container.data('ams-location') + '/' + source.data('ams-switch-handler'), |
5572 {object_name: datatype.data('ams-element-name')}, |
5559 {object_name: datatype.data('ams-element-name')}, |
5573 function(result) { |
5560 function (result) { |
5574 innerdiv.html(result); |
5561 innerdiv.html(result); |
5575 if (result) { |
5562 if (result) { |
5576 MyAMS.initContent(innerdiv); |
5563 ams.initContent(innerdiv); |
5577 switcher.removeClass('fa-plus-square-o') |
5564 switcher.removeClass('fa-plus-square-o') |
5578 .addClass('fa-minus-square-o'); |
5565 .addClass('fa-minus-square-o'); |
5579 } |
5566 } |
5580 }); |
5567 }); |
5581 } else { |
5568 } else { |
5582 MyAMS.skin.cleanContainer(innerdiv); |
5569 ams.skin.cleanContainer(innerdiv); |
5583 innerdiv.empty(); |
5570 innerdiv.empty(); |
5584 switcher.removeClass('fa-minus-square-o') |
5571 switcher.removeClass('fa-minus-square-o') |
5585 .addClass('fa-plus-square-o'); |
5572 .addClass('fa-plus-square-o'); |
5586 } |
5573 } |
5587 }, |
5574 }, |
5994 /** |
5981 /** |
5995 * MyAMS stats management |
5982 * MyAMS stats management |
5996 */ |
5983 */ |
5997 (function($, globals) { |
5984 (function($, globals) { |
5998 |
5985 |
5999 var MyAMS = globals.MyAMS, |
5986 var ams = globals.MyAMS; |
6000 ams = MyAMS; |
5987 |
6001 |
5988 ams.stats = { |
6002 MyAMS.stats = { |
|
6003 |
5989 |
6004 /** |
5990 /** |
6005 * Log current or specified page load |
5991 * Log current or specified page load |
6006 */ |
5992 */ |
6007 logPageview: function(url) { |
5993 logPageview: function(url) { |
6038 * MyAMS page initialization |
6024 * MyAMS page initialization |
6039 * This code is called once to register global events and callbacks |
6025 * This code is called once to register global events and callbacks |
6040 */ |
6026 */ |
6041 (function($, globals) { |
6027 (function($, globals) { |
6042 |
6028 |
6043 var MyAMS = globals.MyAMS, |
6029 var ams = globals.MyAMS; |
6044 ams = MyAMS; |
6030 |
6045 |
6031 ams.initPage = function() { |
6046 MyAMS.initPage = function() { |
|
6047 |
6032 |
6048 var body = $('body'); |
6033 var body = $('body'); |
6049 |
6034 |
6050 /* Init main components */ |
6035 /* Init main components */ |
6051 ams.root = body; |
6036 ams.root = body; |
6593 }); |
6578 }); |
6594 }); |
6579 }); |
6595 |
6580 |
6596 // Enable custom MyAMS refresh events |
6581 // Enable custom MyAMS refresh events |
6597 $(document).on('myams.refresh', function(event, options) { |
6582 $(document).on('myams.refresh', function(event, options) { |
6598 MyAMS.executeFunctionByName(options.handler || MyAMS.skin.refreshContent, event.target, options); |
6583 ams.executeFunctionByName(options.handler || ams.skin.refreshContent, event.target, options); |
6599 }); |
6584 }); |
6600 |
6585 |
6601 // Init page content |
6586 // Init page content |
6602 ams.initContent(document); |
6587 ams.initContent(document); |
6603 if (ams.ajaxNav && nav.exists()) { |
6588 if (ams.ajaxNav && nav.exists()) { |
6614 /** |
6599 /** |
6615 * Main content plug-ins initializer |
6600 * Main content plug-ins initializer |
6616 * This code is called to initialize plugins, callbacks and events listeners each time an HTML content |
6601 * This code is called to initialize plugins, callbacks and events listeners each time an HTML content |
6617 * is loaded dynamically from remote server. |
6602 * is loaded dynamically from remote server. |
6618 */ |
6603 */ |
6619 MyAMS.initContent = function(element) { |
6604 ams.initContent = function(element) { |
6620 |
6605 |
6621 // Remove left tips |
6606 // Remove left tips |
6622 $('.tipsy').remove(); |
6607 $('.tipsy').remove(); |
6623 |
6608 |
6624 // Activate tooltips and popovers |
6609 // Activate tooltips and popovers |
6741 var html = $('HTML'); |
6726 var html = $('HTML'); |
6742 html.removeClass('no-js') |
6727 html.removeClass('no-js') |
6743 .addClass('js'); |
6728 .addClass('js'); |
6744 var lang = html.attr('lang') || html.attr('xml:lang'); |
6729 var lang = html.attr('lang') || html.attr('xml:lang'); |
6745 if (lang && !lang.startsWith('en')) { |
6730 if (lang && !lang.startsWith('en')) { |
6746 MyAMS.lang = lang; |
6731 ams.lang = lang; |
6747 MyAMS.getScript(MyAMS.baseURL + 'i18n/myams_' + lang.substr(0, 2) + MyAMS.devext + '.js', function () { |
6732 ams.getScript(ams.baseURL + 'i18n/myams_' + lang.substr(0, 2) + ams.devext + '.js', function () { |
6748 MyAMS.initPage(); |
6733 ams.initPage(); |
6749 }); |
6734 }); |
6750 } else { |
6735 } else { |
6751 MyAMS.initPage(); |
6736 ams.initPage(); |
6752 } |
6737 } |
6753 }); |
6738 }); |
6754 |
6739 |
6755 })(jQuery, this); |
6740 })(jQuery, this); |