src/pyams_content/skin/resources/js/pyams_content.js
changeset 276 78422a1c4228
parent 233 200b656d851d
child 281 e5bfd8db9f3f
--- a/src/pyams_content/skin/resources/js/pyams_content.js	Fri Nov 10 12:07:09 2017 +0100
+++ b/src/pyams_content/skin/resources/js/pyams_content.js	Fri Nov 10 12:07:43 2017 +0100
@@ -214,6 +214,45 @@
 
 
 		/**
+		 * Types management
+		 */
+		types: {
+
+			switchSubtypes: function(element) {
+				var source = $(this);
+				var switcher = $('i.switch', source);
+				var td = source.parents('td');
+				var subtypes = $('.subtypes', td);
+				var datatype = source.parents('tr');
+				if (switcher.hasClass('fa-plus-square-o')) {
+					var container = datatype.parents('table');
+					subtypes.html('<h1 class="loading"><i class="fa fa-2x fa-gear fa-spin"></i></h1>');
+					MyAMS.ajax.post(container.data('ams-location') + '/get-subtypes-table.json',
+									{object_name: datatype.data('ams-element-name')},
+									function(result) {
+										subtypes.html(result);
+										if (result) {
+											MyAMS.initContent(subtypes);
+											switcher.removeClass('fa-plus-square-o')
+													.addClass('fa-minus-square-o');
+										}
+									});
+				} else {
+					MyAMS.skin.cleanContainer(subtypes);
+					subtypes.empty();
+					switcher.removeClass('fa-minus-square-o')
+							.addClass('fa-plus-square-o');
+				}
+			},
+
+			refreshSubtypes: function(options) {
+				// Reload widget
+				PyAMS_content.refreshTable(options);
+			}
+		},
+
+
+		/**
 		 * Paragraphs management
 		 */
 		paragraphs: {
@@ -247,6 +286,16 @@
 				};
 			},
 
+			refreshParagraphs: 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();
+				}
+			},
+
 			refreshParagraph: function(changes) {
 				var container = $('table[id="paragraphs_list"]');
 				var para = $('tr[data-ams-element-name="' + changes.object_name + '"]', container);