src/pyams_content/skin/resources/js/pyams_content.js
changeset 233 200b656d851d
parent 196 30b26a44e4ae
child 276 78422a1c4228
--- a/src/pyams_content/skin/resources/js/pyams_content.js	Fri Oct 13 08:45:58 2017 +0200
+++ b/src/pyams_content/skin/resources/js/pyams_content.js	Fri Oct 13 08:46:33 2017 +0200
@@ -83,6 +83,10 @@
 		 */
 		galleries: {
 
+			updateImageTitle: function(options) {
+				$('img[id="' + options.image_id + '"]').attr('original-title', options.title);
+			},
+
 			switchImageVisibility: function(element) {
 				return function() {
 					var source = $(this);
@@ -93,30 +97,15 @@
 									function(result, status) {
 										if (result.visible) {
 											$('i', source).attr('class', 'fa fa-fw fa-eye');
+											source.parents('.btn-group').siblings('a.fancyimg').removeClass('not-visible');
 										} else {
 											$('i', source).attr('class', 'fa fa-fw fa-eye-slash text-danger');
+											source.parents('.btn-group').siblings('a.fancyimg').addClass('not-visible');
 										}
 									});
 				};
 			},
 
-			refresh: function(options) {
-				if (typeof(options) === 'string') {
-					options = JSON.parse(options);
-				}
-				var select = $('select[name="form.widgets.galleries:list"]');
-				var plugin = select.data('select2');
-				$('<option></option>').attr('value', options.new_gallery.id)
-									  .attr('selected', 'selected')
-									  .text(options.new_gallery.text)
-									  .appendTo(select);
-				var data = select.select2('data');
-				data.push(options.new_gallery);
-				select.select2('data', data);
-				plugin.results.empty();
-				plugin.opts.populateResults.call(plugin, plugin.results, options.galleries, {term: ''});
-			},
-
 			setOrder: function(event, ui) {
 				if (ui && ui.item.hasClass('already-dropped')) {
 					return;
@@ -150,13 +139,10 @@
 				};
 			},
 
-			refreshContainer: function(changes) {
-				var para = $('tr[data-ams-element-name="' + changes.object_name + '"]');
-				var counter = $('span.count', $('div.action.galleries', para));
-				if (changes.nb_galleries > 0) {
-					counter.text('(' + changes.nb_galleries + ')');
-				} else {
-					counter.text('');
+			afterFancyboxLoad: function(current, previous) {
+				var element = current.element;
+				if (element.hasClass('not-visible')) {
+					current.inner.prepend('<div class="hidden-mask"></div>');
 				}
 			}
 		},
@@ -232,6 +218,18 @@
 		 */
 		paragraphs: {
 
+			/* Store and restore paragraphs state on reload */
+			preReload: function() {
+				PyAMS_content.paragraphs.switched = $('i.switch.fa-minus-square-o', '#paragraphs_list').parents('tr').listattr('id');
+			},
+
+			postReload: function() {
+				$(PyAMS_content.paragraphs.switched).each(function() {
+					$('i.switch.fa-plus-square-o', '[id="' + this + '"]').parents('div:first').click();
+				});
+				delete PyAMS_content.paragraphs.switched;
+			},
+
 			switchVisibility: function(element) {
 				return function() {
 					var source = $(this);
@@ -322,6 +320,47 @@
 													  .addClass('fa-plus-square-o');
 					$('tr', container).removeData('ams-disabled-handlers');
 				}
+			},
+
+			updateToolbar: function(settings) {
+				var container = $('table[id="paragraphs_list"]');
+				var para = $('tr[data-ams-element-name="' + settings.object_name + '"]', container);
+				var toolbar = $('.title-toolbar', para);
+				toolbar.replaceWith(settings.toolbar_tag);
+				toolbar = $('.title-toolbar', para);
+				MyAMS.initContent(toolbar);
+			},
+
+			updateMarkers: function(settings) {
+				var container = $('table[id="paragraphs_list"]');
+				var para = $('tr[data-ams-element-name="' + settings.object_name + '"]', container);
+				var toolbar = $('.title-toolbar', para);
+				var marker = $('DIV.action.' + settings.marker_type, toolbar);
+				if (marker.exists()) {
+					marker.replaceWith(settings.marker_tag);
+				} else {
+					$(settings.marker_tag).appendTo(toolbar);
+				}
+				if (settings.marker_tag) {
+					marker = $('DIV.action.' + settings.marker_type, toolbar);
+					MyAMS.initContent(marker);
+				}
+				MyAMS.helpers.sort(toolbar, 'weight');
+			}
+		},
+
+
+		/**
+		 * Illustrations management
+		 */
+		illustration: {
+
+			addIllustration: function() {
+				var source = $(this);
+				var group = source.parents('.btn-group');
+				var legend = group.siblings('legend.switcher');
+				$('i.fa-plus', legend).click();
+				source.hide();
 			}
 		},
 
@@ -488,23 +527,7 @@
 	globals.PyAMS_content = PyAMS_content;
 
 	$(globals.document).on('PyAMS_content.changed_item', function(event, settings) {
-		switch (settings.object_type) {
-			case 'form':
-				PyAMS_content.refreshForm(settings);
-				break;
-			case 'associations':
-				PyAMS_content.associations.refreshAssociations(settings);
-				break;
-			case 'paragraph':
-				PyAMS_content.paragraphs.refreshParagraph(settings);
-				break;
-			case 'form_field':
-				PyAMS_content.fields.refreshField(settings);
-				break;
-			case 'review_comments':
-				PyAMS_content.review.updateComments();
-				break;
-		}
+		MyAMS.executeFunctionByName(settings.handler, document, settings);
 	});
 
 	var badge = $('.badge', 'nav a[href="#review-comments.html"]');