Added generic object attribute switcher function
authorThierry Florac <tflorac@ulthar.net>
Thu, 19 Jul 2018 02:07:58 +0200
changeset 378 ff73c764fa7d
parent 377 b0f7b9c8cd16
child 379 51b9a88c8164
Added generic object attribute switcher function
src/pyams_skin/resources/js/myams.js
--- a/src/pyams_skin/resources/js/myams.js	Tue Jul 17 15:50:46 2018 +0200
+++ b/src/pyams_skin/resources/js/myams.js	Thu Jul 19 02:07:58 2018 +0200
@@ -2,7 +2,7 @@
  * MyAMS
  * « My Application Management Skin »
  *
- * $Tag$ (rev. 1)
+ * $Tag: 0.1.17 $ (rev. 1)
  * A bootstrap based application/administration skin
  *
  * Custom administration and application skin tools
@@ -4992,6 +4992,29 @@
 						}
 					});
 			}
+		},
+
+		/**
+		 * Switch element attribute
+		 */
+		switchElementAttribute: function() {
+			return function() {
+				var source = $(this);
+				var cell = source.parents('td').first();
+				var attribute = cell.data('ams-switcher-attribute-name');
+				var row = source.parents('tr').first();
+				var table = row.parents('table');
+				ams.ajax.post(table.data('ams-location') + '/' +
+							  (cell.data('ams-attribute-switcher') || table.data('ams-attribute-switcher')),
+					{object_name: row.data('ams-element-name')},
+					function(result, status) {
+						if (result.on) {
+							$('i', source).attr('class', table.data('ams-' + attribute + '-icon-on') || 'fa fa-fw fa-eye');
+						} else {
+							$('i', source).attr('class', table.data('ams-' + attribute + '-icon-off') || 'fa fa-fw fa-eye-slash text-danger');
+						}
+					});
+			}
 		}
 	};