Updated TinyMCE editor initialization to add custom header formatters
authorThierry Florac <thierry.florac@onf.fr>
Tue, 03 Apr 2018 12:46:09 +0200
changeset 505 e60b9a60b546
parent 504 2c0c2f13789b
child 506 174894a2293d
Updated TinyMCE editor initialization to add custom header formatters
src/pyams_content/skin/resources/js/pyams_content.js
src/pyams_content/skin/resources/js/pyams_content.min.js
--- a/src/pyams_content/skin/resources/js/pyams_content.js	Fri Mar 30 15:38:11 2018 +0200
+++ b/src/pyams_content/skin/resources/js/pyams_content.js	Tue Apr 03 12:46:09 2018 +0200
@@ -34,6 +34,71 @@
 			initEditor: function(settings) {
 				settings.image_list = PyAMS_content.TinyMCE.getImagesList;
 				settings.link_list = PyAMS_content.TinyMCE.getLinksList;
+				settings.style_formats = [
+					{
+						title: 'Headings',
+						items: [
+							{title: 'Heading 3', format: 'h3'},
+							{title: 'Heading 4', format: 'h4'},
+							{title: 'Heading 5', format: 'h5'},
+							{title: 'Heading 6', format: 'h6'}
+						]
+					},
+					{
+						title: 'Inline',
+						items: [
+							{title: 'Bold', icon: 'bold', format: 'bold'},
+							{title: 'Italic', icon: 'italic', format: 'italic'},
+							{title: 'Underline', icon: 'underline', format: 'underline'},
+							{title: 'Strikethrough', icon: 'strikethrough', format: 'strikethrough'},
+							{title: 'Superscript', icon: 'superscript', format: 'superscript'},
+							{title: 'Subscript', icon: 'subscript', format: 'subscript'},
+							{title: 'Code', icon: 'code', format: 'code'}
+						]
+					},
+					{
+						title: 'Blocks',
+						items: [
+							{title: 'Paragraph', format: 'p'},
+							{title: 'Blockquote', format: 'blockquote'},
+							{title: 'Div', format: 'div'},
+							{title: 'Pre', format: 'pre'}
+						]
+					},
+					{
+						title: 'Alignment',
+						items: [
+							{title: 'Left', icon: 'alignleft', format: 'alignleft'},
+							{title: 'Center', icon: 'aligncenter', format: 'aligncenter'},
+							{title: 'Right', icon: 'alignright', format: 'alignright'},
+							{title: 'Justify', icon: 'alignjustify', format: 'alignjustify'}
+						]
+					}
+				];
+				// Declare direct H3 style formatter
+				tinyMCE.PluginManager.add('styles', function (editor, url) {
+					['h3'].forEach(function (name) {
+						editor.addButton("style-" + name, {
+							tooltip: "Toggle " + name + " header",
+							text: name.toUpperCase(),
+							onClick: function () {
+								editor.execCommand('mceToggleFormat', false, name);
+							},
+							onPostRender: function () {
+								var self = this, setup = function () {
+									editor.formatter.formatChanged(name, function (state) {
+										self.active(state);
+									});
+								};
+								editor.formatter ? setup() : editor.on('init', setup);
+							}
+						})
+					});
+				});
+				settings.plugins += ' styles';
+				if (settings.toolbar1) {
+					settings.toolbar1 = "undo redo | styleselect style-h3 style-h4 | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent";
+				}
 				return settings;
 			},
 
@@ -57,6 +122,29 @@
 		},
 
 		/**
+		 * Alerts management
+		 */
+		alerts: {
+
+			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-alert-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');
+							}
+						});
+				};
+			}
+		},
+
+		/**
 		 * Galleries management
 		 */
 		galleries: {
@@ -269,7 +357,6 @@
 											var editor = $('.editor', para);
 											if (editor.is(':empty')) {
 												editor.html(result[para_id]);
-												MyAMS.initContent(editor);
 											}
 											$('.fa-plus-square-o', para).removeClass('fa-plus-square-o')
 																		.addClass('fa-minus-square-o');
@@ -279,6 +366,7 @@
 											switcher.removeClass('fa-cog fa-spin')
 													.addClass('fa-minus-square-o');
 										}
