src/pyams_portal/resources/js/portal.js
changeset 197 43b42acef9d8
parent 189 de06dad91889
child 198 3e934db06959
--- a/src/pyams_portal/resources/js/portal.js	Wed Sep 26 17:16:38 2018 +0200
+++ b/src/pyams_portal/resources/js/portal.js	Wed Sep 26 17:47:33 2018 +0200
@@ -6,6 +6,14 @@
 
 	var PyAMS_portal = {
 
+        /**
+		 * I18n strings
+         */
+		i18n: {
+			CANT_DELETE_ROW_WITH_PORTLETS: "A row containing portlets dan't be removed!",
+			CANT_DELETE_SLOT_WITH_PORTLETS: "A slot containing portlets can't be removed!"
+		},
+
 		/**
 		 * Templates management
 		 */
@@ -199,30 +207,38 @@
 
 			deleteRow: function() {
 				return function(row) {
-					MyAMS.skin.bigBox({
-						title: MyAMS.i18n.WARNING,
-						content: '<i class="text-danger fa fa-2x fa-bell"></i>&nbsp; ' + MyAMS.i18n.DELETE_WARNING,
-						status: 'info',
-						buttons: MyAMS.i18n.BTN_OK_CANCEL
-					}, function(button) {
-						if (button === MyAMS.i18n.BTN_OK) {
-							if (!row.hasClass('row')) {
-								row = row.parents('.row');
+					row = row.objectOrParentWithClass('row');
+					var portlets = $('.portlet', row);
+					if (portlets.exists()) {
+						MyAMS.skin.messageBox('error', {
+							title: MyAMS.i18n.ERROR_OCCURED,
+							content: PyAMS_portal.i18n.CANT_DELETE_ROW_WITH_PORTLETS,
+							icon: 'fa fa-warning animated shake',
+							timeout: 5000
+						});
+					} else {
+						MyAMS.skin.bigBox({
+							title: MyAMS.i18n.WARNING,
+							content: '<i class="text-danger fa fa-2x fa-bell"></i>&nbsp; ' + MyAMS.i18n.DELETE_WARNING,
+							status: 'info',
+							buttons: MyAMS.i18n.BTN_OK_CANCEL
+						}, function (button) {
+							if (button === MyAMS.i18n.BTN_OK) {
+								MyAMS.ajax.post('delete-template-row.json',
+									{row_id: row.data('ams-row-id')},
+									function (result) {
+										if (result.status === 'success') {
+											row.remove();
+											$('.row', '#portal_config').each(function (index) {
+												$(this).removeData()
+													.attr('data-ams-row-id', index);
+												$('.row_id', $(this)).text(index + 1);
+											});
+										}
+									});
 							}
-							MyAMS.ajax.post('delete-template-row.json',
-											{row_id: row.data('ams-row-id')},
-											function(result) {
-												if (result.status === 'success') {
-													row.remove();
-													$('.row', '#portal_config').each(function (index) {
-														$(this).removeData()
-															   .attr('data-ams-row-id', index);
-														$('.row_id', $(this)).text(index+1);
-													});
-												}
-											});
-						}
-					});
+						});
+					}
 				};
 			},
 
@@ -398,28 +414,36 @@
 
 			deleteSlot: function() {
 				return function(slot) {
-					MyAMS.skin.bigBox({
-						title: MyAMS.i18n.WARNING,
-						content: '<i class="text-danger fa fa-2x fa-bell"></i>&nbsp; ' + MyAMS.i18n.DELETE_WARNING,
-						status: 'info',
-						buttons: MyAMS.i18n.BTN_OK_CANCEL
-					}, function(button) {
-						if (button === MyAMS.i18n.BTN_OK) {
-							if (!slot.hasClass('slot')) {
-								slot = slot.parents('.slot');
+					slot = slot.objectOrParentWithClass('slot');
+					var portlets = $('.portlet', slot);
+					if (portlets.exists()) {
+						MyAMS.skin.messageBox('error', {
+							title: MyAMS.i18n.ERROR_OCCURED,
+							content: PyAMS_portal.i18n.CANT_DELETE_SLOT_WITH_PORTLETS,
+							icon: 'fa fa-warning animated shake',
+							timeout: 5000
+						});
+					} else {
+						MyAMS.skin.bigBox({
+							title: MyAMS.i18n.WARNING,
+							content: '<i class="text-danger fa fa-2x fa-bell"></i>&nbsp; ' + MyAMS.i18n.DELETE_WARNING,
+							status: 'info',
+							buttons: MyAMS.i18n.BTN_OK_CANCEL
+						}, function (button) {
+							if (button === MyAMS.i18n.BTN_OK) {
+								MyAMS.ajax.post('delete-template-slot.json',
+									{slot_name: slot.data('ams-slot-name')},
+									function (result) {
+										if (result.status === 'success') {
+											slot.remove();
+											$('.slot', '#portal_config').each(function () {
+												$(this).removeData();
+											});
+										}
+									});
 							}
-							MyAMS.ajax.post('delete-template-slot.json',
-											{slot_name: slot.data('ams-slot-name')},
-											function(result) {
-												if (result.status === 'success') {
-													slot.remove();
-													$('.slot', '#portal_config').each(function() {
-														$(this).removeData();
-													});
-												}
-											});
-						}
-					});
+						});
+					}
 				};
 			},
 
@@ -574,4 +598,9 @@
 	};
 	globals.PyAMS_portal = PyAMS_portal;
 
+	var html = $('HTML');
+	if (MyAMS.lang !== 'en') {
+		MyAMS.getScript('/--static--/pyams_portal/js/i18n/' + MyAMS.lang + MyAMS.devext + '.js');
+	}
+
 })(jQuery, this);