src/ztfy/myams/resources/js/myams.js
changeset 156 61176c64158d
parent 154 0fff49179f6d
child 160 6c271ae9cfd3
equal deleted inserted replaced
155:e0fb6fd568eb 156:61176c64158d
    89 	 * JQuery 'scrollbarWidth' function
    89 	 * JQuery 'scrollbarWidth' function
    90 	 * Get width of vertical scrollbar
    90 	 * Get width of vertical scrollbar
    91 	 */
    91 	 */
    92 	if ($.scrollbarWidth === undefined) {
    92 	if ($.scrollbarWidth === undefined) {
    93 		$.scrollbarWidth = function() {
    93 		$.scrollbarWidth = function() {
    94 			var parent = $('<div style="width:50px;height:50px;overflow:auto"><div/></div>').appendTo('body');
    94 			var parent = $('<div style="width:50px; height:50px; overflow:auto"><div/></div>').appendTo('body');
    95 			var child = parent.children();
    95 			var child = parent.children();
    96 			var width = child.innerWidth() - child.height(99).innerWidth();
    96 			var width = child.innerWidth() - child.height(99).innerWidth();
    97 			parent.remove();
    97 			parent.remove();
    98 			return width;
    98 			return width;
    99 		};
    99 		};
   275 				active_item.addClass("open");
   275 				active_item.addClass("open");
   276 			});
   276 			});
   277 
   277 
   278 			menu.find("LI A").on('click', function() {
   278 			menu.find("LI A").on('click', function() {
   279 				var link = $(this);
   279 				var link = $(this);
       
   280 				if (link.hasClass('active')) {
       
   281 					return;
       
   282 				}
       
   283 				var href = link.attr('href').replace(/^#/,'');
   280 				var parent_ul = link.parent().find("UL");
   284 				var parent_ul = link.parent().find("UL");
   281 				if (settings.accordion) {
   285 				if (settings.accordion) {
   282 					var parents = link.parent().parents("UL");
   286 					var parents = link.parent().parents("UL");
   283 					var visible = menu.find("UL:visible");
   287 					var visible = menu.find("UL:visible");
   284 					visible.each(function(visibleIndex) {
   288 					visible.each(function(visibleIndex) {
   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
   792 				async: typeof(callback) === 'function',
   797 				async: typeof(callback) === 'function',
   793 				data: $.param(data),
   798 				data: $.param(data),
   794 				dataType: 'json',
   799 				dataType: 'json',
   795 				success: callback || function(data /*, status*/) {
   800 				success: callback || function(data /*, status*/) {
   796 					result = data.result;
   801 					result = data.result;
   797 				},
   802 				}
   798 				error: ams.error.show
       
   799 			};
   803 			};
   800 			var settings = $.extend({}, defaults, options);
   804 			var settings = $.extend({}, defaults, options);
   801 			$.ajax(settings);
   805 			$.ajax(settings);
   802 			return result;
   806 			return result;
   803 		},
   807 		},
  1255 			var focused = $('[data-ams-focus-target]', container).first();
  1259 			var focused = $('[data-ams-focus-target]', container).first();
  1256 			if (!focused.exists()) {
  1260 			if (!focused.exists()) {
  1257 				focused = $('input, select', container).first();
  1261 				focused = $('input, select', container).first();
  1258 			}
  1262 			}
  1259 			if (focused.exists()) {
  1263 			if (focused.exists()) {
       
  1264 				if (focused.hasClass('select2-input')) {
       
  1265 					focused = focused.parents('.select2');
       
  1266 				}
  1260 				if (focused.hasClass('select2')) {
  1267 				if (focused.hasClass('select2')) {
  1261 					setTimeout(function() {
  1268 					setTimeout(function() {
  1262 						focused.select2('focus')
  1269 						focused.select2('focus');
  1263 						focused.select2('open');
  1270 						if (focused.data('ams-focus-open') === true) {
       
  1271 							focused.select2('open');
       
  1272 						}
  1264 					}, 100);
  1273 					}, 100);
  1265 				} else {
  1274 				} else {
  1266 					focused.focus();
  1275 					focused.focus();
  1267 				}
  1276 				}
  1268 			}
  1277 			}
  1330 			// Check submit validators
  1339 			// Check submit validators
  1331 			if (!ams.form._checkSubmitValidators(form)) {
  1340 			if (!ams.form._checkSubmitValidators(form)) {
  1332 				return false;
  1341 				return false;
  1333 			}
  1342 			}
  1334 			// Remove remaining status messages
  1343 			// Remove remaining status messages
  1335 			$('.alert-danger, SPAN.state-error', form).remove();
  1344 			$('.alert-danger, SPAN.state-error', form).not('.persistent').remove();
  1336 			$('.state-error', form).removeClassPrefix('state-');
  1345 			$('.state-error', form).removeClassPrefix('state-');
  1337 			// Check submit button
  1346 			// Check submit button
  1338 			var button = $(form.data('ams-submit-button'));
  1347 			var button = $(form.data('ams-submit-button'));
  1339 			if (button && !button.data('ams-form-hide-loading')) {
  1348 			if (button && !button.data('ams-form-hide-loading')) {
  1340 				button.button('loading');
  1349 				button.button('loading');
  1818 									.addClass('state-error');
  1827 									.addClass('state-error');
  1819 							$('li.state-error:first a', form).click();
  1828 							$('li.state-error:first a', form).click();
  1820 						}
  1829 						}
  1821 					}
  1830 					}
  1822 				}
  1831 				}
  1823 				ams.skin.alert(form, errors.error_level || 'error', header, message, errors.error_message);
  1832 				ams.skin.alert($('fieldset:first', form), errors.error_level || 'error', header, message, errors.error_message);
  1824 			}
  1833 			}
  1825 		}
  1834 		}
  1826 	};
  1835 	};
  1827 
  1836 
  1828 
  1837 
  1956 													default:
  1965 													default:
  1957 														var content = $(result);
  1966 														var content = $(result);
  1958 														var dialog = $('.modal-dialog', content.wrap('<div></div>').parent());
  1967 														var dialog = $('.modal-dialog', content.wrap('<div></div>').parent());
  1959 														var dialog_data = dialog.data();
  1968 														var dialog_data = dialog.data();
  1960 														var data_options = {
  1969 														var data_options = {
       
  1970 															backdrop: 'static',
  1961 															overflow: dialog_data.amsModalOverflow || '.modal-viewport',
  1971 															overflow: dialog_data.amsModalOverflow || '.modal-viewport',
  1962 															maxHeight: dialog_data.amsModalMaxHeight === undefined ?
  1972 															maxHeight: dialog_data.amsModalMaxHeight === undefined ?
  1963 																	function() {
  1973 																	function() {
  1964 																		return $(window).height() -
  1974 																		return $(window).height() -
  1965 																					$('.modal-header', content).outerHeight(true) -
  1975 																					$('.modal-header', content).outerHeight(true) -
  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);
  3423 														if (typeof(local_target) === 'function') {
  3502 														if (typeof(local_target) === 'function') {
  3424 															local_target.call(table, dnd_table, rows);
  3503 															local_target.call(table, dnd_table, rows);
  3425 														} else {
  3504 														} else {
  3426 															ams.ajax.post(target, {names: JSON.stringify(rows)});
  3505 															ams.ajax.post(target, {names: JSON.stringify(rows)});
  3427 														}
  3506 														}
       
  3507 														// Restore row click handler
       
  3508 														setTimeout(function() {
       
  3509 															$(row).removeData('ams-disabled-handlers');
       
  3510 														}, 50);
  3428 													}
  3511 													}
  3429 													return false;
  3512 													return false;
  3430 												}
  3513 												}
  3431 											};
  3514 											};
  3432 											var settings = $.extend({}, data_options, data.amsTabledndOptions);
  3515 											var settings = $.extend({}, data_options, data.amsTabledndOptions);
  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>') : '');
  4016 		/**
  4099 		/**
  4017 		 * Initialize breadcrumbs based on active menu position
  4100 		 * Initialize breadcrumbs based on active menu position
  4018 		 */
  4101 		 */
  4019 		_drawBreadCrumb: function() {
  4102 		_drawBreadCrumb: function() {
  4020 			var crumb = $('#ribbon OL.breadcrumb');
  4103 			var crumb = $('#ribbon OL.breadcrumb');
  4021 			crumb.empty()
  4104 			$('li', crumb).not('.parent').remove();
  4022 				 .append($('<li></li>').append($('<a></a>').text(ams.i18n.HOME)
  4105 			if (!$('li', crumb).exists()) {
  4023 														   .attr('href', $('nav a[href!="#"]:first').attr('href'))));
  4106 				crumb.append($('<li></li>').append($('<a></a>').text(ams.i18n.HOME)
       
  4107 															   .addClass('padding-right-5')
       
  4108 															   .attr('href', $('nav a[href!="#"]:first').attr('href'))));
       
  4109 			}
  4024 			$('nav LI.active >A').each(function() {
  4110 			$('nav LI.active >A').each(function() {
  4025 				var menu = $(this);
  4111 				var menu = $(this);
  4026 				var body = $.trim(menu.clone()
  4112 				var body = $.trim(menu.clone()
  4027 									  .children(".badge")
  4113 									  .children(".badge")
  4028 									  .remove()
  4114 									  .remove()
  4039 		 * Check URL matching current location hash
  4125 		 * Check URL matching current location hash
  4040 		 */
  4126 		 */
  4041 		checkURL: function() {
  4127 		checkURL: function() {
  4042 
  4128 
  4043 			function updateActiveMenus(menu) {
  4129 			function updateActiveMenus(menu) {
  4044 				$('nav .active').removeClass('active');
  4130 				$('.active', nav).removeClass('active');
  4045 				menu.addClass('open')
  4131 				menu.addClass('open')
  4046 					.addClass('active');
  4132 					.addClass('active');
  4047 				menu.parents('li').addClass('open active')
  4133 				menu.parents('li').addClass('open active')
  4048 					.children('ul').addClass('active')
  4134 					.children('ul').addClass('active')
  4049 					.show();
  4135 					.show();
  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();
  4290 			if (ams.enable_fastclick) {
  4377 			if (ams.enable_fastclick) {
  4291 				ams.ajax.check($.fn.noClickDelay,
  4378 				ams.ajax.check($.fn.noClickDelay,
  4292 							   ams.baseURL + '/ext/jquery-smartclick' + ams.devext + '.js',
  4379 							   ams.baseURL + '/ext/jquery-smartclick' + ams.devext + '.js',
  4293 							   function() {
  4380 							   function() {
  4294 								   $('NAV UL A').noClickDelay();
  4381 								   $('NAV UL A').noClickDelay();
  4295 								   $('#hide-menu A').noClickDelay();
  4382 								   $('A', '#hide-menu').noClickDelay();
  4296 							   });
  4383 							   });
  4297 			}
  4384 			}
  4298 		}
  4385 		}
  4299 
  4386 
  4300 		// Hide menu button
  4387 		// Hide menu button
  4382 				}
  4469 				}
  4383 			});
  4470 			});
  4384 		});
  4471 		});
  4385 
  4472 
  4386 		// Initialize left nav
  4473 		// Initialize left nav
  4387 		$('NAV UL').myams_menu({
  4474 		var nav = $('nav');
  4388 			accordion : true,
  4475 		$('UL', nav).myams_menu({
       
  4476 			accordion : nav.data('ams-menu-accordion') !== false,
  4389 			speed : ams.menu_speed
  4477 			speed : ams.menu_speed
  4390 		});
  4478 		});
  4391 
  4479 
  4392 		// Left navigation collapser
  4480 		// Left navigation collapser
  4393 		$('.minifyme').click(function(e) {
  4481 		$('.minifyme').click(function(e) {
  4427 					   function() {
  4515 					   function() {
  4428 						   $('#main').resize(function() {
  4516 						   $('#main').resize(function() {
  4429 							   ams.skin._setPageHeight();
  4517 							   ams.skin._setPageHeight();
  4430 							   ams.skin._checkMobileWidth();
  4518 							   ams.skin._checkMobileWidth();
  4431 						   });
  4519 						   });
  4432 						   $('nav').resize(function() {
  4520 						   nav.resize(function() {
  4433 							   ams.skin._setPageHeight();
  4521 							   ams.skin._setPageHeight();
  4434 						   });
  4522 						   });
  4435 					   });
  4523 					   });
  4436 
  4524 
  4437 		// Init AJAX navigation
  4525 		// Init AJAX navigation
  4439 			$(document).on('click', 'a[href="#"]', function(e) {
  4527 			$(document).on('click', 'a[href="#"]', function(e) {
  4440 				e.preventDefault();
  4528 				e.preventDefault();
  4441 			});
  4529 			});
  4442 			$(document).on('click', 'a[href!="#"]:not([data-toggle]), [data-ams-url]:not([data-toggle])', function(e) {
  4530 			$(document).on('click', 'a[href!="#"]:not([data-toggle]), [data-ams-url]:not([data-toggle])', function(e) {
  4443 				var link = $(e.currentTarget);
  4531 				var link = $(e.currentTarget);
       
  4532 				var handlers = link.data('ams-disabled-handlers');
       
  4533 				if ((handlers === true) || (handlers === 'click')) {
       
  4534 					return;
       
  4535 				}
  4444 				var href = link.attr('href') || link.data('ams-url');
  4536 				var href = link.attr('href') || link.data('ams-url');
  4445 				if (!href || href.startsWith('javascript') || link.attr('target') || (link.data('ams-context-menu') === true)) {
  4537 				if (!href || href.startsWith('javascript') || link.attr('target') || (link.data('ams-context-menu') === true)) {
  4446 					return;
  4538 					return;
  4447 				}
  4539 				}
  4448 				e.preventDefault();
  4540 				e.preventDefault();
  4500 
  4592 
  4501 		// Initialize modal dialogs links
  4593 		// Initialize modal dialogs links
  4502 		$(document).off('click.modal')
  4594 		$(document).off('click.modal')
  4503 				   .on('click', '[data-toggle="modal"]', function(e) {
  4595 				   .on('click', '[data-toggle="modal"]', function(e) {
  4504 			var source = $(this);
  4596 			var source = $(this);
       
  4597 			var handlers = source.data('ams-disabled-handlers');
       
  4598 			if ((handlers === true) || (handlers === 'click')) {
       
  4599 				return;
       
  4600 			}
  4505 			if (source.data('ams-context-menu') === true) {
  4601 			if (source.data('ams-context-menu') === true) {
  4506 				return;
  4602 				return;
  4507 			}
  4603 			}
  4508 			if (source.data('ams-stop-propagation') === true) {
  4604 			if (source.data('ams-stop-propagation') === true) {
  4509 				e.stopPropagation();
  4605 				e.stopPropagation();
  4522 		});
  4618 		});
  4523 
  4619 
  4524 		// Initialize custom click handlers
  4620 		// Initialize custom click handlers
  4525 		$(document).on('click', '[data-ams-click-handler]', function(e) {
  4621 		$(document).on('click', '[data-ams-click-handler]', function(e) {
  4526 			var source = $(this);
  4622 			var source = $(this);
       
  4623 			var handlers = source.data('ams-disabled-handlers');
       
  4624 			if ((handlers === true) || (handlers === 'click')) {
       
  4625 				return;
       
  4626 			}
  4527 			var data = source.data();
  4627 			var data = source.data();
  4528 			if (data.amsClickHandler) {
  4628 			if (data.amsClickHandler) {
  4529 				if ((data.amsStopPropagation === true) || (data.amsClickStopPropagation === true)) {
  4629 				if ((data.amsStopPropagation === true) || (data.amsClickStopPropagation === true)) {
  4530 					e.stopPropagation();
  4630 					e.stopPropagation();
  4531 				}
  4631 				}
  4540 		});
  4640 		});
  4541 
  4641 
  4542 		// Initialize custom change handlers
  4642 		// Initialize custom change handlers
  4543 		$(document).on('change', '[data-ams-change-handler]', function(e) {
  4643 		$(document).on('change', '[data-ams-change-handler]', function(e) {
  4544 			var source = $(this);
  4644 			var source = $(this);
       
  4645 			var handlers = source.data('ams-disabled-handlers');
       
  4646 			if ((handlers === true) || (handlers === 'change')) {
       
  4647 				return;
       
  4648 			}
  4545 			var data = source.data();
  4649 			var data = source.data();
  4546 			if (data.amsChangeHandler) {
  4650 			if (data.amsChangeHandler) {
  4547 				if (data.amsChangeKeepDefault !== true) {
  4651 				if (data.amsChangeKeepDefault !== true) {
  4548 					e.preventDefault();
  4652 					e.preventDefault();
  4549 				}
  4653 				}
  4624 			}
  4728 			}
  4625 		});
  4729 		});
  4626 
  4730 
  4627 		// Init page content
  4731 		// Init page content
  4628 		ams.initContent(document);
  4732 		ams.initContent(document);
  4629 		if (ams.ajax_nav && $('nav').exists()) {
  4733 		if (ams.ajax_nav && nav.exists()) {
  4630 			ams.skin.checkURL();
  4734 			ams.skin.checkURL();
  4631 		}
  4735 		}
  4632 		ams.form.setFocus(document);
  4736 		ams.form.setFocus(document);
  4633 
  4737 
  4634 		// Add unload event listener to check for modified forms
  4738 		// Add unload event listener to check for modified forms