Added pictograms manager settings
authorThierry Florac <thierry.florac@onf.fr>
Tue, 13 Mar 2018 16:29:56 +0100
changeset 473 482e02c1f3d5
parent 472 7b432f971933
child 474 5626317a6b36
Added pictograms manager settings
src/pyams_content/reference/pictograms/__init__.py
src/pyams_content/reference/pictograms/interfaces/__init__.py
src/pyams_content/reference/pictograms/manager.py
src/pyams_content/reference/pictograms/zmi/manager.py
src/pyams_content/reference/pictograms/zmi/templates/manager-selection.pt
src/pyams_content/skin/resources/js/pyams_content.js
src/pyams_content/skin/resources/js/pyams_content.min.js
--- a/src/pyams_content/reference/pictograms/__init__.py	Tue Mar 13 10:58:18 2018 +0100
+++ b/src/pyams_content/reference/pictograms/__init__.py	Tue Mar 13 16:29:56 2018 +0100
@@ -16,7 +16,7 @@
 # import standard library
 
 # import interfaces
-from pyams_content.reference.pictograms.interfaces import IPictogramTable, IPictogram
+from pyams_content.reference.pictograms.interfaces import IPictogramTable, IPictogram, PICTOGRAM_VOCABULARY
 from pyams_i18n.interfaces import II18n
 from zope.component.interfaces import ISite
 from zope.lifecycleevent import IObjectAddedEvent
@@ -54,7 +54,7 @@
     image = I18nFileProperty(IPictogram['image'])
 
 
-@vocabulary_config(name='PyAMS pictograms')
+@vocabulary_config(name=PICTOGRAM_VOCABULARY)
 class PictogramsVocabulary(SimpleVocabulary):
     """Pictograms vocabulary"""
 
@@ -62,8 +62,7 @@
         table = query_utility(IPictogramTable)
         if table is not None:
             request = check_request()