+										MyAMS.initContent(container);
 									});
 				} else {
 					$('.editor', container).each(function() {
--- a/src/pyams_content/skin/resources/js/pyams_content.min.js	Fri Mar 30 15:38:11 2018 +0200
+++ b/src/pyams_content/skin/resources/js/pyams_content.min.js	Tue Apr 03 12:46:09 2018 +0200
@@ -1,1 +1,1 @@
-!function(a,t){"use strict";var e=t.MyAMS,s={widget:{treeview:{selectFolder:function(t,e){a(t.target).siblings('input[type="hidden"]').val(e.id)},unselectFolder:function(t,e){a(t.target).siblings('input[type="hidden"]').val(null)}}},TinyMCE:{initEditor:function(a){return a.image_list=s.TinyMCE.getImagesList,a.link_list=s.TinyMCE.getLinksList,a},getImagesList:function(t){var s=a(document.activeElement).parents("form");if(s.exists()){var i=s.attr("data-ams-form-handler")||s.attr("action"),n=i.substr(0,i.lastIndexOf("/")+1);return e.ajax.post(n+"get-images-list.json",{},t)}},getLinksList:function(t){var s=a(document.activeElement).parents("form");if(s.exists()){var i=s.attr("data-ams-form-handler")||s.attr("action"),n=i.substr(0,i.lastIndexOf("/")+1);return e.ajax.post(n+"get-links-list.json",{},t)}}},galleries:{updateMediaTitle:function(t){a('img[id="'+t.media_id+'"]').attr("original-title",t.title)},switchMediaVisibility:function(t){return function(){var t=a(this),s=t.parents(".media"),i=s.parents(".gallery");e.ajax.post(i.data("ams-location")+"/set-media-visibility.json",{object_name:s.data("ams-element-name")},function(e,s){e.visible?(a("i",t).attr("class","fa fa-fw fa-eye"),t.parents(".btn-group").siblings("a.fancyimg").removeClass("not-visible")):(a("i",t).attr("class","fa fa-fw fa-eye-slash text-danger"),t.parents(".btn-group").siblings("a.fancyimg").addClass("not-visible"))})}},setOrder:function(t,s){if(!s||!s.item.hasClass("already-dropped")){var i=s.item.parents(".gallery"),n=a(".media",i).listattr("data-ams-element-name");e.ajax.post(i.data("ams-location")+"/set-medias-order.json",{medias:JSON.stringify(n)})}},removeMedia:function(t){return function(){var t=a(this);e.skin.bigBox({title:e.i18n.WARNING,content:'<i class="text-danger fa fa-2x fa-bell shake animated"></i>&nbsp; '+e.i18n.DELETE_WARNING,buttons:e.i18n.BTN_OK_CANCEL},function(a){if(a===e.i18n.BTN_OK){var s=t.parents(".gallery").data("ams-location"),i=t.parents(".media"),n=i.data("ams-element-name");e.ajax.post(s+"/delete-element.json",{object_name:n},function(a,t){i.remove()})}})}},afterFancyboxLoad:function(a,t){a.element.hasClass("not-visible")&&a.inner.prepend('<div class="hidden-mask"></div>')}},illustration:{addIllustration:function(){var t=a(this),e=t.parents(".btn-group").siblings("legend.switcher");a("i.fa-plus",e).click(),t.hide()}},associations:{refreshAssociations:function(a){var t=e.skin.refreshTable(a).siblings("legend");t.parents("fieldset:first").hasClass("switched")&&t.click()},switchVisibility:function(t){return function(){var t=a(this),s=t.parents("tr"),i=s.parents("table");e.ajax.post(i.data("ams-location")+"/set-association-visibility.json",{object_name:s.data("ams-element-name")},function(e,s){e.visible?a("i",t).attr("class","fa fa-fw fa-eye"):a("i",t).attr("class","fa fa-fw fa-eye-slash text-danger")})}}},paragraphs:{preReload:function(){s.paragraphs.switched=a("i.switch.fa-minus-square-o","#paragraphs_list").parents("tr").listattr("id")},postReload:function(){a(s.paragraphs.switched).each(function(){a("i.switch.fa-plus-square-o",'[id="'+this+'"]').parents("div").first().click()}),delete s.paragraphs.switched},switchVisibility:function(t){return function(){var t=a(this),s=t.parents("tr"),i=s.parents("table");e.ajax.post(i.data("ams-location")+"/set-paragraph-visibility.json",{object_name:s.data("ams-element-name")},function(e,s){e.visible?a("i",t).attr("class","fa fa-fw fa-eye"):a("i",t).attr("class","fa fa-fw fa-eye-slash text-danger")})}},refreshParagraphs:function(a){var t=e.skin.refreshTable(a).siblings("legend");t.parents("fieldset:first").hasClass("switched")&&t.click()},refreshParagraph:function(t){var e=a('table[id="paragraphs_list"]'),s=a('tr[data-ams-element-name="'+t.object_name+'"]',e);a("span.title",s).html(t.title||" - - - - - - - -")},switchEditor:function(t){var s=a(this),i=a("i.switch",s),n=s.parents("td"),r=a(".editor",n),l=s.parents("tr");if(i.hasClass("fa-plus-square-o")){var o=l.parents("table");r.html('<h1 class="loading"><i class="fa fa-2x fa-gear fa-spin"></i></h1>'),e.ajax.post(o.data("ams-location")+"/get-paragraph-editor.json",{object_name:l.data("ams-element-name")},function(a){r.html(a),a&&(e.initContent(r),i.removeClass("fa-plus-square-o").addClass("fa-minus-square-o"),l.data("ams-disabled-handlers",!0))})}else e.skin.cleanContainer(r),r.empty(),i.removeClass("fa-minus-square-o").addClass("fa-plus-square-o"),l.removeData("ams-disabled-handlers")},switchAllEditors:function(t){var s=a(this),i=a("i",s),n=s.parents("table");i.hasClass("fa-plus-square-o")?(i.removeClass("fa-plus-square-o").addClass("fa-cog fa-spin"),e.ajax.post(n.data("ams-location")+"/get-paragraphs-editors.json",{},function(t){for(var s in t)if(t.hasOwnProperty(s)){var r=a('tr[data-ams-element-name="'+s+'"]',n),l=a(".editor",r);l.is(":empty")&&(l.html(t[s]),e.initContent(l)),a(".fa-plus-square-o",r).removeClass("fa-plus-square-o").addClass("fa-minus-square-o"),r.data("ams-disabled-handlers",!0)}a("i.fa-plus-square-o",a("tbody",n)).exists()||i.removeClass("fa-cog fa-spin").addClass("fa-minus-square-o")})):(a(".editor",n).each(function(){e.skin.cleanContainer(a(this)),a(this).empty()}),a(".fa-minus-square-o",n).removeClass("fa-minus-square-o").addClass("fa-plus-square-o"),a("tr",n).removeData("ams-disabled-handlers"))},updateToolbar:function(t){var s=a('table[id="paragraphs_list"]'),i=a('tr[data-ams-element-name="'+t.object_name+'"]',s),n=a(".title-toolbar",i);n.replaceWith(t.toolbar_tag),n=a(".title-toolbar",i),e.initContent(n)},updateMarkers:function(t){var s=a('table[id="paragraphs_list"]'),i=a('tr[data-ams-element-name="'+t.object_name+'"]',s),n=a(".title-toolbar",i),r=a("DIV.action."+t.marker_type,n);r.exists()?r.replaceWith(t.marker_tag):a(t.marker_tag).appendTo(n),t.marker_tag&&(r=a("DIV.action."+t.marker_type,n),e.initContent(r)),e.helpers.sort(n,"weight")}},milestones:{refreshMilestones:function(a){var t=e.skin.refreshTable(a).siblings("legend");t.parents("fieldset:first").hasClass("switched")&&t.click()},switchVisibility:function(t){return function(){var t=a(this),s=t.parents("tr"),i=s.parents("table");e.ajax.post(i.data("ams-location")+"/set-milestone-visibility.json",{object_name:s.data("ams-element-name")},function(e,s){e.visible?a("i",t).attr("class","fa fa-fw fa-eye"):a("i",t).attr("class","fa fa-fw fa-eye-slash text-danger")})}}},pictograms:{initManagerSelection:function(){var t=a(this),e=a('input[type="hidden"]',a(".selected-pictograms",t)).listattr("value");return{selected:JSON.stringify(e)}},switchPictogram:function(){var t=a(this),e=t.parents(".pictograms"),s=e.parents(".pictograms-manager");e.hasClass("available-pictograms")?a(".selected-pictograms",s).append(t):a(".available-pictograms",s).append(t)},refreshPictograms:function(a){var t=e.skin.refreshTable(a).siblings("legend");t.parents("fieldset:first").hasClass("switched")&&t.click()},switchVisibility:function(t){return function(){var t=a(this),s=t.parents("tr"),i=s.parents("table");e.ajax.post(i.data("ams-location")+"/set-pictogram-visibility.json",{object_name:s.data("ams-element-name")},function(e,s){e.visible?a("i",t).attr("class","fa fa-fw fa-eye"):a("i",t).attr("class","fa fa-fw fa-eye-slash text-danger")})}}},themes:{initExtracts:function(t){var s=a('select[name="form.widgets.thesaurus_name:list"]',t).val(),i=a('select[name="form.widgets.extract_name:list"]',t),n=i.val();s&&e.jsonrpc.post("getExtracts",{thesaurus_name:s},{url:"/api/thesaurus/json"},function(t){i.empty(),a(t.result).each(function(){a("<option></option>").attr("value",this.id).attr("selected",this.id===n).text(this.text).appendTo(i)})}),i.attr("data-ams-events-handlers",'{"select2-open": "PyAMS_content.themes.getExtracts"}')},getExtracts:function(t){var s=a(t.currentTarget).parents("form"),i=a('select[name="form.widgets.thesaurus_name:list"]',s).val();i&&e.jsonrpc.post("getExtracts",{thesaurus_name:i},{url:"/api/thesaurus/json"},function(t){var e=a('select[name="form.widgets.extract_name:list"]',s).data("select2");e.results.empty(),e.opts.populateResults.call(e,e.results,t.result,{term:""})})}},fields:{refreshField:function(t){var e=a('table[id="form_fields_list"]'),s=a('tr[data-ams-element-name="'+t.object_name+'"]',e);a("td:nth-child(4)",s).html(t.title)},switchVisibility:function(t){return function(){var t=a(this),s=t.parents("tr"),i=s.parents("table");e.ajax.post(i.data("ams-location")+"/set-form-field-visibility.json",{object_name:s.data("ams-element-name")},function(e,s){e.visible?a("i",t).attr("class","fa fa-fw fa-eye"):a("i",t).attr("class","fa fa-fw fa-eye-slash text-danger")})}}},imgmap:{init:function(){var t=a(this);e.ajax.check(a.fn.canvasAreaDraw,"/--static--/pyams_content/js/jquery-canvasAreaDraw"+e.devext+".js",function(){t.canvasAreaDraw({imageUrl:t.data("ams-image-url")})})},initPreview:function(){var t=a(this);e.ajax.check(a.fn.mapster,"/--static--/pyams_content/js/jquery-imagemapster-1.2.10"+e.devext+".js",function(){t.mapster({fillColor:"ff0000",fillOpacity:.35,selected:!0,highlight:!0,staticState:!0})})}},types:{switchSubtypes:function(t){var s=a(this),i=a("i.switch",s),n=s.parents("td"),r=a(".subtypes",n),l=s.parents("tr");if(i.hasClass("fa-plus-square-o")){var o=l.parents("table");r.html('<h1 class="loading"><i class="fa fa-2x fa-gear fa-spin"></i></h1>'),e.ajax.post(o.data("ams-location")+"/get-subtypes-table.json",{object_name:l.data("ams-element-name")},function(a){r.html(a),a&&(e.initContent(r),i.removeClass("fa-plus-square-o").addClass("fa-minus-square-o"))})}else e.skin.cleanContainer(r),r.empty(),i.removeClass("fa-minus-square-o").addClass("fa-plus-square-o")}},site:{switchVisibility:function(){return function(){var t=a(this),s=t.parents("tr").first();e.ajax.post(s.data("ams-location")+"/set-content-visibility.json",{object_name:s.data("ams-element-name")},function(e,s){var i;i=e.visible?"fa-eye":"fa-eye-slash",e.published||(i+=" text-danger"),a("i",t).attr("class","fa fa-fw "+i)})}}},review:{timer:null,timer_duration:{general:3e4,chat:5e3},initComments:function(t){var i=a(".chat-body",t);i.animate({scrollTop:i[0].scrollHeight},1e3),clearInterval(s.review.timer),s.review.timer=setInterval(s.review.updateComments,s.review.timer_duration.chat),e.skin.registerCleanCallback(s.review.cleanCommentsCallback)},cleanCommentsCallback:function(){clearInterval(s.review.timer),s.review.timer=setInterval(s.review.updateComments,s.review.timer_duration.general)},updateComments:function(){var t,s=a(".badge",'nav a[href="#review-comments.html"]'),i=a(".chat-body",".widget-body");t=i.exists()?a(".message",i).length:parseInt(s.text()),e.ajax.post("get-last-review-comments.json",{count:t},function(e){i.exists()&&s.removeClass("bg-color-danger").addClass("bg-color-info"),t!==e.count&&(s.text(e.count).removeClass("hidden"),i.exists()&&(a(".messages",i).append(e.content),i.animate({scrollTop:i[0].scrollHeight},1e3)),i.exists()||s.removeClass("bg-color-info").addClass("bg-color-danger").animate({padding:"3px 12px 2px","margin-right":"9px"},"slow",function(){a(this).animate({padding:"3px 6px 2px","margin-right":"15px"},"slow")}))})},initCommentData:function(t){var e=a(".chat-body",".widget-body");return{count:a(".message",e).length}},addCommentAction:function(){return function(){a('textarea[name="comment"]').focus()}},addCommentCallback:function(t){var e=a(this),s=e.parents(".widget-body");a(".messages",s).append(t.content),a('textarea[name="comment"]',e).val("");var i=a(".chat-body",s);i.animate({scrollTop:i[0].scrollHeight},1e3),a(".badge",'nav a[href="#review-comments.html"]').text(t.count).removeClass("hidden")}},profile:{switchFavorite:function(){var t=a(this),s=t.data("sequence-oid");e.ajax.post("switch-user-favorite.json",{oid:s},function(a,e){a.favorite?t.removeClass("fa-star-o").addClass("fa-star"):t.removeClass("fa-star").addClass("fa-star-o")})}}};a(".badge",'nav a[href="#review-comments.html"]').exists()&&(s.review.timer=setInterval(s.review.updateComments,s.review.timer_duration.general)),t.PyAMS_content=s}(jQuery,this);
+!function(a,t){"use strict";var e=t.MyAMS,s={widget:{treeview:{selectFolder:function(t,e){a(t.target).siblings('input[type="hidden"]').val(e.id)},unselectFolder:function(t,e){a(t.target).siblings('input[type="hidden"]').val(null)}}},TinyMCE:{initEditor:function(a){return a.image_list=s.TinyMCE.getImagesList,a.link_list=s.TinyMCE.getLinksList,a},getImagesList:function(t){var s=a(document.activeElement).parents("form");if(s.exists()){var i=s.attr("data-ams-form-handler")||s.attr("action"),n=i.substr(0,i.lastIndexOf("/")+1);return e.ajax.post(n+"get-images-list.json",{},t)}},getLinksList:function(t){var s=a(document.activeElement).parents("form");if(s.exists()){var i=s.attr("data-ams-form-handler")||s.attr("action"),n=i.substr(0,i.lastIndexOf("/")+1);return e.ajax.post(n+"get-links-list.json",{},t)}}},alerts:{switchVisibility:function(t){return function(){var t=a(this),s=t.parents("tr"),i=s.parents("table");e.ajax.post(i.data("ams-location")+"/set-alert-visibility.json",{object_name:s.data("ams-element-name")},function(e,s){e.visible?a("i",t).attr("class","fa fa-fw fa-eye"):a("i",t).attr("class","fa fa-fw fa-eye-slash text-danger")})}}},galleries:{updateMediaTitle:function(t){a('img[id="'+t.media_id+'"]').attr("original-title",t.title)},switchMediaVisibility:function(t){return function(){var t=a(this),s=t.parents(".media"),i=s.parents(".gallery");e.ajax.post(i.data("ams-location")+"/set-media-visibility.json",{object_name:s.data("ams-element-name")},function(e,s){e.visible?(a("i",t).attr("class","fa fa-fw fa-eye"),t.parents(".btn-group").siblings("a.fancyimg").removeClass("not-visible")):(a("i",t).attr("class","fa fa-fw fa-eye-slash text-danger"),t.parents(".btn-group").siblings("a.fancyimg").addClass("not-visible"))})}},setOrder:function(t,s){if(!s||!s.item.hasClass("already-dropped")){var i=s.item.parents(".gallery"),n=a(".media",i).listattr("data-ams-element-name");e.ajax.post(i.data("ams-location")+"/set-medias-order.json",{medias:JSON.stringify(n)})}},removeMedia:function(t){return function(){var t=a(this);e.skin.bigBox({title:e.i18n.WARNING,content:'<i class="text-danger fa fa-2x fa-bell shake animated"></i>&nbsp; '+e.i18n.DELETE_WARNING,buttons:e.i18n.BTN_OK_CANCEL},function(a){if(a===e.i18n.BTN_OK){var s=t.parents(".gallery").data("ams-location"),i=t.parents(".media"),n=i.data("ams-element-name");e.ajax.post(s+"/delete-element.json",{object_name:n},function(a,t){i.remove()})}})}},afterFancyboxLoad:function(a,t){a.element.hasClass("not-visible")&&a.inner.prepend('<div class="hidden-mask"></div>')}},illustration:{addIllustration:function(){var t=a(this),e=t.parents(".btn-group").siblings("legend.switcher");a("i.fa-plus",e).click(),t.hide()}},associations:{refreshAssociations:function(a){var t=e.skin.refreshTable(a).siblings("legend");t.parents("fieldset:first").hasClass("switched")&&t.click()},switchVisibility:function(t){return function(){var t=a(this),s=t.parents("tr"),i=s.parents("table");e.ajax.post(i.data("ams-location")+"/set-association-visibility.json",{object_name:s.data("ams-element-name")},function(e,s){e.visible?a("i",t).attr("class","fa fa-fw fa-eye"):a("i",t).attr("class","fa fa-fw fa-eye-slash text-danger")})}}},paragraphs:{preReload:function(){s.paragraphs.switched=a("i.switch.fa-minus-square-o","#paragraphs_list").parents("tr").listattr("id")},postReload:function(){a(s.paragraphs.switched).each(function(){a("i.switch.fa-plus-square-o",'[id="'+this+'"]').parents("div").first().click()}),delete s.paragraphs.switched},switchVisibility:function(t){return function(){var t=a(this),s=t.parents("tr"),i=s.parents("table");e.ajax.post(i.data("ams-location")+"/set-paragraph-visibility.json",{object_name:s.data("ams-element-name")},function(e,s){e.visible?a("i",t).attr("class","fa fa-fw fa-eye"):a("i",t).attr("class","fa fa-fw fa-eye-slash text-danger")})}},refreshParagraphs:function(a){var t=e.skin.refreshTable(a).siblings("legend");t.parents("fieldset:first").hasClass("switched")&&t.click()},refreshParagraph:function(t){var e=a('table[id="paragraphs_list"]'),s=a('tr[data-ams-element-name="'+t.object_name+'"]',e);a("span.title",s).html(t.title||" - - - - - - - -")},switchEditor:function(t){var s=a(this),i=a("i.switch",s),n=s.parents("td"),r=a(".editor",n),l=s.parents("tr");if(i.hasClass("fa-plus-square-o")){var o=l.parents("table");r.html('<h1 class="loading"><i class="fa fa-2x fa-gear fa-spin"></i></h1>'),e.ajax.post(o.data("ams-location")+"/get-paragraph-editor.json",{object_name:l.data("ams-element-name")},function(a){r.html(a),a&&(e.initContent(r),i.removeClass("fa-plus-square-o").addClass("fa-minus-square-o"),l.data("ams-disabled-handlers",!0))})}else e.skin.cleanContainer(r),r.empty(),i.removeClass("fa-minus-square-o").addClass("fa-plus-square-o"),l.removeData("ams-disabled-handlers")},switchAllEditors:function(t){var s=a(this),i=a("i",s),n=s.parents("table");i.hasClass("fa-plus-square-o")?(i.removeClass("fa-plus-square-o").addClass("fa-cog fa-spin"),e.ajax.post(n.data("ams-location")+"/get-paragraphs-editors.json",{},function(t){for(var s in t)if(t.hasOwnProperty(s)){var r=a('tr[data-ams-element-name="'+s+'"]',n),l=a(".editor",r);l.is(":empty")&&(l.html(t[s]),e.initContent(l)),a(".fa-plus-square-o",r).removeClass("fa-plus-square-o").addClass("fa-minus-square-o"),r.data("ams-disabled-handlers",!0)}a("i.fa-plus-square-o",a("tbody",n)).exists()||i.removeClass("fa-cog fa-spin").addClass("fa-minus-square-o")})):(a(".editor",n).each(function(){e.skin.cleanContainer(a(this)),a(this).empty()}),a(".fa-minus-square-o",n).removeClass("fa-minus-square-o").addClass("fa-plus-square-o"),a("tr",n).removeData("ams-disabled-handlers"))},updateToolbar:function(t){var s=a('table[id="paragraphs_list"]'),i=a('tr[data-ams-element-name="'+t.object_name+'"]',s),n=a(".title-toolbar",i);n.replaceWith(t.toolbar_tag),n=a(".title-toolbar",i),e.initContent(n)},updateMarkers:function(t){var s=a('table[id="paragraphs_list"]'),i=a('tr[data-ams-element-name="'+t.object_name+'"]',s),n=a(".title-toolbar",i),r=a("DIV.action."+t.marker_type,n);r.exists()?r.replaceWith(t.marker_tag):a(t.marker_tag).appendTo(n),t.marker_tag&&(r=a("DIV.action."+t.marker_type,n),e.initContent(r)),e.helpers.sort(n,"weight")}},milestones:{refreshMilestones:function(a){var t=e.skin.refreshTable(a).siblings("legend");t.parents("fieldset:first").hasClass("switched")&&t.click()},switchVisibility:function(t){return function(){var t=a(this),s=t.parents("tr"),i=s.parents("table");e.ajax.post(i.data("ams-location")+"/set-milestone-visibility.json",{object_name:s.data("ams-element-name")},function(e,s){e.visible?a("i",t).attr("class","fa fa-fw fa-eye"):a("i",t).attr("class","fa fa-fw fa-eye-slash text-danger")})}}},pictograms:{initManagerSelection:function(){var t=a(this),e=a('input[type="hidden"]',a(".selected-pictograms",t)).listattr("value");return{selected:JSON.stringify(e)}},switchPictogram:function(){var t=a(this),e=t.parents(".pictograms"),s=e.parents(".pictograms-manager");e.hasClass("available-pictograms")?a(".selected-pictograms",s).append(t):a(".available-pictograms",s).append(t)},refreshPictograms:function(a){var t=e.skin.refreshTable(a).siblings("legend");t.parents("fieldset:first").hasClass("switched")&&t.click()},switchVisibility:function(t){return function(){var t=a(this),s=t.parents("tr"),i=s.parents("table");e.ajax.post(i.data("ams-location")+"/set-pictogram-visibility.json",{object_name:s.data("ams-element-name")},function(e,s){e.visible?a("i",t).attr("class","fa fa-fw fa-eye"):a("i",t).attr("class","fa fa-fw fa-eye-slash text-danger")})}}},themes:{initExtracts:function(t){var s=a('select[name="form.widgets.thesaurus_name:list"]',t).val(),i=a('select[name="form.widgets.extract_name:list"]',t),n=i.val();s&&e.jsonrpc.post("getExtracts",{thesaurus_name:s},{url:"/api/thesaurus/json"},function(t){i.empty(),a(t.result).each(function(){a("<option></option>").attr("value",this.id).attr("selected",this.id===n).text(this.text).appendTo(i)})}),i.attr("data-ams-events-handlers",'{"select2-open": "PyAMS_content.themes.getExtracts"}')},getExtracts:function(t){var s=a(t.currentTarget).parents("form"),i=a('select[name="form.widgets.thesaurus_name:list"]',s).val();i&&e.jsonrpc.post("getExtracts",{thesaurus_name:i},{url:"/api/thesaurus/json"},function(t){var e=a('select[name="form.widgets.extract_name:list"]',s).data("select2");e.results.empty(),e.opts.populateResults.call(e,e.results,t.result,{term:""})})}},fields:{refreshField:function(t){var e=a('table[id="form_fields_list"]'),s=a('tr[data-ams-element-name="'+t.object_name+'"]',e);a("td:nth-child(4)",s).html(t.title)},switchVisibility:function(t){return function(){var t=a(this),s=t.parents("tr"),i=s.parents("table");e.ajax.post(i.data("ams-location")+"/set-form-field-visibility.json",{object_name:s.data("ams-element-name")},function(e,s){e.visible?a("i",t).attr("class","fa fa-fw fa-eye"):a("i",t).attr("class","fa fa-fw fa-eye-slash text-danger")})}}},imgmap:{init:function(){var t=a(this);e.ajax.check(a.fn.canvasAreaDraw,"/--static--/pyams_content/js/jquery-canvasAreaDraw"+e.devext+".js",function(){t.canvasAreaDraw({imageUrl:t.data("ams-image-url")})})},initPreview:function(){var t=a(this);e.ajax.check(a.fn.mapster,"/--static--/pyams_content/js/jquery-imagemapster-1.2.10"+e.devext+".js",function(){t.mapster({fillColor:"ff0000",fillOpacity:.35,selected:!0,highlight:!0,staticState:!0})})}},types:{switchSubtypes:function(t){var s=a(this),i=a("i.switch",s),n=s.parents("td"),r=a(".subtypes",n),l=s.parents("tr");if(i.hasClass("fa-plus-square-o")){var o=l.parents("table");r.html('<h1 class="loading"><i class="fa fa-2x fa-gear fa-spin"></i></h1>'),e.ajax.post(o.data("ams-location")+"/get-subtypes-table.json",{object_name:l.data("ams-element-name")},function(a){r.html(a),a&&(e.initContent(r),i.removeClass("fa-plus-square-o").addClass("fa-minus-square-o"))})}else e.skin.cleanContainer(r),r.empty(),i.removeClass("fa-minus-square-o").addClass("fa-plus-square-o")}},site:{switchVisibility:function(){return function(){var t=a(this),s=t.parents("tr").first();e.ajax.post(s.data("ams-location")+"/set-content-visibility.json",{object_name:s.data("ams-element-name")},function(e,s){var i;i=e.visible?"fa-eye":"fa-eye-slash",e.published||(i+=" text-danger"),a("i",t).attr("class","fa fa-fw "+i)})}}},review:{timer:null,timer_duration:{general:3e4,chat:5e3},initComments:function(t){var i=a(".chat-body",t);i.animate({scrollTop:i[0].scrollHeight},1e3),clearInterval(s.review.timer),s.review.timer=setInterval(s.review.updateComments,s.review.timer_duration.chat),e.skin.registerCleanCallback(s.review.cleanCommentsCallback)},cleanCommentsCallback:function(){clearInterval(s.review.timer),s.review.timer=setInterval(s.review.updateComments,s.review.timer_duration.general)},updateComments:function(){var t,s=a(".badge",'nav a[href="#review-comments.html"]'),i=a(".chat-body",".widget-body");t=i.exists()?a(".message",i).length:parseInt(s.text()),e.ajax.post("get-last-review-comments.json",{count:t},function(e){i.exists()&&s.removeClass("bg-color-danger").addClass("bg-color-info"),t!==e.count&&(s.text(e.count).removeClass("hidden"),i.exists()&&(a(".messages",i).append(e.content),i.animate({scrollTop:i[0].scrollHeight},1e3)),i.exists()||s.removeClass("bg-color-info").addClass("bg-color-danger").animate({padding:"3px 12px 2px","margin-right":"9px"},"slow",function(){a(this).animate({padding:"3px 6px 2px","margin-right":"15px"},"slow")}))})},initCommentData:function(t){var e=a(".chat-body",".widget-body");return{count:a(".message",e).length}},addCommentAction:function(){return function(){a('textarea[name="comment"]').focus()}},addCommentCallback:function(t){var e=a(this),s=e.parents(".widget-body");a(".messages",s).append(t.content),a('textarea[name="comment"]',e).val("");var i=a(".chat-body",s);i.animate({scrollTop:i[0].scrollHeight},1e3),a(".badge",'nav a[href="#review-comments.html"]').text(t.count).removeClass("hidden")}},profile:{switchFavorite:function(){var t=a(this),s=t.data("sequence-oid");e.ajax.post("switch-user-favorite.json",{oid:s},function(a,e){a.favorite?t.removeClass("fa-star-o").addClass("fa-star"):t.removeClass("fa-star").addClass("fa-star-o")})}}};a(".badge",'nav a[href="#review-comments.html"]').exists()&&(s.review.timer=setInterval(s.review.updateComments,s.review.timer_duration.general)),t.PyAMS_content=s}(jQuery,this);