src/ztfy/myams/resources/js/myams.js
changeset 193 68dd5a05c059
parent 192 d58af89193e3
child 196 bbeb090d73e9
equal deleted inserted replaced
192:d58af89193e3 193:68dd5a05c059
   546 	MyAMS.isInDOM = function(element) {
   546 	MyAMS.isInDOM = function(element) {
   547 		element = $(element);
   547 		element = $(element);
   548 		if (!element.exists()) {
   548 		if (!element.exists()) {
   549 			return false;
   549 			return false;
   550 		}
   550 		}
   551 		return globals.document.contains(element[0]);
   551 		return globals.document.body.contains(element[0]);
   552 	};
   552 	};
   553 
   553 
   554 	/**
   554 	/**
   555 	 * Get script or CSS file using browser cache
   555 	 * Get script or CSS file using browser cache
   556 	 * Script or CSS URLs can include variable names, given between braces, as in
   556 	 * Script or CSS URLs can include variable names, given between braces, as in
   757 			}
   757 			}
   758 			var defaults = {
   758 			var defaults = {
   759 				async: typeof(callback) === 'function'
   759 				async: typeof(callback) === 'function'
   760 			};
   760 			};
   761 			var settings = $.extend({}, defaults, options);
   761 			var settings = $.extend({}, defaults, options);
   762 			if (checker === undefined) {
   762 			if (checker instanceof Array) {
   763 				ams.getScript(source, function() {
   763 				var deferred = [];
   764 					if (typeof(callback) === 'function') {
   764 				for (var index = 0; index < checker.length; index++) {
   765 						callback(true, options);
   765 					if (checker[index] === undefined) {
       
   766 						deferred.push(ams.getScript(source[index], {async: true}));
   766 					}
   767 					}
   767 				}, settings);
   768 				}
       
   769 				if (deferred.length > 0) {
       
   770 					$.when.apply($, deferred).then(function () {
       
   771 						if (typeof(callback) === 'function') {
       
   772 							callback(true, options);
       
   773 						}
       
   774 					});
       
   775 				} else if (typeof(callback) === 'function') {
       
   776 					callback(false, options);
       
   777 				}
       
   778 			} else if (checker === undefined) {
       
   779 				if (typeof(source) === 'string') {
       
   780 					ams.getScript(source, function () {
       
   781 						if (typeof(callback) === 'function') {
       
   782 							callback(true, options);
       
   783 						}
       
   784 					}, settings);
       
   785 				}
   768 			} else {
   786 			} else {
   769 				if (typeof(callback) === 'function') {
   787 				if (typeof(callback) === 'function') {
   770 					callback(false, options);
   788 					callback(false, options);
   771 				}
   789 				}
   772 			}
   790 			}
  2553 					}
  2571 					}
  2554 				}
  2572 				}
  2555 			}
  2573 			}
  2556 
  2574 
  2557 			for (name in plugins) {
  2575 			for (name in plugins) {
       
  2576 				if (!plugins.hasOwnProperty(name)) {
       
  2577 					continue;
       
  2578 				}
  2558 				plugin = plugins[name];
  2579 				plugin = plugins[name];
  2559 				if (ams.plugins.enabled[name] === undefined) {
  2580 				if (ams.plugins.enabled[name] === undefined) {
  2560 					ams.getScript(plugin.src, _loadPlugin, {
  2581 					ams.getScript(plugin.src, _loadPlugin, {
  2561 						async: plugin.async === undefined ? true : plugin.async
  2582 						async: plugin.async === undefined ? true : plugin.async
  2562 					});
  2583 					});
  2609 				var dataElement = $(this);
  2630 				var dataElement = $(this);
  2610 				var data = dataElement.data('ams-data');
  2631 				var data = dataElement.data('ams-data');
  2611 				if (data) {
  2632 				if (data) {
  2612 					for (var name in data) {
  2633 					for (var name in data) {
  2613 						if (data.hasOwnProperty(name)) {
  2634 						if (data.hasOwnProperty(name)) {
  2614 							dataElement.attr('data-' + name, data[name]);
  2635 							var elementData = data[name];
       
  2636 							if (typeof(elementData) !== 'string') {
       
  2637 								elementData = JSON.stringify(elementData);
       
  2638 							}
       
  2639 							dataElement.attr('data-' + name, elementData);
  2615 						}
  2640 						}
  2616 					}
  2641 					}
  2617 				}
  2642 				}
  2618 			});
  2643 			});
  2619 		},
  2644 		},
  4124 								if (table.hasClass('datatable')) {
  4149 								if (table.hasClass('datatable')) {
  4125 									table.dataTable().fnDeleteRow(tr[0]);
  4150 									table.dataTable().fnDeleteRow(tr[0]);
  4126 								} else {
  4151 								} else {
  4127 									tr.remove();
  4152 									tr.remove();
  4128 								}
  4153 								}
       
  4154 							} else {
       
  4155 								MyAMS.ajax.handleJSON(result);
  4129 							}
  4156 							}
  4130 						});
  4157 						});
  4131 					}
  4158 					}
  4132 				});
  4159 				});
  4133 			};
  4160 			};
  4410 				}
  4437 				}
  4411 				menu = $('A[href="' + hash + '"]', nav);
  4438 				menu = $('A[href="' + hash + '"]', nav);
  4412 				if (menu.exists()) {
  4439 				if (menu.exists()) {
  4413 					updateActiveMenus(menu);
  4440 					updateActiveMenus(menu);
  4414 				}
  4441 				}
  4415 				ams.skin.loadURL(url, container);
  4442 				ams.skin.loadURL(url, container, {afterLoadCallback: function() {
  4416 				var prefix = $('html head title').data('ams-title-prefix');
  4443 					var prefix = $('html head title').data('ams-title-prefix');
  4417 				document.title = (prefix ? prefix + ' > ' : '') +
  4444 					document.title = (prefix ? prefix + ' > ' : '') +
  4418 								 ($('[data-ams-page-title]:first', container).data('ams-page-title') ||
  4445 						($('[data-ams-page-title]:first', container).data('ams-page-title') ||
  4419 								  menu.attr('title') ||
  4446 						menu.attr('title') ||
  4420 								  document.title);
  4447 						document.title);
       
  4448 				}});
  4421 			} else {
  4449 			} else {
  4422 				var activeUrl = $('[data-ams-active-menu]').data('ams-active-menu');
  4450 				var activeUrl = $('[data-ams-active-menu]').data('ams-active-menu');
  4423 				if (activeUrl) {
  4451 				if (activeUrl) {
  4424 					menu = $('A[href="' + activeUrl + '"]', nav);
  4452 					menu = $('A[href="' + activeUrl + '"]', nav);
  4425 				} else {
  4453 				} else {
  4481 			if (url.startsWith('#')) {
  4509 			if (url.startsWith('#')) {
  4482 				url = url.substr(1);
  4510 				url = url.substr(1);
  4483 			}
  4511 			}
  4484 			if (typeof(options) === 'function') {
  4512 			if (typeof(options) === 'function') {
  4485 				callback = options;
  4513 				callback = options;
       
  4514 				options = {};
       
  4515 			} else if (options === undefined) {
  4486 				options = {};
  4516 				options = {};
  4487 			}
  4517 			}
  4488 			container = $(container);
  4518 			container = $(container);
  4489 			var defaults = {
  4519 			var defaults = {
  4490 				type: 'GET',
  4520 				type: 'GET',
  4491 				url: url,
  4521 				url: url,
  4492 				dataType: 'html',
  4522 				dataType: 'html',
  4493 				cache: false,
  4523 				cache: false,
  4494 				beforeSend: function() {
  4524 				beforeSend: function() {
  4495 					ams.skin.cleanContainer(container);
  4525 					ams.skin.cleanContainer(container);
  4496 					container.html('<h1 class="loading"><i class="fa fa-cog fa-spin"></i> Loading... </h1>');
  4526 					container.html('<h1 class="loading"><i class="fa fa-cog fa-spin"></i> ' + ams.i18n.LOADING + ' </h1>');
  4497 					if (container[0] === $('#content')[0]) {
  4527 					if (container[0] === $('#content')[0]) {
  4498 						ams.skin._drawBreadCrumb();
  4528 						ams.skin._drawBreadCrumb();
  4499 						var prefix = $('html head title').data('ams-title-prefix');
  4529 						var prefix = $('html head title').data('ams-title-prefix');
  4500 						document.title = (prefix ? prefix + ' > ' : '') + $('.breadcrumb LI:last-child').text();
  4530 						document.title = (prefix ? prefix + ' > ' : '') + $('.breadcrumb LI:last-child').text();
  4501 						$('html, body').animate({scrollTop: 0}, 'fast');
  4531 						$('html, body').animate({scrollTop: 0}, 'fast');
  4544 				error: function(request, options, error) {
  4574 				error: function(request, options, error) {
  4545 					container.html('<h3 class="error"><i class="fa fa-warning txt-color-orangeDark"></i> ' +
  4575 					container.html('<h3 class="error"><i class="fa fa-warning txt-color-orangeDark"></i> ' +
  4546 								   ams.i18n.ERROR + error + '</h3>' +
  4576 								   ams.i18n.ERROR + error + '</h3>' +
  4547 								   request.responseText);
  4577 								   request.responseText);
  4548 				},
  4578 				},
  4549 				async: false
  4579 				async: options.async === undefined ? true : options.async
  4550 			};
  4580 			};
  4551 			var settings = $.extend({}, defaults, options);
  4581 			var settings = $.extend({}, defaults, options);
  4552 			$.ajax(settings);
  4582 			$.ajax(settings);
  4553 		},
  4583 		},
  4554 
  4584 
  5029 				if (data.amsTabLoaded) {
  5059 				if (data.amsTabLoaded) {
  5030 					return;
  5060 					return;
  5031 				}
  5061 				}
  5032 				try {
  5062 				try {
  5033 					link.append('<i class="fa fa-spin fa-cog margin-left-5"></i>');
  5063 					link.append('<i class="fa fa-spin fa-cog margin-left-5"></i>');
  5034 					ams.skin.loadURL(data.amsUrl, link.attr('href'));
  5064 					ams.skin.loadURL(data.amsUrl, link.attr('href'), {afterLoadCallback: function() {
  5035 					if (data.amsTabLoadOnce) {
  5065 						if (data.amsTabLoadOnce) {
  5036 						link.data('ams-tab-loaded', true);
  5066 							link.data('ams-tab-loaded', true);
  5037 					}
  5067 						}
       
  5068 					}});
  5038 				}
  5069 				}
  5039 				finally {
  5070 				finally {
  5040 					$('i', link).remove();
  5071 					$('i', link).remove();
  5041 				}
  5072 				}
  5042 			}
  5073 			}
  5112 
  5143 
  5113 		INFO: "Information",
  5144 		INFO: "Information",
  5114 		WARNING: "!! WARNING !!",
  5145 		WARNING: "!! WARNING !!",
  5115 		ERROR: "ERROR: ",
  5146 		ERROR: "ERROR: ",
  5116 
  5147 
       
  5148 		LOADING: "Loading...",
  5117 		WAIT: "Please wait!",
  5149 		WAIT: "Please wait!",
  5118 		FORM_SUBMITTED: "This form was already submitted...",
  5150 		FORM_SUBMITTED: "This form was already submitted...",
  5119 		NO_SERVER_RESPONSE: "No response from server!",
  5151 		NO_SERVER_RESPONSE: "No response from server!",
  5120 		ERROR_OCCURED: "An error occured!",
  5152 		ERROR_OCCURED: "An error occured!",
  5121 		ERRORS_OCCURED: "Some errors occured!",
  5153 		ERRORS_OCCURED: "Some errors occured!",