-            terms = [SimpleTerm(v,
-                                token=v.__name__,
+            terms = [SimpleTerm(v.__name__,
                                 title=II18n(v).query_attribute('title', request=request))
                      for v in table.values()]
         else:
--- a/src/pyams_content/reference/pictograms/interfaces/__init__.py	Tue Mar 13 10:58:18 2018 +0100
+++ b/src/pyams_content/reference/pictograms/interfaces/__init__.py	Tue Mar 13 16:29:56 2018 +0100
@@ -17,16 +17,27 @@
 
 # import interfaces
 from pyams_content.reference.interfaces import IReferenceInfo, IReferenceTable
+from zope.annotation.interfaces import IAttributeAnnotatable
 
 # import packages
 from pyams_i18n.schema import I18nImageField
 from zope.container.constraints import containers, contains
+from zope.interface import Interface
+from zope.schema import List, Choice
 
 from pyams_content import _
 
 
+PICTOGRAM_VOCABULARY = 'PyAMS pictograms'
+SELECTED_PICTOGRAM_VOCABULARY = 'PyAMS selected pictograms'
+
+
 class IPictogram(IReferenceInfo):
-    """Pictogram interface"""
+    """Pictogram interface
+
+    Pictograms are managed in a specific reference table to be easily reused by the application
+    into any shared content.
+    """
 
     containers('.IPictogramTable')
 
@@ -39,3 +50,23 @@
     """Pictograms table interface"""
 
     contains(IPictogram)
+
+
+PICTOGRAM_MANAGER_KEY = 'pyams_content.pictogram.manager'
+
+
+class IPictogramManager(Interface):
+    """Pictogram manager interface
+
+    A pictogram manager (typically, a shared tool) is a component which allows selection of a set of
+    pictogram which will be available for selection into shared content.
+    """
+
+    selected_pictograms = List(title=_("Selected pictograms"),
+                               description=_("List of selected pictograms which will be available to shared contents"),
+                               required=False,
+                               value_type=Choice(vocabulary='PyAMS pictograms'))
+
+
+class IPictogramManagerTarget(IAttributeAnnotatable):
+    """Pictogram manager target interface"""
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/pyams_content/reference/pictograms/manager.py	Tue Mar 13 16:29:56 2018 +0100
@@ -0,0 +1,73 @@
+#
+# Copyright (c) 2008-2015 Thierry Florac <tflorac AT ulthar.net>
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+
+__docformat__ = 'restructuredtext'
+
+
+# import standard library
+from persistent import Persistent
+
+# import interfaces
+from pyams_i18n.interfaces import II18n
+from pyams_content.reference.pictograms.interfaces import IPictogramTable, IPictogramManager, IPictogramManagerTarget, \
+    PICTOGRAM_MANAGER_KEY, SELECTED_PICTOGRAM_VOCABULARY
+from zope.annotation import IAnnotations
+
+# import packages
+from pyams_utils.adapter import adapter_config
+from pyams_utils.registry import get_current_registry, query_utility
+from pyams_utils.request import check_request
+from pyams_utils.traversing import get_parent
+from pyams_utils.vocabulary import vocabulary_config
+from zope.container.contained import Contained
+from zope.interface import implementer
+from zope.lifecycleevent import ObjectCreatedEvent
+from zope.location import locate
+from zope.schema.fieldproperty import FieldProperty
+from zope.schema.vocabulary import SimpleVocabulary, SimpleTerm
+
+
+@implementer(IPictogramManager)
+class PictogramManager(Persistent, Contained):
+    """Pictogram manager settings persistent class"""
+
+    selected_pictograms = FieldProperty(IPictogramManager['selected_pictograms'])
+
+
+@adapter_config(context=IPictogramManagerTarget, provides=IPictogramManager)
+def PictogramManagerFactory(target):
+    """Pictogram manager factory"""
+    annotations = IAnnotations(target)
+    manager = annotations.get(PICTOGRAM_MANAGER_KEY)
+    if manager is None:
+        manager = annotations[PICTOGRAM_MANAGER_KEY] = PictogramManager()
+        get_current_registry().notify(ObjectCreatedEvent(manager))
+        locate(manager, target)
+    return manager
+
+
+@vocabulary_config(name=SELECTED_PICTOGRAM_VOCABULARY)
+class SelectedPictogramsVocabulary(SimpleVocabulary):
+    """Selected pictograms vocabulary"""
+
+    def __init__(self, context=None):
+        terms = []
+        table = query_utility(IPictogramTable)
+        if table is not None:
+            manager = get_parent(context, IPictogramManagerTarget)
+            if manager is not None:
+                request = check_request()
+                pictograms = [table.get(name) for name in manager.selected_pictograms]
+                terms = [SimpleTerm(v.__name__,
+                                    title=II18n(v).query_attribute('title', request=request))
+                         for v in pictograms if v is not None]
+        super(SelectedPictogramsVocabulary, self).__init__(terms)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/pyams_content/reference/pictograms/zmi/manager.py	Tue Mar 13 16:29:56 2018 +0100
@@ -0,0 +1,115 @@
+#
+# Copyright (c) 2008-2015 Thierry Florac <tflorac AT ulthar.net>
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+
+__docformat__ = 'restructuredtext'
+
+
+# import standard library
+import json
+
+# import interfaces
+from pyams_content.interfaces import MANAGE_TOOL_PERMISSION
+from pyams_content.reference.pictograms.interfaces import IPictogramManagerTarget, IPictogramManager, IPictogramTable
+from pyams_form.interfaces.form import IWidgetForm, IWidgetsSuffixViewletsManager, IUncheckedEditFormButtons
+from pyams_skin.interfaces import IInnerPage
+from pyams_skin.layer import IPyAMSLayer
+from pyams_utils.interfaces.data import IObjectData
+from pyams_zmi.interfaces.menu import IPropertiesMenu
+from pyams_zmi.layer import IAdminLayer
+
+# import packages
+from pyams_form.form import AJAXEditForm
+from pyams_pagelet.pagelet import pagelet_config
+from pyams_skin.viewlet.menu import MenuItem
+from pyams_template.template import template_config
+from pyams_utils.registry import query_utility
+from pyams_utils.traversing import get_parent
+from pyams_viewlet.viewlet import viewlet_config, Viewlet
+from pyams_zmi.form import AdminEditForm
+from pyramid.view import view_config
+from z3c.form import field, button
+from z3c.form.util import changedField
+from zope.interface import implementer, Interface
+
+from pyams_content import _
+
+
+@viewlet_config(name='pictograms-selection.menu', context=IPictogramManagerTarget, layer=IAdminLayer,
+                manager=IPropertiesMenu, permission=MANAGE_TOOL_PERMISSION, weight=50)
+class PictogramManagerMenu(MenuItem):
+    """Pictogram manager menu"""
+
+    label = _("Pictograms selection...")
+    icon_class = 'fa-paint-brush'
+    url = '#pictograms-selection.html'
+
+
+@pagelet_config(name='pictograms-selection.html', context=IPictogramManagerTarget, layer=IPyAMSLayer,
+                permission=MANAGE_TOOL_PERMISSION)
+@implementer(IWidgetForm, IInnerPage, IObjectData)
+class PictogramManagerEditForm(AdminEditForm):
+    """Pictogram manager selection form"""
+
+    legend = _("Selected pictograms")
+
+    fields = field.Fields(Interface)
+    buttons = button.Buttons(IUncheckedEditFormButtons)
+
+    object_data = {'ams-form-data-init-callback': 'PyAMS_content.pictogram.initManagerSelection'}
+
+    ajax_handler = 'pictograms-selection.json'
+    edit_permission = MANAGE_TOOL_PERMISSION
+
+    def update_content(self, content, data):
+        changes = {}
+        manager = IPictogramManager(self.context)
+        field = IPictogramManager['selected_pictograms']
+        selected = json.loads(self.request.params.get('selected'), '[]')
+        if changedField(field, selected, context=manager):
+            manager.selected_pictograms = selected
+            changes.setdefault(IPictogramManager, []).append(field.__name__)
+        return changes
+
+
+@view_config(name='pictograms-selection.json', context=IPictogramManagerTarget, request_type=IPyAMSLayer,
+             permission=MANAGE_TOOL_PERMISSION, renderer='json', xhr=True)
+class PictogramManagerAJAXEditForm(AJAXEditForm, PictogramManagerEditForm):
+    """Pictogram manager selection form, JSON renderer"""
+
+
+@viewlet_config(name='pictogram-selection.subform', context=IPictogramManagerTarget, layer=IAdminLayer,
+                view=PictogramManagerEditForm, manager=IWidgetsSuffixViewletsManager, permission=MANAGE_TOOL_PERMISSION)
+@template_config(template='templates/manager-selection.pt', layer=IAdminLayer)
+class PictogramManagerSelectionView(Viewlet):
+    """Pictogram manager selection viewlet"""
+
+    @property
+    def available_pictograms(self):
+        table = query_utility(IPictogramTable)
+        target = get_parent(self.context, IPictogramManagerTarget)
+        if target is not None:
+            manager = IPictogramManager(target)
+            for pictogram in table.values():
+                if (not manager.selected_pictograms) or (pictogram.__name__ not in manager.selected_pictograms):
+                    yield pictogram
+
+    @property
+    def selected_pictograms(self):
+        table = query_utility(IPictogramTable)
+        target = get_parent(self.context, IPictogramManagerTarget)
+        if target is not None:
+            manager = IPictogramManager(target)
+            if manager.selected_pictograms:
+                for name in manager.selected_pictograms:
+                    pictogram = table.get(name)
+                    if pictogram is not None:
+                        yield pictogram
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/pyams_content/reference/pictograms/zmi/templates/manager-selection.pt	Tue Mar 13 16:29:56 2018 +0100
@@ -0,0 +1,40 @@
+<div i18n:domain="pyams_content"
+	 data-ams-plugins="pyams_content"
+	 tal:attributes="data-ams-plugin-pyams_content-src extension:resource_path('pyams_content.skin:pyams_content')">
+	<fieldset class="bordered margin-x-20 col-md-5">
+		<legend class="inner" i18n:translate="">Available pictograms</legend>
+		<div class="droppable sortable height-min-100 pictograms available-pictograms viewport-y viewport-500"
+			 data-ams-droppable-accept=".pictogram">
+			<div class="draggable pictogram padding-y-5 clearfix"
+				 data-ams-draggable-connect-sortable=".pictograms"
+				 tal:repeat="pictogram view.available_pictograms">
+				<input type="hidden" name="form.widgets.selected_pictograms:list"
+					   tal:attributes="value pictogram.__name__" />
+				<div class="width-50 text-center pull-left">
+					<img tal:define="img i18n:pictogram.image"
+						 tal:condition="img"
+						 tal:attributes="src extension:absolute_url(img, '++thumb++32x32')" />
+				</div>
+				<span tal:content="i18n:pictogram.title">Title</span>
+			</div>
+		</div>
+	</fieldset>
+	<fieldset class="bordered margin-x-20 col-md-5">
+		<legend class="inner" i18n:translate="">Selected pictograms</legend>
+		<div class="droppable sortable height-min-100 pictograms selected-pictograms viewport-y viewport-500"
+			 data-ams-droppable-accept=".pictogram">
+			<div class="draggable pictogram padding-y-5 clearfix"
+				 data-ams-draggable-connect-sortable=".pictograms"
+				 tal:repeat="pictogram view.selected_pictograms">
+				<input type="hidden" name="form.widgets.selected_pictograms:list"
+					   tal:attributes="value pictogram.__name__" />
+				<div class="width-50 text-center pull-left">
+					<img tal:define="img i18n:pictogram.image"
+						 tal:condition="img"
+						 tal:attributes="src extension:absolute_url(img, '++thumb++32x32')" />
+				</div>
+				<span tal:content="i18n:pictogram.title">Title</span>
+			</div>
+		</div>
+	</fieldset>
+</div>
--- a/src/pyams_content/skin/resources/js/pyams_content.js	Tue Mar 13 10:58:18 2018 +0100
+++ b/src/pyams_content/skin/resources/js/pyams_content.js	Tue Mar 13 16:29:56 2018 +0100
@@ -457,6 +457,20 @@
 		},
 
 		/**
+		 * Pictograms management
+		 */
+		pictogram: {
+
+			initManagerSelection: function() {
+				var form = $(this);
+				var selected = $('input[type="hidden"]', $('.selected-pictograms', form)).listattr('value');
+				return {
+					selected: JSON.stringify(selected)
+				};
+			}
+		},
+
+		/**
 		 * Types management
 		 */
 		types: {
--- a/src/pyams_content/skin/resources/js/pyams_content.min.js	Tue Mar 13 10:58:18 2018 +0100
+++ b/src/pyams_content/skin/resources/js/pyams_content.min.js	Tue Mar 13 16:29:56 2018 +0100
@@ -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")})}}},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")})}}},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),o=s.parents("tr");if(i.hasClass("fa-plus-square-o")){var l=o.parents("table");r.html('<h1 class="loading"><i class="fa fa-2x fa-gear fa-spin"></i></h1>'),e.ajax.post(l.data("ams-location")+"/get-paragraph-editor.json",{object_name:o.data("ams-element-name")},function(a){r.html(a),a&&(e.initContent(r),i.removeClass("fa-plus-square-o").addClass("fa-minus-square-o"),o.data("ams-disabled-handlers",!0))})}else e.skin.cleanContainer(r),r.empty(),i.removeClass("fa-minus-square-o").addClass("fa-plus-square-o"),o.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),o=a(".editor",r);o.is(":empty")&&(o.html(t[s]),e.initContent(o)),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")}},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),o=s.parents("tr");if(i.hasClass("fa-plus-square-o")){var l=o.parents("table");r.html('<h1 class="loading"><i class="fa fa-2x fa-gear fa-spin"></i></h1>'),e.ajax.post(l.data("ams-location")+"/get-subtypes-table.json",{object_name:o.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)}}},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")})}}},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")})}}},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),o=s.parents("tr");if(i.hasClass("fa-plus-square-o")){var l=o.parents("table");r.html('<h1 class="loading"><i class="fa fa-2x fa-gear fa-spin"></i></h1>'),e.ajax.post(l.data("ams-location")+"/get-paragraph-editor.json",{object_name:o.data("ams-element-name")},function(a){r.html(a),a&&(e.initContent(r),i.removeClass("fa-plus-square-o").addClass("fa-minus-square-o"),o.data("ams-disabled-handlers",!0))})}else e.skin.cleanContainer(r),r.empty(),i.removeClass("fa-minus-square-o").addClass("fa-plus-square-o"),o.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),o=a(".editor",r);o.is(":empty")&&(o.html(t[s]),e.initContent(o)),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")}},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})})}},pictogram:{initManagerSelection:function(){var t=a(this),e=a('input[type="hidden"]',a(".selected-pictograms",t)).listattr("value");return{selected:JSON.stringify(e)}}},types:{switchSubtypes:function(t){var s=a(this),i=a("i.switch",s),n=s.parents("td"),r=a(".subtypes",n),o=s.parents("tr");if(i.hasClass("fa-plus-square-o")){var l=o.parents("table");r.html('<h1 class="loading"><i class="fa fa-2x fa-gear fa-spin"></i></h1>'),e.ajax.post(l.data("ams-location")+"/get-subtypes-table.json",{object_name:o.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);