289 return false; |
293 return false; |
290 } |
294 } |
291 }); |
295 }); |
292 if (close) { |
296 if (close) { |
293 if (parent_ul !== visible[visibleIndex]) { |
297 if (parent_ul !== visible[visibleIndex]) { |
294 $(visible[visibleIndex]).slideUp(settings.speed, function() { |
298 var visibleItem = $(visible[visibleIndex]); |
295 link.parent("LI") |
299 if (href || !visibleItem.hasClass('active')) { |
296 .find("b:first") |
300 visibleItem.slideUp(settings.speed, function () { |
297 .html(settings.closedSign); |
301 $(this).parent("LI") |
298 link.parent("LI") |
302 .removeClass('open') |
299 .removeClass("open"); |
303 .find("B:first") |
300 }); |
304 .delay(settings.speed) |
|
305 .html(settings.closedSign); |
|
306 }); |
|
307 } |
301 } |
308 } |
302 } |
309 } |
303 }); |
310 }); |
304 } |
311 } |
305 var first_ul = link.parent().find("UL:first"); |
312 var first_ul = link.parent().find("UL:first"); |
306 if (!link.attr('href').replace(/^#/,'') && |
313 if (!href && first_ul.is(":visible") && !first_ul.hasClass("active")) { |
307 first_ul.is(":visible") && |
|
308 !first_ul.hasClass("active")) { |
|
309 first_ul.slideUp(settings.speed, function() { |
314 first_ul.slideUp(settings.speed, function() { |
310 link.parent("LI") |
315 link.parent("LI") |
311 .removeClass("open") |
316 .removeClass("open") |
312 .find("B:first") |
317 .find("B:first") |
313 .delay(settings.speed) |
318 .delay(settings.speed) |
631 MyAMS.error = { |
636 MyAMS.error = { |
632 |
637 |
633 /** |
638 /** |
634 * Default JQuery AJAX error handler |
639 * Default JQuery AJAX error handler |
635 */ |
640 */ |
636 ajax: function(event, request /*, settings*/) { |
641 ajax: function(event, response, request, error) { |
637 if (request.statusText === 'OK') { |
642 if (response.statusText === 'OK') { |
638 return; |
643 return; |
639 } |
644 } |
640 var response = ams.ajax.getResponse(request); |
645 var ajax_response = ams.ajax.getResponse(response); |
641 if (response.content_type === 'json') { |
646 if (ajax_response.content_type === 'json') { |
642 ams.ajax.handleJSON(response.data); |
647 ams.ajax.handleJSON(ajax_response.data); |
643 } else { |
648 } else { |
644 var title = event.statusText || event.type; |
649 var title = event.statusText || event.type; |
645 var message = request.responseText; |
650 var message = response.responseText; |
646 ams.skin.messageBox('error', { |
651 ams.skin.messageBox('error', { |
647 title: ams.i18n.ERROR_OCCURED, |
652 title: ams.i18n.ERROR_OCCURED, |
648 content: '<h4>' + title + '</h4><p>' + message + '</p>', |
653 content: '<h4>' + title + '</h4><p>' + message + '</p>', |
649 icon: 'fa fa-warning animated shake', |
654 icon: 'fa fa-warning animated shake', |
650 timeout: 10000 |
655 timeout: 10000 |
651 }); |
656 }); |
652 } |
657 } |
653 if (globals.console) { |
658 if (globals.console) { |
654 globals.console.error(event); |
659 globals.console.error(event); |
655 globals.console.debug(request); |
660 globals.console.debug(response); |
656 } |
661 } |
657 }, |
662 }, |
658 |
663 |
659 /** |
664 /** |
660 * Show AJAX error |
665 * Show AJAX error |
2265 for (var index=0; index < plugins.length; index++) { |
2275 for (var index=0; index < plugins.length; index++) { |
2266 disabled.push(plugins[index]); |
2276 disabled.push(plugins[index]); |
2267 } |
2277 } |
2268 }); |
2278 }); |
2269 |
2279 |
2270 // Load and register new plug-ins |
2280 // Scan new element for plug-ins |
|
2281 var plugins = {}; |
|
2282 var plugin; |
|
2283 var name; |
|
2284 |
2271 $('[data-ams-plugins]', element).each(function() { |
2285 $('[data-ams-plugins]', element).each(function() { |
|
2286 |
|
2287 function registerPlugin(name, new_plugin) { |
|
2288 if (plugins.hasOwnProperty(name)) { |
|
2289 var plugin = plugins[name]; |
|
2290 plugin.css = plugin.css || new_plugin.css; |
|
2291 if (new_plugin.callback) { |
|
2292 plugin.callbacks.push(new_plugin.callback); |
|
2293 } |
|
2294 if (new_plugin.register) { |
|
2295 plugin.register = true; |
|
2296 } |
|
2297 if (new_plugin.async === false) { |
|
2298 plugin.async = false; |
|
2299 } |
|
2300 } else { |
|
2301 plugins[name] = { |
|
2302 src: new_plugin.src, |
|
2303 css: new_plugin.css, |
|
2304 callbacks: new_plugin.callback ? [new_plugin.callback] : [], |
|
2305 register: new_plugin.register, |
|
2306 async: new_plugin.async |
|
2307 } |
|
2308 } |
|
2309 } |
|
2310 |
2272 var source = $(this); |
2311 var source = $(this); |
2273 var plugins = {}; |
2312 var ams_plugins = source.data('ams-plugins'); |
2274 var name; |
2313 if (typeof(ams_plugins) === 'string') { |
2275 if (typeof(source.data('ams-plugins')) === 'string') { |
|
2276 var names = source.data('ams-plugins').split(/\s+/); |
2314 var names = source.data('ams-plugins').split(/\s+/); |
2277 for (var index=0; index < names.length; index++) { |
2315 for (var index = 0; index < names.length; index++) { |
2278 name = names[index]; |
2316 name = names[index]; |
2279 plugins[name] = { |
2317 var new_plugin = { |
2280 src: source.data('ams-plugin-' + name + '-src'), |
2318 src: source.data('ams-plugin-' + name + '-src'), |
2281 css: source.data('ams-plugin-' + name + '-css'), |
2319 css: source.data('ams-plugin-' + name + '-css'), |
2282 callback: source.data('ams-plugin-' + name + '-callback'), |
2320 callback: source.data('ams-plugin-' + name + '-callback'), |
2283 register: source.data('ams-plugin-' + name + '-register'), |
2321 register: source.data('ams-plugin-' + name + '-register'), |
2284 async: source.data('ams-plugin-' + name + '-async') |
2322 async: source.data('ams-plugin-' + name + '-async') |
2285 }; |
2323 }; |
|
2324 registerPlugin(name, new_plugin); |
2286 } |
2325 } |
2287 } else { |
2326 } else { |
2288 plugins = source.data('ams-plugins'); |
2327 for (name in ams_plugins) { |
2289 } |
2328 if (!ams_plugins.hasOwnProperty(name)) { |
2290 for (name in plugins) { |
2329 continue; |
2291 if (ams.plugins.enabled[name] === undefined) { |
2330 } |
2292 var plugin = plugins[name]; |
2331 registerPlugin(name, ams_plugins[name]); |
2293 ams.getScript(plugin.src, function() { |
2332 } |
2294 var callback = plugin.callback; |
2333 } |
2295 if (callback) { |
2334 }); |
2296 var called = ams.getFunctionByName(callback); |
2335 |
2297 if (plugin.register !== false) |
2336 // Load new plug-ins and execute async ones |
2298 ams.plugins.enabled[name] = called; |
2337 for (name in plugins) { |
2299 } else { |
2338 if (ams.plugins.enabled[name] === undefined) { |
2300 if (plugin.register !== false) |
2339 plugin = plugins[name]; |
2301 ams.plugins.enabled[name] = null; |
2340 ams.getScript(plugin.src, function() { |
|
2341 var index; |
|
2342 var callbacks = plugin.callbacks; |
|
2343 if (callbacks) { |
|
2344 for (index=0; index < callbacks.length; index++) { |
|
2345 var called = ams.getFunctionByName(callbacks[index]); |
|
2346 if (plugin.register !== false) { |
|
2347 var enabled = ams.plugins.enabled; |
|
2348 if (enabled.hasOwnProperty(name)) { |
|
2349 enabled[name].push(called); |
|
2350 } else { |
|
2351 enabled[name] = [called]; |
|
2352 } |
|
2353 } |
2302 } |
2354 } |
2303 var css = plugin['css']; |
2355 } else { |
2304 if (css) { |
2356 if (plugin.register !== false) { |
2305 ams.getCSS(css, name + '_css'); |
2357 ams.plugins.enabled[name] = null; |
2306 } |
2358 } |
2307 }, { |
2359 } |
2308 async: plugin.async === undefined ? true : plugin.async |
2360 var css = plugin.css; |
2309 }); |
2361 if (css) { |
2310 } |
2362 ams.getCSS(css, name + '_css'); |
2311 } |
2363 } |
2312 }); |
2364 // If running in async mode, registered plug-ins are run |
|
2365 // before callback is called so we call plug-in manually |
|
2366 if (callbacks && (plugin.async !== false)) { |
|
2367 for (index=0; index < callbacks.length; index++) { |
|
2368 callbacks[index](element); |
|
2369 } |
|
2370 } |
|
2371 }, { |
|
2372 async: plugin.async === undefined ? true : plugin.async |
|
2373 }); |
|
2374 } |
|
2375 } |
2313 |
2376 |
2314 // Run all enabled plug-ins |
2377 // Run all enabled plug-ins |
2315 for (var index in ams.plugins.enabled) { |
2378 for (var index in ams.plugins.enabled) { |
2316 if (!ams.plugins.enabled.hasOwnProperty(index)) { |
2379 if (!ams.plugins.enabled.hasOwnProperty(index)) { |
2317 continue; |
2380 continue; |
2318 } |
2381 } |
2319 if (disabled.indexOf(index) >= 0) { |
2382 if (disabled.indexOf(index) >= 0) { |
2320 continue; |
2383 continue; |
2321 } |
2384 } |
2322 var plugin = ams.plugins.enabled[index]; |
2385 var callbacks = ams.plugins.enabled[index]; |
2323 if (typeof(plugin) === 'function') { |
2386 switch (typeof(callbacks)) { |
2324 plugin(element); |
2387 case 'function': |
|
2388 callbacks(element); |
|
2389 break; |
|
2390 default: |
|
2391 for (var cb_index = 0; cb_index < callbacks.length; cb_index++) { |
|
2392 var callback = callbacks[cb_index]; |
|
2393 if (typeof(callback) === 'function') { |
|
2394 callback(element); |
|
2395 } |
|
2396 } |
2325 } |
2397 } |
2326 } |
2398 } |
2327 }, |
2399 }, |
2328 |
2400 |
2329 /** |
2401 /** |
2930 */ |
3002 */ |
2931 maskedit: function(element) { |
3003 maskedit: function(element) { |
2932 var masks = $('[data-mask]', element); |
3004 var masks = $('[data-mask]', element); |
2933 if (masks.length > 0) { |
3005 if (masks.length > 0) { |
2934 ams.ajax.check($.fn.mask, |
3006 ams.ajax.check($.fn.mask, |
2935 ams.baseURL + 'ext/jquery-maskedinput-1.3.1.min.js', |
3007 ams.baseURL + 'ext/jquery-maskedinput-1.4.1' + ams.devext + '.js', |
2936 function() { |
3008 function() { |
2937 masks.each(function() { |
3009 masks.each(function() { |
2938 var mask = $(this); |
3010 var mask = $(this); |
2939 var data = mask.data(); |
3011 var data = mask.data(); |
2940 var data_options = { |
3012 var data_options = { |
2941 placeholder: data.amsMaskeditPlaceholder || 'X' |
3013 placeholder: data.amsMaskeditPlaceholder === undefined ? 'X' : data.amsMaskeditPlaceholder, |
|
3014 complete: ams.getFunctionByName(data.amsMaskeditComplete) |
2942 }; |
3015 }; |
2943 var settings = $.extend({}, data_options, data.amsMaskeditOptions); |
3016 var settings = $.extend({}, data_options, data.amsMaskeditOptions); |
2944 settings = ams.executeFunctionByName(data.amsMaskeditInitCallback, mask, settings) || settings; |
3017 settings = ams.executeFunctionByName(data.amsMaskeditInitCallback, mask, settings) || settings; |
2945 var plugin = mask.mask(mask.attr('data-mask'), settings); |
3018 var plugin = mask.mask(mask.attr('data-mask'), settings); |
2946 ams.executeFunctionByName(data.amsMaskeditAfterInitCallback, mask, plugin, settings); |
3019 ams.executeFunctionByName(data.amsMaskeditAfterInitCallback, mask, plugin, settings); |
3395 ams.ajax.check($.fn.tableDnD, |
3468 ams.ajax.check($.fn.tableDnD, |
3396 ams.baseURL + 'ext/jquery-tablednd' + ams.devext + '.js', |
3469 ams.baseURL + 'ext/jquery-tablednd' + ams.devext + '.js', |
3397 function(first_load) { |
3470 function(first_load) { |
3398 tables.each(function() { |
3471 tables.each(function() { |
3399 var table = $(this); |
3472 var table = $(this); |
3400 $(table).on('mouseover', 'tr', function() { |
|
3401 $(this.cells[0]).addClass('drag-handle'); |
|
3402 }).on('mouseout', 'tr', function() { |
|
3403 $(this.cells[0]).removeClass('drag-handle'); |
|
3404 }); |
|
3405 var data = table.data(); |
3473 var data = table.data(); |
|
3474 if (data.amsTabledndDragHandle) { |
|
3475 $('tr', table).addClass('no-drag-handle'); |
|
3476 } else { |
|
3477 $(table).on('mouseover', 'tr', function () { |
|
3478 $(this.cells[0]).addClass('drag-handle'); |
|
3479 }).on('mouseout', 'tr', function () { |
|
3480 $(this.cells[0]).removeClass('drag-handle'); |
|
3481 }); |
|
3482 } |
3406 var data_options = { |
3483 var data_options = { |
3407 onDragClass: data.amsTabledndDragClass || 'dragging-row', |
3484 onDragClass: data.amsTabledndDragClass || 'dragging-row', |
3408 onDragStart: data.amsTabledndDragStart, |
3485 onDragStart: ams.getFunctionByName(data.amsTabledndDragStart), |
3409 dragHandle: data.amsTabledndDragHandle, |
3486 dragHandle: data.amsTabledndDragHandle, |
3410 scrollAmount: data.amsTabledndScrollAmount, |
3487 scrollAmount: data.amsTabledndScrollAmount, |
3411 onAllowDrop: data.amsTabledndAllowDrop, |
3488 onAllowDrop: data.amsTabledndAllowDrop, |
3412 onDrop: data.amsTabledndDrop || function(dnd_table, row) { |
3489 onDrop: ams.getFunctionByName(data.amsTabledndDrop) || function(dnd_table, row) { |
3413 var target = data.amsTabledndDropTarget; |
3490 var target = data.amsTabledndDropTarget; |
3414 if (target) { |
3491 if (target) { |
|
3492 // Disable row click handler |
|
3493 $(row).data('ams-disabled-handlers', 'click'); |
3415 var rows = []; |
3494 var rows = []; |
3416 $(dnd_table.rows).each(function() { |
3495 $(dnd_table.rows).each(function() { |
3417 var row_id = $(this).data('ams-element-name'); |
3496 var row_id = $(this).data('ams-element-name'); |
3418 if (row_id) { |
3497 if (row_id) { |
3419 rows.push(row_id); |
3498 rows.push(row_id); |
3905 * @message: main alert message |
3988 * @message: main alert message |
3906 * @subtitle: optional subtitle |
3989 * @subtitle: optional subtitle |
3907 * @margin: if true, a margin will be displayed around alert |
3990 * @margin: if true, a margin will be displayed around alert |
3908 */ |
3991 */ |
3909 alert: function(parent, status, header, message, subtitle, margin) { |
3992 alert: function(parent, status, header, message, subtitle, margin) { |
3910 $('.alert', parent).remove(); |
|
3911 if (status === 'error') { |
3993 if (status === 'error') { |
3912 status = 'danger'; |
3994 status = 'danger'; |
3913 } |
3995 } |
3914 var content = '<div class="' + (margin ? 'margin-10' : '') + ' alert alert-block alert-' + status + ' fade in">' + |
3996 $('.alert-' + status, parent).remove(); |
|
3997 var content = '<div class="' + (margin ? 'margin-10' : '') + ' alert alert-block alert-' + status + ' padding-5 fade in">' + |
3915 '<a class="close" data-dismiss="alert"><i class="fa fa-check"></i></a>' + |
3998 '<a class="close" data-dismiss="alert"><i class="fa fa-check"></i></a>' + |
3916 '<h4 class="alert-heading">' + |
3999 '<h4 class="alert-heading">' + |
3917 '<i class="fa fa-fw fa-warning"></i> ' + header + |
4000 '<i class="fa fa-fw fa-warning"></i> ' + header + |
3918 '</h4>' + |
4001 '</h4>' + |
3919 (subtitle ? ('<p>' + subtitle + '</p>') : ''); |
4002 (subtitle ? ('<p>' + subtitle + '</p>') : ''); |
4051 menu.parents('ul').addClass(menu.attr('href').replace(/^#/, '') ? 'active' : '') |
4137 menu.parents('ul').addClass(menu.attr('href').replace(/^#/, '') ? 'active' : '') |
4052 .show(); |
4138 .show(); |
4053 } |
4139 } |
4054 |
4140 |
4055 var menu; |
4141 var menu; |
|
4142 var nav = $('nav'); |
4056 var hash = location.hash; |
4143 var hash = location.hash; |
4057 var url = hash.replace(/^#/, ''); |
4144 var url = hash.replace(/^#/, ''); |
4058 if (url) { |
4145 if (url) { |
4059 var container = $('#content'); |
4146 var container = $('#content'); |
4060 if (!container.exists()) { |
4147 if (!container.exists()) { |
4061 container = $('body'); |
4148 container = $('body'); |
4062 } |
4149 } |
4063 menu = $('nav A[href="' + hash + '"]'); |
4150 menu = $('A[href="' + hash + '"]', nav); |
4064 if (menu.exists()) { |
4151 if (menu.exists()) { |
4065 updateActiveMenus(menu); |
4152 updateActiveMenus(menu); |
4066 } |
4153 } |
4067 ams.skin.loadURL(url, container); |
4154 ams.skin.loadURL(url, container); |
4068 document.title = $('[data-ams-page-title]:first', container).data('ams-page-title') || |
4155 document.title = $('[data-ams-page-title]:first', container).data('ams-page-title') || |
4069 menu.attr('title') || |
4156 menu.attr('title') || |
4070 document.title; |
4157 document.title; |
4071 } else { |
4158 } else { |
4072 var active_url = $('[data-ams-active-menu]').data('ams-active-menu'); |
4159 var active_url = $('[data-ams-active-menu]').data('ams-active-menu'); |
4073 if (active_url) { |
4160 if (active_url) { |
4074 menu = $('nav A[href="' + active_url + '"]'); |
4161 menu = $('A[href="' + active_url + '"]', nav); |
4075 } else { |
4162 } else { |
4076 menu = $('nav >UL >LI >A[href!="#"]').first(); |
4163 menu = $('>UL >LI >A[href!="#"]', nav).first(); |
4077 } |
4164 } |
4078 if (menu.exists()) { |
4165 if (menu.exists()) { |
4079 updateActiveMenus(menu); |
4166 updateActiveMenus(menu); |
4080 if (active_url) { |
4167 if (active_url) { |
4081 ams.skin._drawBreadCrumb(); |
4168 ams.skin._drawBreadCrumb(); |