src/pyams_skin/resources/js/myams-skin.js
changeset 489 63ea9a94bd47
parent 486 48b7cea0d903
--- a/src/pyams_skin/resources/js/myams-skin.js	Wed Dec 12 21:16:29 2018 +0100
+++ b/src/pyams_skin/resources/js/myams-skin.js	Thu Dec 13 14:28:29 2018 +0100
@@ -12,7 +12,6 @@
 		 */
 		_setPageHeight: function() {
 			var mainHeight = $('#main').height();
-			var menuHeight = ams.leftPanel.height();
 			var windowHeight = $(window).height() - ams.navbarHeight;
 			if (mainHeight > windowHeight) {
 				ams.root.css('min-height', mainHeight + ams.navbarHeight);
@@ -38,16 +37,16 @@
 		 * Show/hide shortcut buttons
 		 */
 		_showShortcutButtons: function() {
-			ams.shortcuts.animate({
-				height: 'show'
-			}, 200, 'easeOutCirc');
+			ams.shortcuts && ams.shortcuts.animate({
+													   height: 'show'
+												   }, 200, 'easeOutCirc');
 			ams.root.addClass('shortcut-on');
 		},
 
 		_hideShortcutButtons: function() {
-			ams.shortcuts.animate({
-				height: 'hide'
-			}, 300, 'easeOutCirc');
+			ams.shortcuts && ams.shortcuts.animate({
+													   height: 'hide'
+												   }, 300, 'easeOutCirc');
 			ams.root.removeClass('shortcut-on');
 		},
 
@@ -58,10 +57,10 @@
 			var badge = $('.badge', '#user-activity >span');
 			if (parseInt(badge.text()) > 0) {
 				badge.removeClass("hidden")
-					 .addClass("bg-color-red bounceIn animated");
+					.addClass("bg-color-red bounceIn animated");
 			} else {
 				badge.addClass("hidden")
-					 .removeClass("bg-color-red bounceIn animated");
+					.removeClass("bg-color-red bounceIn animated");
 			}
 		},
 
@@ -81,7 +80,7 @@
 			var target = $('[id="' + options.object_id + '"]');
 			target.replaceWith($(options.content));
 			target = $('[id="' + options.object_id + '"]');
-			ams.initContent(target);
+			ams.initContent && ams.initContent(target);
 			return target;
 		},
 
@@ -103,7 +102,7 @@
 			}
 			var label = widget.parents('.input').last();
 			label.html(options.content);
-			ams.initContent(label);
+			ams.initContent && ams.initContent(label);
 			return label;
 		},
 
@@ -114,7 +113,7 @@
 			var widget = $('[id="' + options.object_id + '"]').parents('.ams-widget:first');
 			widget.replaceWith($(options.table));
 			widget = $('[id="' + options.object_id + '"]').parents('.ams-widget:first');
-			ams.initContent(widget);
+			ams.initContent && ams.initContent(widget);
 			return widget;
 		},
 
@@ -124,9 +123,11 @@
 		 */
 		refreshSwitchedTable: function(options) {
 			var widget = ams.skin.refreshTable(options);
-			var legend = widget.siblings('legend');
-			if (legend.parents('fieldset:first').hasClass('switched')) {
-				legend.click();
+			if (widget) {
+				var legend = widget.siblings('legend');
+				if (legend.parents('fieldset:first').hasClass('switched')) {
+					legend.click();
+				}
 			}
 		},
 
@@ -138,7 +139,7 @@
 			var table = tr.parents('table').first();
 			var new_tr = $(options.row);
 			tr.replaceWith(new_tr);
-			ams.initContent(new_tr);
+			ams.initContent && ams.initContent(new_tr);
 			if (table.hasClass('table-dnd')) {
 				new_tr.addClass('no-drag-handle');
 				table.tableDnDUpdate();
@@ -158,7 +159,7 @@
 			if (index > -1) {
 				var cell = $($('td', tr).get(index));
 				cell.html(options.cell);
-				ams.initContent(cell);
+				ams.initContent && ams.initContent(cell);
 			}
 		},
 
@@ -171,21 +172,21 @@
 			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>');
-				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');
-						}
-					});
+				ams.ajax && 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 && ams.initContent(innerdiv);
+												  switcher.removeClass('fa-plus-square-o')
+													  .addClass('fa-minus-square-o');
+											  }
+										  });
 			} else {
 				ams.skin.cleanContainer(innerdiv);
 				innerdiv.empty();
 				switcher.removeClass('fa-minus-square-o')
-						.addClass('fa-plus-square-o');
+					.addClass('fa-plus-square-o');
 			}
 		},
 
