From 036b8e8f3b95feafe80b0eb3e59c37ee08f68909 Mon Sep 17 00:00:00 2001 From: Johannes Raggam Date: Tue, 25 Apr 2017 11:56:51 +0200 Subject: [PATCH] Update thememapper bundle. --- CHANGES.rst | 1 + .../browser/resources/thememapper-compiled.js | 186 ++++++++++++------ .../resources/thememapper-compiled.min.js | 8 +- .../resources/thememapper-compiled.min.js.map | 2 +- 4 files changed, 137 insertions(+), 60 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index 387c54d0..fe195b55 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -17,6 +17,7 @@ New features: Bug fixes: - Fix thememapper pattern handling of buttons (via mockup update). + Update thememapper bundle. [thet] diff --git a/src/plone/app/theming/browser/resources/thememapper-compiled.js b/src/plone/app/theming/browser/resources/thememapper-compiled.js index 80970822..f446cbb3 100644 --- a/src/plone/app/theming/browser/resources/thememapper-compiled.js +++ b/src/plone/app/theming/browser/resources/thememapper-compiled.js @@ -34791,13 +34791,13 @@ define('text!mockup-patterns-relateditems-url/templates/breadcrumb.xml',[],funct define('text!mockup-patterns-relateditems-url/templates/favorite.xml',[],function () { return '
  • <%- title %>
  • \n';}); -define('text!mockup-patterns-relateditems-url/templates/result.xml',[],function () { return '
    \n \n <% if (typeof getURL !== \'undefined\' && ((typeof getIcon !== \'undefined\' && getIcon === true) || portal_type === "Image")) { %>
    <% } %>\n state-<%- review_state %> <% } %> " /span>\n <%- Title %>\n <%- path %>\n
    \n \n <% if (mode !== "search" && is_folderish) { %>\n \n <% } %>\n \n
    \n';}); +define('text!mockup-patterns-relateditems-url/templates/result.xml',[],function () { return '
    \n \n <% if (is_folderish) { %>\n \n <% } %>\n \n \n <% if (typeof getURL !== \'undefined\' && ((typeof getIcon !== \'undefined\' && getIcon === true) || portal_type === "Image")) { %>
    <% } %>\n \t<%- Title %>\n <%- path %>\n
    \n
    \n';}); -define('text!mockup-patterns-relateditems-url/templates/selection.xml',[],function () { return '\n <% if (typeof getURL !== \'undefined\' && ((typeof getIcon !== \'undefined\' && getIcon === true) || portal_type === "Image")) { %>
    <% } %>\n state-<%- review_state %> <% } %>" ><%- Title %>\n <%- path %>\n
    \n';}); +define('text!mockup-patterns-relateditems-url/templates/selection.xml',[],function () { return '\n <% if (typeof getURL !== \'undefined\' && ((typeof getIcon !== \'undefined\' && getIcon === true) || portal_type === "Image")) { %>
    <% } %>\n <%- Title %>\n <%- path %>\n
    \n';}); -define('text!mockup-patterns-relateditems-url/templates/toolbar.xml',[],function () { return '
    \n \n \n
    \n
    \n <%- searchText %>\n \n <%= items %>\n
    \n
    \n <% if (favorites.length > 0) { %>\n \n <% } %>\n
    \n';}); +define('text!mockup-patterns-relateditems-url/templates/toolbar.xml',[],function () { return '<% if (mode!==\'auto\') { %>\n
    \n \n \n
    \n<% } %>\n
    \n <%- searchText %>\n \n <%= items %>\n
    \n
    \n <% if (favorites.length > 0) { %>\n \n <% } %>\n
    \n';}); (function(root) { define("bootstrap-dropdown", ["jquery"], function() { @@ -34979,18 +34979,23 @@ define("bootstrap-dropdown", ["jquery"], function() { * vocabularyUrl(string): This is a URL to a JSON-formatted file used to populate the list (null) * attributes(array): This list is passed to the server during an AJAX request to specify the attributes which should be included on each item. (['UID', 'Title', 'portal_type', 'path']) * basePath(string): Start browse/search in this path. Default: set to rootPath. + * contextPath(string): Path of the object, which is currently edited. If this path is given, this object will not be selectable. * closeOnSelect(boolean): Select2 option. Whether or not the drop down should be closed when an item is selected. (true) * dropdownCssClass(string): Select2 option. CSS class to add to the drop down element. ('pattern-relateditems-dropdown') * favorites(array): Array of objects. These are favorites, which can be used to quickly jump to different locations. Objects have the attributes "title" and "path". Default: [] - * mode(string): Initial widget mode. Possible values: 'search', 'browse'. If set to 'search', the catalog is searched for a searchterm. If set to 'browse', browsing starts at basePath. Default: 'search'. * maximumSelectionSize(integer): The maximum number of items that can be selected in a multi-select control. If this number is less than 1 selection is not limited. (-1) * minimumInputLength: Select2 option. Number of characters necessary to start a search. Default: 0. + * mode(string): Initial widget mode. Possible values: 'search', 'browse'. If set to 'search', the catalog is searched for a searchterm. If set to 'browse', browsing starts at basePath. Default: 'search'. * orderable(boolean): Whether or not items should be drag-and-drop sortable. (true) + * pageSize(int): Batch size to break down big result sets into multiple pages. (10). * rootPath(string): Only display breadcrumb path elements deeper than this path. Default: "/" * rootUrl(string): Visible URL up to the rootPath. This is prepended to the currentPath to generate submission URLs. + * scanSelection(boolean): Scan the list of selected elements for other patterns. * selectableTypes(array): If the value is null all types are selectable. Otherwise, provide a list of strings to match item types that are selectable. (null) * separator(string): Select2 option. String which separates multiple items. (',') * tokenSeparators(array): Select2 option, refer to select2 documentation. ([",", " "]) + * upload(boolen): Allow file and image uploads from within the related items widget. + * uploadAllowView(string): View, which returns a JSON response in the form of {allowUpload: true}, if upload is allowed in the current context. * width(string): Specify a width for the widget. ('100%') * breadcrumbTemplate(string): Template to use for a single item in the breadcrumbs. * breadcrumbTemplateSelector(string): Select an element from the DOM from which to grab the breadcrumbTemplate. (null) @@ -35000,8 +35005,6 @@ define("bootstrap-dropdown", ["jquery"], function() { * resultTemplateSelector(string): Select an element from the DOM from which to grab the resultTemplate. (null) * selectionTemplate(string): Template for element that will be used to construct a selected item. (Refer to source) * selectionTemplateSelector(string): Select an element from the DOM from which to grab the selectionTemplate. (null) - * upload(boolen): Allow file and image uploads from within the related items widget. - * uploadAllowView(string): View, which returns a JSON response in the form of {allowUpload: true}, if upload is allowed in the current context. * * Documentation: * The Related Items pattern is based on Select2 so many of the same options will work here as well. @@ -35061,7 +35064,6 @@ define("bootstrap-dropdown", ["jquery"], function() { * */ - define('mockup-patterns-relateditems',[ 'jquery', 'underscore', @@ -35069,6 +35071,7 @@ define('mockup-patterns-relateditems',[ 'mockup-patterns-select2', 'mockup-ui-url/views/button', 'mockup-utils', + 'pat-registry', 'translate', 'text!mockup-patterns-relateditems-url/templates/breadcrumb.xml', 'text!mockup-patterns-relateditems-url/templates/favorite.xml', @@ -35076,7 +35079,7 @@ define('mockup-patterns-relateditems',[ 'text!mockup-patterns-relateditems-url/templates/selection.xml', 'text!mockup-patterns-relateditems-url/templates/toolbar.xml', 'bootstrap-dropdown' -], function($, _, Base, Select2, ButtonView, utils, _t, +], function($, _, Base, Select2, ButtonView, utils, registry, _t, BreadcrumbTemplate, FavoriteTemplate, ResultTemplate, @@ -35096,23 +35099,27 @@ define('mockup-patterns-relateditems',[ vocabularyUrl: null, // must be set to work // more options - upload: false, attributes: ['UID', 'Title', 'portal_type', 'path', 'getURL', 'getIcon', 'is_folderish', 'review_state'], // used by utils.QueryHelper basePath: '', + pageSize: 10, + browsing: undefined, closeOnSelect: true, + contextPath: undefined, dropdownCssClass: 'pattern-relateditems-dropdown', favorites: [], maximumSelectionSize: -1, minimumInputLength: 0, - mode: 'search', // possible values are search and browse - browsing: undefined, + mode: 'auto', // possible values are search and browse orderable: true, // mockup-patterns-select2 + pathOperator: 'plone.app.querystring.operation.string.path', rootPath: '/', rootUrl: '', // default to be relative. - pathOperator: 'plone.app.querystring.operation.string.path', + scanSelection: false, // False, to no unnecessarily use CPU time on this. selectableTypes: null, // null means everything is selectable, otherwise a list of strings to match types that are selectable separator: ',', tokenSeparators: [',', ' '], + upload: false, + uploadAllowView: undefined, width: '100%', // templates @@ -35144,49 +35151,105 @@ define('mockup-patterns-relateditems',[ template = self.options[tpl + 'Template']; } // let's give all the options possible to the template generation - var options = $.extend(true, {}, self.options, item); + var options = $.extend(true, {}, self.options, item, {'browsing': self.browsing}); options._item = item; return _.template(template)(options); }, - setQuery: function () { + setAjax: function () { - var baseCriteria = []; + var ajax = { - if (this.options.mode == 'search') { - // MODE SEARCH + url: this.options.vocabularyUrl, + dataType: 'JSON', + quietMillis: 100, + + data: function (term, page) { - // restrict to given types - if (this.options.selectableTypes) { - baseCriteria.push({ - i: 'portal_type', - o: 'plone.app.querystring.operation.selection.any', - v: this.options.selectableTypes + var criterias = []; + if (term) { + term = '*' + term + '*'; + criterias.push({ + i: 'SearchableText', + o: 'plone.app.querystring.operation.string.contains', + v: term + }); + } + + // We don't restrict for selectable types while browsing... + if (!this.browsing && this.options.selectableTypes) { + criterias.push({ + i: 'portal_type', + o: 'plone.app.querystring.operation.selection.any', + v: this.options.selectableTypes + }); + } + + criterias.push({ + i: 'path', + o: this.options.pathOperator, + v: this.options.rootPath + this.currentPath + (this.browsing ? '::1' : '') }); - } - baseCriteria.push({ - i: 'path', - o: this.options.pathOperator, - v: this.options.rootPath + this.currentPath - }); + var data = { + query: JSON.stringify({ + criteria: criterias, + sort_on: 'path', + sort_order: 'ascending' + }), + attributes: JSON.stringify(this.options.attributes), + batch: JSON.stringify({ + page: page ? page : 1, + size: this.options.pageSize + }) + }; + return data; + }.bind(this), - } + results: function (data, page) { - // set query object - this.query = new utils.QueryHelper( - $.extend(true, {}, this.options, { - pattern: this, - baseCriteria: baseCriteria - }) - ); + var more = (page * this.options.pageSize) < data.total; + var results = data.results; + + // Filter out non-selectable and non-folderish while browsing. + if (this.browsing) { + results = results.filter( + function (item) { + if (!item.is_folderish && !this.isSelectable(item)) { + return false; + } + return true; + }.bind(this) + ); + } + + // Extend ``data`` with a ``oneLevelUp`` item when browsing + var path = this.currentPath.split('/'); + if (page === 1 && // Show level up only on top. + this.browsing && // only level up when browsing + path.length > 1 && // do not try to level up one level under root. + this.currentPath !== '/' // do not try to level up beyond root + ) { + results = [{ + 'oneLevelUp': true, + 'Title': _('One level up'), + 'path': path.slice(0, path.length - 1).join('/') || '/', + 'portal_type': 'Folder', + 'is_folderish': true, + 'selectable': false + }].concat(results); + } + return { + results: results, + more: more + }; + }.bind(this) + + }; - var ajax = {}; - if (this.query.valid) { - ajax = this.query.selectAjax(); - } this.options.ajax = ajax; this.$el.select2(this.options); + }, setBreadCrumbs: function () { @@ -35200,9 +35263,8 @@ define('mockup-patterns-relateditems',[ _.each(paths, function(node) { if (node !== '') { var item = {}; - itemPath = itemPath + '/' + node; + item.path = itemPath = itemPath + '/' + node; item.text = node; - item.path = itemPath; itemsHtml = itemsHtml + self.applyTemplate('breadcrumb', item); } }); @@ -35210,7 +35272,7 @@ define('mockup-patterns-relateditems',[ // favorites var favoritesHtml = ''; _.each(self.options.favorites, function (item) { - var item_copy = _.clone(item) + var item_copy = _.clone(item); item_copy.path = item_copy.path.substr(self.options.rootPath.length) || '/'; favoritesHtml = favoritesHtml + self.applyTemplate('favorite', item_copy); }); @@ -35233,13 +35295,11 @@ define('mockup-patterns-relateditems',[ if (self.browsing) { $('button.mode.search', self.$toolbar).toggleClass('btn-primary btn-default'); $('button.mode.browse', self.$toolbar).toggleClass('btn-primary btn-default'); - self.options.mode = 'search'; self.browsing = false; if (self.$el.select2('data').length > 0) { // Have to call after initialization self.openAfterInit = true; } - self.setQuery(); if (!self.openAfterInit) { self.$el.select2('close'); self.$el.select2('open'); @@ -35256,13 +35316,11 @@ define('mockup-patterns-relateditems',[ if (!self.browsing) { $('button.mode.search', self.$toolbar).toggleClass('btn-primary btn-default'); $('button.mode.browse', self.$toolbar).toggleClass('btn-primary btn-default'); - self.options.mode = 'browse'; self.browsing = true; if (self.$el.select2('data').length > 0) { // Have to call after initialization self.openAfterInit = true; } - self.setQuery(); if (!self.openAfterInit) { self.$el.select2('close'); self.$el.select2('open'); @@ -35337,7 +35395,6 @@ define('mockup-patterns-relateditems',[ self.currentPath = path; self.$el.select2('close'); self.setBreadCrumbs(); - self.setQuery(); self.$el.select2('open'); self.emit('after-browse'); }, @@ -35366,6 +35423,12 @@ define('mockup-patterns-relateditems',[ isSelectable: function(item) { var self = this; + if (item.selectable === false) { + return false; + } + if (self.options.contextPath === this.options.rootPath + item.path) { + return false; + } if (self.options.selectableTypes === null) { return true; } else { @@ -35376,14 +35439,14 @@ define('mockup-patterns-relateditems',[ init: function() { var self = this; - self.browsing = self.options.mode === 'browse'; + self.browsing = self.options.mode !== 'search'; // Remove trailing slash self.options.rootPath = self.options.rootPath.replace(/\/$/, ''); // Substract rootPath from basePath with is the relative currentPath. Has a leading slash. Or use '/' self.currentPath = self.options.basePath.substr(self.options.rootPath.length) || '/'; - self.setQuery(); + self.setAjax(); self.$el.wrap('
    '); self.$container = self.$el.parents('.pattern-relateditems-container'); @@ -35392,8 +35455,13 @@ define('mockup-patterns-relateditems',[ Select2.prototype.initializeValues.call(self); Select2.prototype.initializeTags.call(self); - self.options.formatSelection = function(item, $container) { - return self.applyTemplate('selection', item); + self.options.formatSelection = function(item) { + // activate petterns on the result set. + var $selection = $(self.applyTemplate('selection', item)); + if (self.options.scanSelection) { + registry.scan($selection); + } + return $selection; }; Select2.prototype.initializeOrdering.call(self); @@ -35408,7 +35476,6 @@ define('mockup-patterns-relateditems',[ return; } } - var result = $(self.applyTemplate('result', item)); $('.pattern-relateditems-result-select', result).on('click', function(event) { @@ -35445,7 +35512,6 @@ define('mockup-patterns-relateditems',[ }; self.options.initSelection = function(element, callback) { - var data = []; var value = $(element).val(); if (value !== '') { var ids = value.split(self.options.separator); @@ -35484,6 +35550,16 @@ define('mockup-patterns-relateditems',[ }; + self.options.tokenizer = function (input) { + if (this.options.mode === 'auto') { + if (input) { + this.browsing = false; + } else { + this.browsing = true; + } + } + }.bind(this); + self.options.id = function(item) { return item.UID; }; diff --git a/src/plone/app/theming/browser/resources/thememapper-compiled.min.js b/src/plone/app/theming/browser/resources/thememapper-compiled.min.js index 009eb6c3..b1450d8b 100644 --- a/src/plone/app/theming/browser/resources/thememapper-compiled.min.js +++ b/src/plone/app/theming/browser/resources/thememapper-compiled.min.js @@ -15,8 +15,8 @@ if(a){if(!this.inMultiSelectMode&&0===this.rangeCount){var c=this.toOrientedRang switch(b.length){case 0:for(;++d").attr(a);this.setElement(d,!1)}}}),b.sync=function(a,d,e){var f=x[a];c.defaults(e||(e={}),{emulateHTTP:b.emulateHTTP,emulateJSON:b.emulateJSON});var g={type:f,dataType:"json"};if(e.url||(g.url=c.result(d,"url")||K()),null!=e.data||!d||"create"!==a&&"update"!==a&&"patch"!==a||(g.contentType="application/json",g.data=JSON.stringify(e.attrs||d.toJSON(e))),e.emulateJSON&&(g.contentType="application/x-www-form-urlencoded",g.data=g.data?{model:g.data}:{}),e.emulateHTTP&&("PUT"===f||"DELETE"===f||"PATCH"===f)){g.type="POST",e.emulateJSON&&(g.data._method=f);var h=e.beforeSend;e.beforeSend=function(a){if(a.setRequestHeader("X-HTTP-Method-Override",f),h)return h.apply(this,arguments)}}"GET"===g.type||e.emulateJSON||(g.processData=!1),"PATCH"===g.type&&w&&(g.xhr=function(){return new ActiveXObject("Microsoft.XMLHTTP")});var i=e.xhr=b.ajax(c.extend(g,e));return d.trigger("request",d,i,e),i};var w=!("undefined"==typeof window||!window.ActiveXObject||window.XMLHttpRequest&&(new XMLHttpRequest).dispatchEvent),x={create:"POST",update:"PUT",patch:"PATCH","delete":"DELETE",read:"GET"};b.ajax=function(){return b.$.ajax.apply(b.$,arguments)};var y=b.Router=function(a){a||(a={}),a.routes&&(this.routes=a.routes),this._bindRoutes(),this.initialize.apply(this,arguments)},z=/\((.*?)\)/g,A=/(\(\?)?:\w+/g,B=/\*\w+/g,C=/[\-{}\[\]+?.,\\\^$|#\s]/g;c.extend(y.prototype,h,{initialize:function(){},route:function(a,d,e){c.isRegExp(a)||(a=this._routeToRegExp(a)),c.isFunction(d)&&(e=d,d=""),e||(e=this[d]);var f=this;return b.history.route(a,function(c){var g=f._extractParameters(a,c);f.execute(e,g),f.trigger.apply(f,["route:"+d].concat(g)),f.trigger("route",d,g),b.history.trigger("route",f,d,g)}),this},execute:function(a,b){a&&a.apply(this,b)},navigate:function(a,c){return b.history.navigate(a,c),this},_bindRoutes:function(){if(this.routes){this.routes=c.result(this,"routes");for(var a,b=c.keys(this.routes);null!=(a=b.pop());)this.route(a,this.routes[a])}},_routeToRegExp:function(a){return a=a.replace(C,"\\$&").replace(z,"(?:$1)?").replace(A,function(a,b){return b?a:"([^/?]+)"}).replace(B,"([^?]*?)"),new RegExp("^"+a+"(?:\\?([\\s\\S]*))?$")},_extractParameters:function(a,b){var d=a.exec(b).slice(1);return c.map(d,function(a,b){return b===d.length-1?a||null:a?decodeURIComponent(a):null})}});var D=b.History=function(){this.handlers=[],c.bindAll(this,"checkUrl"),"undefined"!=typeof window&&(this.location=window.location,this.history=window.history)},E=/^[#\/]|\s+$/g,F=/^\/+|\/+$/g,G=/msie [\w.]+/,H=/\/$/,I=/#.*$/;D.started=!1,c.extend(D.prototype,h,{interval:50,atRoot:function(){return this.location.pathname.replace(/[^\/]$/,"$&/")===this.root},getHash:function(a){var b=(a||this).location.href.match(/#(.*)$/);return b?b[1]:""},getFragment:function(a,b){if(null==a)if(this._hasPushState||!this._wantsHashChange||b){a=decodeURI(this.location.pathname+this.location.search);var c=this.root.replace(H,"");a.indexOf(c)||(a=a.slice(c.length))}else a=this.getHash();return a.replace(E,"")},start:function(a){if(D.started)throw new Error("Backbone.history has already been started");D.started=!0,this.options=c.extend({root:"/"},this.options,a),this.root=this.options.root,this._wantsHashChange=this.options.hashChange!==!1,this._wantsPushState=!!this.options.pushState,this._hasPushState=!!(this.options.pushState&&this.history&&this.history.pushState);var d=this.getFragment(),e=document.documentMode,f=G.exec(navigator.userAgent.toLowerCase())&&(!e||e<=7);if(this.root=("/"+this.root+"/").replace(F,"/"),f&&this._wantsHashChange){var g=b.$('