src/pyams_content/skin/resources/js/pyams_content.js
changeset 179 fb7c5f27e8a3
parent 176 64e00f5537fe
child 188 4a7679f7f16c
--- a/src/pyams_content/skin/resources/js/pyams_content.js	Thu Sep 21 12:44:15 2017 +0200
+++ b/src/pyams_content/skin/resources/js/pyams_content.js	Thu Sep 21 12:44:37 2017 +0200
@@ -7,6 +7,26 @@
 	var PyAMS_content = {
 
 		/**
+		 * Replace given form with new content
+		 */
+		refreshForm: function(changes) {
+			var parent = $('#' + changes.object_name);
+			parent.replaceWith($(changes.form));
+			parent = $('#' + changes.object_name);
+			MyAMS.initContent(parent);
+			return parent;
+		},
+
+		refreshTable: function(changes) {
+			var widget = $('#' + changes.object_name).parent('.ams-widget');
+			widget.replaceWith($(changes.table));
+			widget = $('#' + changes.object_name).parent('.ams-widget');
+			MyAMS.initContent(widget);
+			return widget;
+		},
+
+
+		/**
 		 * TinyMCE editor configuration
 		 */
 		TinyMCE: {
@@ -174,6 +194,40 @@
 
 
 		/**
+		 * Associations management
+		 */
+		associations: {
+
+			refreshAssociations: function(options) {
+				// Reload widget
+				var widget = PyAMS_content.refreshTable(options);
+				// Check fieldset state
+				var legend = widget.siblings('legend');
+				if (legend.parents('fieldset:first').hasClass('switched')) {
+					legend.click();
+				}
+			},
+
+			switchVisibility: function (element) {
+				return function () {
+					var source = $(this);
+					var association = source.parents('tr');
+					var container = association.parents('table');
+					MyAMS.ajax.post(container.data('ams-location') + '/set-association-visibility.json',
+						{object_name: association.data('ams-element-name')},
+						function (result, status) {
+							if (result.visible) {
+								$('i', source).attr('class', 'fa fa-fw fa-eye');
+							} else {
+								$('i', source).attr('class', 'fa fa-fw fa-eye-slash text-danger');
+							}
+						});
+				};
+			}
+		},
+
+
+		/**
 		 * Paragraphs management
 		 */
 		paragraphs: {
@@ -273,43 +327,6 @@
 
 
 		/**
-		 * Associations management
-		 */
-		associations: {
-
-			refreshAssociations: function(options) {
-				// Reload widget
-				var widget = $('#' + options.object_name).parent('.ams-widget');
-				widget.replaceWith($(options.table));
-				widget = $('#' + options.object_name).parent('.ams-widget');
-				MyAMS.initContent(widget);
-				// Check fieldset state
-				var legend = widget.siblings('legend');
-				if (legend.parents('fieldset:first').hasClass('switched')) {
-					legend.click();
-				}
-			},
-
-			switchVisibility: function (element) {
-				return function () {
-					var source = $(this);
-					var association = source.parents('tr');
-					var container = association.parents('table');
-					MyAMS.ajax.post(container.data('ams-location') + '/set-association-visibility.json',
-						{object_name: association.data('ams-element-name')},
-						function (result, status) {
-							if (result.visible) {
-								$('i', source).attr('class', 'fa fa-fw fa-eye');
-							} else {
-								$('i', source).attr('class', 'fa fa-fw fa-eye-slash text-danger');
-							}
-						});
-				};
-			}
-		},
-
-
-		/**
 		 * Form fields management
 		 */
 		fields: {
@@ -340,20 +357,6 @@
 
 
 		/**
-		 * Illustration management
-		 */
-		illustration: {
-
-			refreshIllustration: function(options) {
-				var parent = $('#' + options.object_name);
-				parent.replaceWith($(options.form));
-				parent = $('#' + options.object_name);
-				MyAMS.initContent(parent);
-			}
-		},
-
-
-		/**
 		 * Themes management
 		 */
 		themes: {
@@ -480,14 +483,14 @@
 
 	$(globals.document).on('PyAMS_content.changed_item', function(event, settings) {
 		switch (settings.object_type) {
-			case 'paragraph':
-				PyAMS_content.paragraphs.refreshParagraph(settings);
+			case 'form':
+				PyAMS_content.refreshForm(settings);
 				break;
 			case 'associations':
 				PyAMS_content.associations.refreshAssociations(settings);
 				break;
-			case 'illustration':
-				PyAMS_content.illustration.refreshIllustration(settings);
+			case 'paragraph':
+				PyAMS_content.paragraphs.refreshParagraph(settings);
 				break;
 			case 'form_field':
 				PyAMS_content.fields.refreshField(settings);