@@ -196,22 +197,22 @@
 			if (ams.enableWidgets) {
 				var widgets = $('.ams-widget', element);
 				if (widgets.length > 0) {
-					ams.ajax.check($.fn.MyAMSWidget,
-								   ams.baseURL + 'myams-widgets' + ams.devext + '.js',
-								   function () {
-									   widgets.each(function () {
-										   var widget = $(this);
-										   var data = widget.data();
-										   var dataOptions = {
-											   deleteSettingsKey: '#deletesettingskey-options',
-											   deletePositionKey: '#deletepositionkey-options'
-										   };
-										   var settings = $.extend({}, dataOptions, data.amsWidgetOptions);
-										   settings = ams.executeFunctionByName(data.amsWidgetInitcallback, widget, settings) || settings;
-										   widget.MyAMSWidget(settings);
-									   });
-									   globals.MyAMSWidget.initWidgetsGrid($('.ams-widget-grid', element));
-								   });
+					ams.ajax && ams.ajax.check($.fn.MyAMSWidget,
+											   ams.baseURL + 'myams-widgets' + ams.devext + '.js',
+											   function() {
+												   widgets.each(function() {
+													   var widget = $(this);
+													   var data = widget.data();
+													   var dataOptions = {
+														   deleteSettingsKey: '#deletesettingskey-options',
+														   deletePositionKey: '#deletepositionkey-options'
+													   };
+													   var settings = $.extend({}, dataOptions, data.amsWidgetOptions);
+													   settings = ams.executeFunctionByName(data.amsWidgetInitcallback, widget, settings) || settings;
+													   widget.MyAMSWidget(settings);
+												   });
+												   globals.MyAMSWidget.initWidgetsGrid($('.ams-widget-grid', element));
+											   });
 				}
 			}
 		},
@@ -243,7 +244,7 @@
 				'<i class="fa fa-fw fa-warning"></i> ' + header +
 				'</h4>' +
 				(subtitle ? ('<p>' + subtitle + '</p>') : '');
-			if (typeof(message) === 'string') {
+			if (typeof (message) === 'string') {
 				content += '<ul><li>' + message + '</li></ul>';
 			} else if (message) {
 				content += '<ul>';
@@ -266,73 +267,73 @@
 		 * Big message box
 		 */
 		bigBox: function(options, callback) {
-			ams.ajax.check(ams.notify,
-						   ams.baseURL + 'myams-notify' + ams.devext + '.js',
-						   function() {
-								ams.notify.messageBox(options, callback);
-						   });
+			ams.ajax && ams.ajax.check(ams.notify,
+									   ams.baseURL + 'myams-notify' + ams.devext + '.js',
+									   function() {
+										   ams.notify.messageBox(options, callback);
+									   });
 		},
 
 		/**
 		 * Medium notification message box, displayed on page's bottom right
 		 */
 		messageBox: function(status, options, callback) {
-			if (typeof(status) === 'object') {
+			if (typeof (status) === 'object') {
 				callback = options;
 				options = status || {};
 				status = 'info';
 			}
-			ams.ajax.check(ams.notify,
-						   ams.baseURL + 'myams-notify' + ams.devext + '.js',
-						   function() {
-							   switch (status) {
-								   case 'error':
-								   case 'danger':
-									   options.color = '#C46A69';
-									   break;
-								   case 'warning':
-									   options.color = '#C79121';
-									   break;
-								   case 'success':
-									   options.color = '#739E73';
-									   break;
-								   default:
-									   options.color = options.color || '#3276B1';
-							   }
-							   options.sound = false;
-							   ams.notify.bigBox(options, callback);
-						   });
+			ams.ajax && ams.ajax.check(ams.notify,
+									   ams.baseURL + 'myams-notify' + ams.devext + '.js',
+									   function() {
+										   switch (status) {
+											   case 'error':
+											   case 'danger':
+												   options.color = '#C46A69';
+												   break;
+											   case 'warning':
+												   options.color = '#C79121';
+												   break;
+											   case 'success':
+												   options.color = '#739E73';
+												   break;
+											   default:
+												   options.color = options.color || '#3276B1';
+										   }
+										   options.sound = false;
+										   ams.notify.bigBox(options, callback);
+									   });
 		},
 
 		/**
 		 * Small notification message box, displayed on page's top right
 		 */
 		smallBox: function(status, options, callback) {
-			if (typeof(status) === 'object') {
+			if (typeof (status) === 'object') {
 				callback = options;
 				options = status || {};
 				status = 'info';
 			}
-			ams.ajax.check(ams.notify,
-						   ams.baseURL + 'myams-notify' + ams.devext + '.js',
-						   function () {
-							   switch (status) {
-								   case 'error':
-								   case 'danger':
-									   options.color = '#C46A69';
-									   break;
-								   case 'warning':
-									   options.color = '#C79121';
-									   break;
-								   case 'success':
-									   options.color = '#739E73';
-									   break;
-								   default:
-									   options.color = options.color || '#3276B1';
-							   }
-							   options.sound = false;
-							   ams.notify.smallBox(options, callback);
-						   });
+			ams.ajax && ams.ajax.check(ams.notify,
+									   ams.baseURL + 'myams-notify' + ams.devext + '.js',
+									   function() {
+										   switch (status) {
+											   case 'error':
+											   case 'danger':
+												   options.color = '#C46A69';
+												   break;
+											   case 'warning':
+												   options.color = '#C79121';
+												   break;
+											   case 'success':
+												   options.color = '#739E73';
+												   break;
+											   default:
+												   options.color = options.color || '#3276B1';
+										   }
+										   options.sound = false;
+										   ams.notify.smallBox(options, callback);
+									   });
 		},
 
 		/**
@@ -342,20 +343,20 @@
 		 * @param options: scroll options
 		 */
 		scrollTo: function(element, options) {
-			ams.ajax.check($.scrollTo,
-						   ams.baseURL + 'ext/jquery-scrollto-2.1.2' + ams.devext + '.js',
-						   function() {
-								var body = $('body');
-								var offset = options.offset || 0;
-								if (body.hasClass('fixed-header')) {
-									offset -= $('#header').height();
-								}
-								if (body.hasClass('fixed-ribbon')) {
-									offset -= $('#ribbon').height();
-								}
-								options = $.extend({}, options, {offset: offset});
-								$.scrollTo(element, options);
-						   });
+			ams.ajax && ams.ajax.check($.scrollTo,
+									   ams.baseURL + 'ext/jquery-scrollto-2.1.2' + ams.devext + '.js',
+									   function() {
+										   var body = $('body');
+										   var offset = options.offset || 0;
+										   if (body.hasClass('fixed-header')) {
+											   offset -= $('#header').height();
+										   }
+										   if (body.hasClass('fixed-ribbon')) {
+											   offset -= $('#ribbon').height();
+										   }
+										   options = $.extend({}, options, {offset: offset});
+										   $.scrollTo(element, options);
+									   });
 		},
 
 		/**
@@ -366,8 +367,8 @@
 			$('li', crumb).not('.parent').remove();
 			if (!$('li', crumb).exists()) {
 				crumb.append($('<li></li>').append($('<a></a>').text(ams.i18n.HOME)
-															   .addClass('padding-right-5')
-															   .attr('href', $('nav a[href!="#"]:first').attr('href'))));
+													   .addClass('padding-right-5')
+													   .attr('href', $('nav a[href!="#"]:first').attr('href'))));
 			}
 			$('LI.active >A', 'nav').each(function() {
 				var menu = $(this);
@@ -377,8 +378,8 @@
 									  .end()
 									  .text());
 				var item = $("<li></li>").append(menu.attr('href').replace(/^#/, '') ?
-												 $("<a></a>").html(body).attr('href', menu.attr('href'))
-												 : body);
+													 $("<a></a>").html(body).attr('href', menu.attr('href'))
+													 : body);
 				crumb.append(item);
 			});
 		},
@@ -413,13 +414,15 @@
 				if (menu.exists()) {
 					updateActiveMenus(menu);
 				}
-				ams.skin.loadURL(url, container, {afterLoadCallback: function() {
-					var prefix = $('html head title').data('ams-title-prefix');
-					document.title = (prefix ? prefix + ' > ' : '') +
-						($('[data-ams-page-title]:first', container).data('ams-page-title') ||
-						menu.attr('title') ||
-						document.title);
-				}});
+				ams.skin.loadURL(url, container, {
+					afterLoadCallback: function() {
+						var prefix = $('html head title').data('ams-title-prefix');
+						document.title = (prefix ? prefix + ' > ' : '') +
+							($('[data-ams-page-title]:first', container).data('ams-page-title') ||
+								menu.attr('title') ||
+								document.title);
+					}
+				});
 			} else {
 				var activeUrl = $('[data-ams-active-menu]').data('ams-active-menu');
 				if (activeUrl) {
@@ -471,7 +474,7 @@
 		 */
 		cleanContainer: function(container) {
 			var callbacks = ams.skin._clean_callbacks;
-			for (var index=0; index < callbacks.length; index++) {
+			for (var index = 0; index < callbacks.length; index++) {
 				callbacks[index].call(container);
 			}
 		},
@@ -483,7 +486,7 @@
 			if (url.startsWith('#')) {
 				url = url.substr(1);
 			}
-			if (typeof(options) === 'function') {
+			if (typeof (options) === 'function') {
 				callback = options;
 				options = {};
 			} else if (options === undefined) {
@@ -514,44 +517,46 @@
 					if (callback) {
 						ams.executeFunctionByName(callback, this, data, status, request, options);
 					} else {
-						var response = ams.ajax.getResponse(request);
-						var dataType = response.contentType;
-						var result = response.data;
-						$('.loading', container).remove();
-						switch (dataType) {
-							case 'json':
-								ams.ajax.handleJSON(result, container);
-								break;
-							case 'script':
-								break;
-							case 'xml':
-								break;
-							case 'html':
+						var response = ams.ajax && ams.ajax.getResponse(request);
+						if (response) {
+							var dataType = response.contentType;
+							var result = response.data;
+							$('.loading', container).remove();
+							switch (dataType) {
+								case 'json':
+									ams.ajax.handleJSON(result, container);
+									break;
+								case 'script':
+									break;
+								case 'xml':
+									break;
+								case 'html':
 								/* falls through */
-							case 'text':
+								case 'text':
 								/* falls through */
-							default:
-								// Show and init container
-								container.parents('.hidden').removeClass('hidden');
-								$('.alert', container.parents('.alerts-container')).remove();
-								container.css({opacity: '0.0'})
-										 .html(data)
-										 .removeClass('hidden')
-										 .delay(50)
-										 .animate({opacity: '1.0'}, 300);
-								ams.initContent(container);
-								ams.form.setFocus(container);
+								default:
+									// Show and init container
+									container.parents('.hidden').removeClass('hidden');
+									$('.alert', container.parents('.alerts-container')).remove();
+									container.css({opacity: '0.0'})
+										.html(data)
+										.removeClass('hidden')
+										.delay(50)
+										.animate({opacity: '1.0'}, 300);
+									ams.initContent && ams.initContent(container);
+									ams.form && ams.form.setFocus(container);
+							}
+							if (options && options.afterLoadCallback) {
+								ams.executeFunctionByName(options.afterLoadCallback, this, options.afterLoadCallbackOptions);
+							}
+							ams.stats && ams.stats.logPageview();
 						}
-						if (options && options.afterLoadCallback) {
-							ams.executeFunctionByName(options.afterLoadCallback, this, options.afterLoadCallbackOptions);
-						}
-						ams.stats.logPageview();
 					}
 				},
 				error: function(request, errorOptions, error) {
 					container.html('<h3 class="error"><i class="fa fa-warning txt-color-orangeDark"></i> ' +
-								   ams.i18n.ERROR + error + '</h3>' +
-								   request.responseText);
+									   ams.i18n.ERROR + error + '</h3>' +
+									   request.responseText);
 					if (options && options.afterErrorCallback) {
 						ams.executeFunctionByName(options.afterErrorCallback, this);
 					}
@@ -571,13 +576,13 @@
 			switch (handlerType) {
 				case 'json':
 					var method = options.method || 'setUserLanguage';
-					ams.jsonrpc.post(method, {lang: lang}, function() {
+					ams.jsonrpc && ams.jsonrpc.post(method, {lang: lang}, function() {
 						window.location.reload(true);
 					});
 					break;
 				case 'ajax':
 					var href = options.href || 'setUserLanguage';
-					ams.ajax.post(href, {lang: lang}, function() {
+					ams.ajax && ams.ajax.post(href, {lang: lang}, function() {
 						window.location.reload(true);
 					});
 					break;