You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

workflowengine.js 28KB

12345678910111213141516171819202122
  1. !function(e){var n={};function t(o){if(n[o])return n[o].exports;var l=n[o]={i:o,l:!1,exports:{}};return e[o].call(l.exports,l,l.exports,t),l.l=!0,l.exports}t.m=e,t.c=n,t.d=function(e,n,o){t.o(e,n)||Object.defineProperty(e,n,{enumerable:!0,get:o})},t.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},t.t=function(e,n){if(1&n&&(e=t(e)),8&n)return e;if(4&n&&"object"==typeof e&&e&&e.__esModule)return e;var o=Object.create(null);if(t.r(o),Object.defineProperty(o,"default",{enumerable:!0,value:e}),2&n&&"string"!=typeof e)for(var l in e)t.d(o,l,function(n){return e[n]}.bind(null,l));return o},t.n=function(e){var n=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(n,"a",n),n},t.o=function(e,n){return Object.prototype.hasOwnProperty.call(e,n)},t.p="/js/",t(t.s=0)}([function(e,n,t){"use strict";t.r(n);t(1),t(2),t(3),t(4),t(5),t(6),t(7),t(8),t(9),t(10),t(11);window.OCA.WorkflowEngine=OCA.WorkflowEngine},function(e,n){
  2. /**
  3. * @copyright Copyright (c) 2016 Morris Jobke <hey@morrisjobke.de>
  4. *
  5. * @license GNU AGPL version 3 or any later version
  6. *
  7. * This program is free software: you can redistribute it and/or modify
  8. * it under the terms of the GNU Affero General Public License as
  9. * published by the Free Software Foundation, either version 3 of the
  10. * License, or (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU Affero General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Affero General Public License
  18. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. *
  20. */
  21. Handlebars.registerHelper("selectItem",function(e,n){return e===n?'selected="selected"':""}),Handlebars.registerHelper("getOperators",function(e){var n=OCA.WorkflowEngine.getCheckByClass(e);return _.isUndefined(n)?[]:n.operators}),OCA.WorkflowEngine=_.extend(OCA.WorkflowEngine||{},{availablePlugins:[],availableChecks:[],getCheckByClass:function(e){for(var n=OCA.WorkflowEngine.availableChecks.length,t=0;t<n;t++)if(OCA.WorkflowEngine.availableChecks[t].class===e)return OCA.WorkflowEngine.availableChecks[t]}}),OCA.WorkflowEngine.Operation=OC.Backbone.Model.extend({defaults:{class:"OCA\\WorkflowEngine\\Operation",name:"",checks:[],operation:""}}),OCA.WorkflowEngine.OperationsCollection=OC.Backbone.Collection.extend({model:OCA.WorkflowEngine.Operation,url:OC.generateUrl("apps/workflowengine/operations")}),OCA.WorkflowEngine.OperationView=OC.Backbone.View.extend({templateId:"#operation-template",events:{"change .check-class":"checkChanged","change .check-operator":"checkChanged","change .check-value":"checkChanged","change .operation-name":"operationChanged","change .operation-operation":"operationChanged","click .button-reset":"reset","click .button-save":"save","click .button-add":"add","click .button-delete":"delete","click .button-delete-check":"deleteCheck"},originalModel:null,hasChanged:!1,message:"",errorMessage:"",saving:!1,groups:[],template:function(e){return OCA.WorkflowEngine.Templates.operation(_.extend({shortRuleDescTXT:t("workflowengine","Short rule description"),addRuleTXT:t("workflowengine","Add rule"),resetTXT:t("workflowengine","Reset"),saveTXT:t("workflowengine","Save"),savingTXT:t("workflowengine","Saving…")},e))},initialize:function(){this.originalModel=JSON.parse(JSON.stringify(this.model)),this.model.on("change",function(){console.log("model changed"),this.hasChanged=!0,this.render()},this),void 0===this.model.get("id")&&(this.hasChanged=!0);var e=this;$.ajax({url:OC.linkToOCS("cloud/groups",2)+"details",dataType:"json",quietMillis:100}).success(function(n){n.ocs.data.groups&&n.ocs.data.groups.length>0?(n.ocs.data.groups.forEach(function(n){e.groups.push({id:n.id,displayname:n.displayname})}),e.render()):(OC.Notification.error(t("workflowengine","Group list is empty"),{type:"error"}),console.log(n))}).error(function(e){OC.Notification.error(t("workflowengine","Unable to retrieve the group list"),{type:"error"}),console.log(e)})},delete:function(){OC.PasswordConfirmation.requiresPasswordConfirmation()?OC.PasswordConfirmation.requirePasswordConfirmation(_.bind(this.delete,this)):(this.model.destroy(),this.remove())},reset:function(){this.hasChanged=!1,this.model.set(this.originalModel,{silent:!0}),this.render()},save:function(){OC.PasswordConfirmation.requiresPasswordConfirmation()?OC.PasswordConfirmation.requirePasswordConfirmation(_.bind(this.save,this)):(this.hasChanged=!1,this.saving=!0,this.render(),this.model.save(null,{success:function(e,n,o){this.saving=!1,this.originalModel=JSON.parse(JSON.stringify(this.model)),this.message=t("workflowengine","Saved"),this.errorMessage="",this.render()},error:function(e,n,o){this.saving=!1,this.hasChanged=!0,this.message=t("workflowengine","Saving failed:"),this.errorMessage=n.responseText,this.render()},context:this}))},add:function(){var e=_.clone(this.model.get("checks")),n=OCA.WorkflowEngine.availableChecks[0].class,t=OCA.WorkflowEngine.availableChecks[0].operators;e.push({class:n,operator:t[0].operator,value:""}),this.model.set({checks:e})},checkChanged:function(e){for(var n=e.target.value,t=$(e.target.parentElement).data("id"),o=JSON.parse(JSON.stringify(this.model.get("checks"))),l=null,a=0;a<e.target.classList.length;a++){var i=e.target.classList[a];if("check-"===i.substr(0,"check-".length)){l=i.substr("check-".length);break}}if(null!==l)if(_.has(o[t],l)){if(o[t][l]=n,"class"===l){var r=OCA.WorkflowEngine.getCheckByClass(n);_.isUndefined(r)||(o[t].operator=r.operators[0].operator,o[t].value="")}this.model.set({checks:o})}else console.warn('key "'+l+'" is not available in check',r);else console.warn('checkChanged triggered but element doesn\'t have any "check-" class')},deleteCheck:function(e){console.log(arguments);var n=$(e.target.parentElement).data("id"),t=JSON.parse(JSON.stringify(this.model.get("checks")));t.splice(n,1),this.model.set({checks:t})},operationChanged:function(e){for(var n=e.target.value,t=null,o=0;o<e.target.classList.length;o++){var l=e.target.classList[o];if("operation-"===l.substr(0,"operation-".length)){t=l.substr("operation-".length);break}}null!==t?"name"===t||"operation"===t?this.model.set(t,n):console.warn('key "'+t+'" is no valid attribute'):console.warn('operationChanged triggered but element doesn\'t have any "operation-" class')},render:function(){this.$el.html(this.template({operation:this.model.toJSON(),classes:OCA.WorkflowEngine.availableChecks,hasChanged:this.hasChanged,message:this.message,errorMessage:this.errorMessage,saving:this.saving}));var e=this.model.get("checks");return _.each(this.$el.find(".check"),function(n){var t=$(n),o=t.data("id"),l=e[o],a=t.find(".check-value").first(),i=this;_.each(OCA.WorkflowEngine.availablePlugins,function(e){_.isFunction(e.render)&&e.render(a,l,i.groups)})},this),""!==this.message&&(_.delay(function(e){$(e).css("opacity",0)},7e3,this.$el.find(".msg.success")),this.message=""),this.$el}}),OCA.WorkflowEngine.OperationsView=OC.Backbone.View.extend({templateId:"#operations-template",collection:null,$el:null,events:{"click .button-add-operation":"add"},template:function(e){return OCA.WorkflowEngine.Templates.operations(_.extend({addRuleGroupTXT:t("workflowengine","Add rule group")},e))},initialize:function(e){OCA.WorkflowEngine.availablePlugins.length||(OCA.WorkflowEngine.availablePlugins=OC.Plugins.getPlugins("OCA.WorkflowEngine.CheckPlugins"),_.each(OCA.WorkflowEngine.availablePlugins,function(n){_.isFunction(n.getCheck)&&OCA.WorkflowEngine.availableChecks.push(n.getCheck(e))})),this.collection.fetch({data:{class:e}}),this.collection.once("sync",this.render,this)},add:function(){var e=this.collection.create();this.renderOperation(e)},renderOperation:function(e){this.$el.find(".operations").append(e.$el),e.render()},render:function(){this.$el.html(this.template()),this.collection.each(this.renderOperation,this)}})},function(e,n){function t(e){return(t="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}var o,l;o=Handlebars.template,(l=OCA.WorkflowEngine.Templates=OCA.WorkflowEngine.Templates||{}).operation=o({1:function(e,n,t,o,l){return" modified"},3:function(e,n,t,o,l){return'\t\t\t<span class="button-delete icon-delete"></span>\n'},5:function(e,n,o,l,a,i,r){var s,c,u=null!=n?n:e.nullContext||{},g=o.helperMissing,f=e.escapeExpression;return'\t\t\t<div class="check" data-id="'+f("function"===t(c=null!=(c=o.index||a&&a.index)?c:g)?c.call(u,{name:"index",hash:{},data:a}):c)+'">\n\t\t\t\t<select class="check-class">\n'+(null!=(s=o.each.call(u,null!=r[1]?r[1].classes:r[1],{name:"each",hash:{},fn:e.program(6,a,0,i,r),inverse:e.noop,data:a}))?s:"")+'\t\t\t\t</select>\n\t\t\t\t<select class="check-operator">\n'+(null!=(s=o.each.call(u,(o.getOperators||n&&n.getOperators||g).call(u,null!=n?n.class:n,{name:"getOperators",hash:{},data:a}),{name:"each",hash:{},fn:e.program(8,a,0,i,r),inverse:e.noop,data:a}))?s:"")+'\t\t\t\t</select>\n\t\t\t\t<input type="text" class="check-value" value="'+f("function"===t(c=null!=(c=o.value||(null!=n?n.value:n))?c:g)?c.call(u,{name:"value",hash:{},data:a}):c)+'">\n\t\t\t\t<span class="button-delete-check icon-delete"></span>\n\t\t\t</div>\n'},6:function(e,n,o,l,a,i,r){var s,c,u=null!=n?n:e.nullContext||{},g=o.helperMissing,f=e.escapeExpression;return'\t\t\t\t\t\t<option value="'+f("function"===t(c=null!=(c=o.class||(null!=n?n.class:n))?c:g)?c.call(u,{name:"class",hash:{},data:a}):c)+'" '+(null!=(s=(o.selectItem||n&&n.selectItem||g).call(u,null!=n?n.class:n,null!=r[1]?r[1].class:r[1],{name:"selectItem",hash:{},data:a}))?s:"")+">"+f("function"===t(c=null!=(c=o.name||(null!=n?n.name:n))?c:g)?c.call(u,{name:"name",hash:{},data:a}):c)+"</option>\n"},8:function(e,n,o,l,a,i,r){var s,c,u=null!=n?n:e.nullContext||{},g=o.helperMissing,f=e.escapeExpression;return'\t\t\t\t\t\t<option value="'+f("function"===t(c=null!=(c=o.operator||(null!=n?n.operator:n))?c:g)?c.call(u,{name:"operator",hash:{},data:a}):c)+'" '+(null!=(s=(o.selectItem||n&&n.selectItem||g).call(u,null!=n?n.operator:n,null!=r[1]?r[1].operator:r[1],{name:"selectItem",hash:{},data:a}))?s:"")+">"+f("function"===t(c=null!=(c=o.name||(null!=n?n.name:n))?c:g)?c.call(u,{name:"name",hash:{},data:a}):c)+"</option>\n"},10:function(e,n,t,o,l){var a,i,r=null!=n?n:e.nullContext||{};return(null!=(a=t.if.call(r,null!=(a=null!=n?n.operation:n)?a.id:a,{name:"if",hash:{},fn:e.program(11,l,0),inverse:e.noop,data:l}))?a:"")+'\t\t<button class="button-save pull-right">'+e.escapeExpression("function"==typeof(i=null!=(i=t.saveTXT||(null!=n?n.saveTXT:n))?i:t.helperMissing)?i.call(r,{name:"saveTXT",hash:{},data:l}):i)+"</button>\n"},11:function(e,n,t,o,l){var a;return'\t\t\t<button class="button-reset pull-right">'+e.escapeExpression("function"==typeof(a=null!=(a=t.resetTXT||(null!=n?n.resetTXT:n))?a:t.helperMissing)?a.call(null!=n?n:e.nullContext||{},{name:"resetTXT",hash:{},data:l}):a)+"</button>\n"},13:function(e,n,t,o,l){var a;return'\t\t<span class="icon-loading-small pull-right"></span>\n\t\t<span class="pull-right">'+e.escapeExpression("function"==typeof(a=null!=(a=t.savingTXT||(null!=n?n.savingTXT:n))?a:t.helperMissing)?a.call(null!=n?n:e.nullContext||{},{name:"savingTXT",hash:{},data:l}):a)+"</span>\n\t"},15:function(e,n,t,o,l){var a;return null!=(a=t.if.call(null!=n?n:e.nullContext||{},null!=n?n.message:n,{name:"if",hash:{},fn:e.program(16,l,0),inverse:e.noop,data:l}))?a:""},16:function(e,n,t,o,l){var a,i,r=null!=n?n:e.nullContext||{};return'\n\t\t<span class="msg pull-right '+(null!=(a=t.if.call(r,null!=n?n.errorMessage:n,{name:"if",hash:{},fn:e.program(17,l,0),inverse:e.program(19,l,0),data:l}))?a:"")+'">\n\t\t\t\t\t'+e.escapeExpression("function"==typeof(i=null!=(i=t.message||(null!=n?n.message:n))?i:t.helperMissing)?i.call(r,{name:"message",hash:{},data:l}):i)+(null!=(a=t.if.call(r,null!=n?n.errorMessage:n,{name:"if",hash:{},fn:e.program(21,l,0),inverse:e.noop,data:l}))?a:"")+"\n\t\t\t\t</span>\n\t"},17:function(e,n,t,o,l){return"error"},19:function(e,n,t,o,l){return"success"},21:function(e,n,t,o,l){var a;return" "+e.escapeExpression("function"==typeof(a=null!=(a=t.errorMessage||(null!=n?n.errorMessage:n))?a:t.helperMissing)?a.call(null!=n?n:e.nullContext||{},{name:"errorMessage",hash:{},data:l}):a)},compiler:[7,">= 4.0.0"],main:function(e,n,o,l,a,i,r){var s,c,u=null!=n?n:e.nullContext||{},g=o.helperMissing,f=e.escapeExpression,d=e.lambda;return'<div class="operation'+(null!=(s=o.if.call(u,null!=n?n.hasChanged:n,{name:"if",hash:{},fn:e.program(1,a,0,i,r),inverse:e.noop,data:a}))?s:"")+'">\n\t<div class="operation-header">\n\t\t<input type="text" class="operation-name" placeholder="'+f("function"===t(c=null!=(c=o.shortRuleDescTXT||(null!=n?n.shortRuleDescTXT:n))?c:g)?c.call(u,{name:"shortRuleDescTXT",hash:{},data:a}):c)+'" value="'+f(d(null!=(s=null!=n?n.operation:n)?s.name:s,n))+'" />\n\t\t<input type="text" class="operation-operation" value="'+f(d(null!=(s=null!=n?n.operation:n)?s.operation:s,n))+'" />\n'+(null!=(s=o.if.call(u,null!=(s=null!=n?n.operation:n)?s.id:s,{name:"if",hash:{},fn:e.program(3,a,0,i,r),inverse:e.noop,data:a}))?s:"")+'\t</div>\n\n\t<div class="checks">\n'+(null!=(s=o.each.call(u,null!=(s=null!=n?n.operation:n)?s.checks:s,{name:"each",hash:{},fn:e.program(5,a,0,i,r),inverse:e.noop,data:a}))?s:"")+'\t</div>\n\t<button class="button-add">'+f("function"===t(c=null!=(c=o.addRuleTXT||(null!=n?n.addRuleTXT:n))?c:g)?c.call(u,{name:"addRuleTXT",hash:{},data:a}):c)+"</button>\n"+(null!=(s=o.if.call(u,null!=n?n.hasChanged:n,{name:"if",hash:{},fn:e.program(10,a,0,i,r),inverse:e.noop,data:a}))?s:"")+(null!=(s=o.if.call(u,null!=n?n.saving:n,{name:"if",hash:{},fn:e.program(13,a,0,i,r),inverse:e.program(15,a,0,i,r),data:a}))?s:"")+"\n</div>\n"},useData:!0,useDepths:!0}),l.operations=o({compiler:[7,">= 4.0.0"],main:function(e,n,t,o,l){var a;return'<div class="operations"></div>\n<button class="button-add-operation">'+e.escapeExpression("function"==typeof(a=null!=(a=t.addRuleGroupTXT||(null!=n?n.addRuleGroupTXT:n))?a:t.helperMissing)?a.call(null!=n?n:e.nullContext||{},{name:"addRuleGroupTXT",hash:{},data:l}):a)+"</button>\n"},useData:!0})},function(e,n){OCA.WorkflowEngine=OCA.WorkflowEngine||{},OCA.WorkflowEngine.Plugins=OCA.WorkflowEngine.Plugins||{},OCA.WorkflowEngine.Plugins.FileMimeTypePlugin={getCheck:function(){return{class:"OCA\\WorkflowEngine\\Check\\FileMimeType",name:t("workflowengine","File MIME type"),operators:[{operator:"is",name:t("workflowengine","is")},{operator:"!is",name:t("workflowengine","is not")},{operator:"matches",name:t("workflowengine","matches")},{operator:"!matches",name:t("workflowengine","does not match")}]}},render:function(e,n){if("OCA\\WorkflowEngine\\Check\\FileMimeType"===n.class){var o="text/plain";"matches"!==n.operator&&"!matches"!==n.operator||(o="/^text\\/(plain|html)$/i",this._validateRegex(n.value)?$(e).removeClass("invalid-input"):$(e).addClass("invalid-input")),$(e).css("width","250px").attr("placeholder",o).attr("title",t("workflowengine","Example: {placeholder}",{placeholder:o})).addClass("has-tooltip").tooltip({placement:"bottom"})}},_validateRegex:function(e){return null!==/^\/(.*)\/([gui]{0,3})$/.exec(e)}},OC.Plugins.register("OCA.WorkflowEngine.CheckPlugins",OCA.WorkflowEngine.Plugins.FileMimeTypePlugin)},function(e,n){OCA.WorkflowEngine=OCA.WorkflowEngine||{},OCA.WorkflowEngine.Plugins=OCA.WorkflowEngine.Plugins||{},OCA.WorkflowEngine.Plugins.FileNamePlugin={getCheck:function(){return{class:"OCA\\WorkflowEngine\\Check\\FileName",name:t("workflowengine","File name"),operators:[{operator:"is",name:t("workflowengine","is")},{operator:"!is",name:t("workflowengine","is not")},{operator:"matches",name:t("workflowengine","matches")},{operator:"!matches",name:t("workflowengine","does not match")}]}},render:function(e,n){if("OCA\\WorkflowEngine\\Check\\FileName"===n.class){var o="dummy.jpg";"matches"!==n.operator&&"!matches"!==n.operator||(o="/^dummy-.+$/i",this._validateRegex(n.value)?$(e).removeClass("invalid-input"):$(e).addClass("invalid-input")),$(e).css("width","250px").attr("placeholder",o).attr("title",t("workflowengine","Example: {placeholder}",{placeholder:o})).addClass("has-tooltip").tooltip({placement:"bottom"})}},_validateRegex:function(e){return null!==/^\/(.*)\/([gui]{0,3})$/.exec(e)}},OC.Plugins.register("OCA.WorkflowEngine.CheckPlugins",OCA.WorkflowEngine.Plugins.FileNamePlugin)},function(e,n){OCA.WorkflowEngine=OCA.WorkflowEngine||{},OCA.WorkflowEngine.Plugins=OCA.WorkflowEngine.Plugins||{},OCA.WorkflowEngine.Plugins.FileSizePlugin={getCheck:function(){return{class:"OCA\\WorkflowEngine\\Check\\FileSize",name:t("workflowengine","File size (upload)"),operators:[{operator:"less",name:t("workflowengine","less")},{operator:"!greater",name:t("workflowengine","less or equals")},{operator:"!less",name:t("workflowengine","greater or equals")},{operator:"greater",name:t("workflowengine","greater")}]}},render:function(e,n){"OCA\\WorkflowEngine\\Check\\FileSize"===n.class&&$(e).css("width","250px").attr("placeholder","12 MB").attr("title",t("workflowengine","Example: {placeholder}",{placeholder:"12 MB"})).addClass("has-tooltip").tooltip({placement:"bottom"})}},OC.Plugins.register("OCA.WorkflowEngine.CheckPlugins",OCA.WorkflowEngine.Plugins.FileSizePlugin)},function(e,n){OCA.WorkflowEngine=OCA.WorkflowEngine||{},OCA.WorkflowEngine.Plugins=OCA.WorkflowEngine.Plugins||{},OCA.WorkflowEngine.Plugins.FileSystemTagsPlugin={getCheck:function(){return this.collection=OC.SystemTags.collection,{class:"OCA\\WorkflowEngine\\Check\\FileSystemTags",name:t("workflowengine","File system tag"),operators:[{operator:"is",name:t("workflowengine","is tagged with")},{operator:"!is",name:t("workflowengine","is not tagged with")}]}},render:function(e,n){"OCA\\WorkflowEngine\\Check\\FileSystemTags"===n.class&&($(e).css("width","400px"),$(e).select2({allowClear:!1,multiple:!1,placeholder:t("workflowengine","Select tag…"),query:_.debounce(function(e){e.callback({results:OC.SystemTags.collection.filterByName(e.term)})},100,!0),id:function(e){return e.get("id")},initSelection:function(e,n){n($(e).val())},formatResult:function(e){return OC.SystemTags.getDescriptiveTag(e)},formatSelection:function(e){var n=OC.SystemTags.collection.get(e);if(!_.isUndefined(n))return OC.SystemTags.getDescriptiveTag(n)},escapeMarkup:function(e){return e}}))}},OC.Plugins.register("OCA.WorkflowEngine.CheckPlugins",OCA.WorkflowEngine.Plugins.FileSystemTagsPlugin)},function(e,n){OCA.WorkflowEngine=OCA.WorkflowEngine||{},OCA.WorkflowEngine.Plugins=OCA.WorkflowEngine.Plugins||{},OCA.WorkflowEngine.Plugins.RequestRemoteAddressPlugin={getCheck:function(){return{class:"OCA\\WorkflowEngine\\Check\\RequestRemoteAddress",name:t("workflowengine","Request remote address"),operators:[{operator:"matchesIPv4",name:t("workflowengine","matches IPv4")},{operator:"!matchesIPv4",name:t("workflowengine","does not match IPv4")},{operator:"matchesIPv6",name:t("workflowengine","matches IPv6")},{operator:"!matchesIPv6",name:t("workflowengine","does not match IPv6")}]}},render:function(e,n){if("OCA\\WorkflowEngine\\Check\\RequestRemoteAddress"===n.class){var o="127.0.0.1/32";"matchesIPv6"===n.operator||"!matchesIPv6"===n.operator?(o="::1/128",this._validateIPv6(n.value)?$(e).removeClass("invalid-input"):$(e).addClass("invalid-input")):this._validateIPv4(n.value)?$(e).removeClass("invalid-input"):$(e).addClass("invalid-input"),$(e).css("width","300px").attr("placeholder",o).attr("title",t("workflowengine","Example: {placeholder}",{placeholder:o})).addClass("has-tooltip").tooltip({placement:"bottom"})}},_validateIPv4:function(e){return null!==/^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\/(3[0-2]|[1-2][0-9]|[1-9])$/.exec(e)},_validateIPv6:function(e){return null!==/^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))\/(1([01][0-9]|2[0-8])|[1-9][0-9]|[0-9])$/.exec(e)}},OC.Plugins.register("OCA.WorkflowEngine.CheckPlugins",OCA.WorkflowEngine.Plugins.RequestRemoteAddressPlugin)},function(e,n){OCA.WorkflowEngine=OCA.WorkflowEngine||{},OCA.WorkflowEngine.Plugins=OCA.WorkflowEngine.Plugins||{},OCA.WorkflowEngine.Plugins.RequestTimePlugin={timezones:["Europe/Berlin","Europe/London"],_$element:null,getCheck:function(){return{class:"OCA\\WorkflowEngine\\Check\\RequestTime",name:t("workflowengine","Request time"),operators:[{operator:"in",name:t("workflowengine","between")},{operator:"!in",name:t("workflowengine","not between")}]}},render:function(e,n){if("OCA\\WorkflowEngine\\Check\\RequestTime"===n.class){var o="09:00",l="18:00",a=jstz.determine().name(),i=$(e);if(_.isString(n.value)&&""!==n.value){var r=JSON.parse(n.value),s=r[0].split(" ",2),c=r[1].split(" ",2);o=s[0],l=c[0],a=s[1]}var u=JSON.stringify([o+" "+a,l+" "+a]);n.value!==u&&(n.value=u,i.val(u)),i.css("display","none"),$("<input>").attr("type","text").attr("placeholder",t("workflowengine","Start")).attr("title",t("workflowengine","Example: {placeholder}",{placeholder:"16:00"})).addClass("has-tooltip").tooltip({placement:"bottom"}).addClass("start").val(o).insertBefore(i),$("<input>").attr("type","text").attr("placeholder",t("workflowengine","End")).attr("title",t("workflowengine","Example: {placeholder}",{placeholder:"16:00"})).addClass("has-tooltip").tooltip({placement:"bottom"}).addClass("end").val(l).insertBefore(i);var g=$("<input>").attr("type","hidden").css("width","250px").insertBefore(i).val(a);g.select2({allowClear:!1,multiple:!1,placeholder:t("workflowengine","Select timezone…"),ajax:{url:OC.generateUrl("apps/workflowengine/timezones"),dataType:"json",quietMillis:100,data:function(e){return""===e&&(e=(e=jstz.determine().name().split("/"))[0]),{search:e}},results:function(e){var n=[];return $.each(e,function(e){n.push({id:e})}),{results:n,more:!1}}},initSelection:function(e,n){n(e.val())},formatResult:function(e){return"<span>"+e.id+"</span>"},formatSelection:function(e){return _.isUndefined(e.id)||(e=e.id),"<span>"+e+"</span>"}}),g.addClass("timezone"),i.parent().on("change",".start",_.bind(this.update,this)).on("change",".end",_.bind(this.update,this)).on("change",".timezone",_.bind(this.update,this)),this._$element=i}},update:function(e){for(var n=e.target.value,t=null,o=0;o<e.target.classList.length;o++)t=e.target.classList[o];if(null!==t){var l=JSON.parse(this._$element.val()),a=moment(l[0].split(" ",2)[0],"H:m Z"),i=moment(l[1].split(" ",2)[0],"H:m Z"),r=l[0].split(" ",2)[1];if("start"===t||"end"===t){var s=moment(n,["H:m","h:m a"],!0).format("HH:mm");if("Invalid date"===s)return;var c=0;"end"===t&&(c=1),l[c]=s+" "+r}"timezone"===t&&(l[0]=a.format("HH:mm")+" "+n,l[1]=i.format("HH:mm")+" "+n),this._$element.val(JSON.stringify(l)),this._$element.trigger("change")}else console.warn("update triggered but element doesn't have any class")}},OC.Plugins.register("OCA.WorkflowEngine.CheckPlugins",OCA.WorkflowEngine.Plugins.RequestTimePlugin)},function(e,n){OCA.WorkflowEngine=OCA.WorkflowEngine||{},OCA.WorkflowEngine.Plugins=OCA.WorkflowEngine.Plugins||{},OCA.WorkflowEngine.Plugins.RequestURLPlugin={predefinedValues:["webdav"],getCheck:function(){return{class:"OCA\\WorkflowEngine\\Check\\RequestURL",name:t("workflowengine","Request URL"),operators:[{operator:"is",name:t("workflowengine","is")},{operator:"!is",name:t("workflowengine","is not")},{operator:"matches",name:t("workflowengine","matches")},{operator:"!matches",name:t("workflowengine","does not match")}]}},render:function(e,n){if("OCA\\WorkflowEngine\\Check\\RequestURL"===n.class){var o="https://localhost/index.php";if("matches"!==n.operator&&"!matches"!==n.operator||(o="/^https\\:\\/\\/localhost\\/index\\.php$/i"),$(e).css("width","250px").attr("placeholder",o).attr("title",t("workflowengine","Example: {placeholder}",{placeholder:o})).addClass("has-tooltip").tooltip({placement:"bottom"}),"matches"===n.operator||"!matches"===n.operator)this._validateRegex(n.value)?$(e).removeClass("invalid-input"):$(e).addClass("invalid-input");else{var l=this,a=[{text:t("workflowengine","Predefined URLs"),children:[{id:"webdav",text:t("workflowengine","Files WebDAV")}]}];-1===this.predefinedValues.indexOf(n.value)&&a.unshift({id:n.value,text:n.value}),$(e).select2({data:a,createSearchChoice:function(e){if(-1===l.predefinedValues.indexOf(n.value))return{id:e,text:e}},id:function(e){return e.id},formatResult:function(e){return e.text},formatSelection:function(e){return e.text},escapeMarkup:function(e){return e}})}}},_validateRegex:function(e){return null!==/^\/(.*)\/([gui]{0,3})$/.exec(e)}},OC.Plugins.register("OCA.WorkflowEngine.CheckPlugins",OCA.WorkflowEngine.Plugins.RequestURLPlugin)},function(e,n){OCA.WorkflowEngine=OCA.WorkflowEngine||{},OCA.WorkflowEngine.Plugins=OCA.WorkflowEngine.Plugins||{},OCA.WorkflowEngine.Plugins.RequestUserAgentPlugin={predefinedValues:["android","ios","desktop"],getCheck:function(){return{class:"OCA\\WorkflowEngine\\Check\\RequestUserAgent",name:t("workflowengine","Request user agent"),operators:[{operator:"is",name:t("workflowengine","is")},{operator:"!is",name:t("workflowengine","is not")},{operator:"matches",name:t("workflowengine","matches")},{operator:"!matches",name:t("workflowengine","does not match")}]}},render:function(e,n){if("OCA\\WorkflowEngine\\Check\\RequestUserAgent"===n.class){var o="Mozilla/5.0 User Agent";if("matches"!==n.operator&&"!matches"!==n.operator||(o="/^Mozilla\\/5\\.0 (.*)$/i"),$(e).css("width","250px").attr("placeholder",o).attr("title",t("workflowengine","Example: {placeholder}",{placeholder:o})).addClass("has-tooltip").tooltip({placement:"bottom"}),"matches"===n.operator||"!matches"===n.operator)this._validateRegex(n.value)?$(e).removeClass("invalid-input"):$(e).addClass("invalid-input");else{var l=this,a=[{text:t("workflowengine","Sync clients"),children:[{id:"android",text:t("workflowengine","Android client")},{id:"ios",text:t("workflowengine","iOS client")},{id:"desktop",text:t("workflowengine","Desktop client")},{id:"mail",text:t("workflowengine","Thunderbird & Outlook addons")}]}];-1===this.predefinedValues.indexOf(n.value)&&a.unshift({id:n.value,text:n.value}),$(e).select2({data:a,createSearchChoice:function(e){if(-1===l.predefinedValues.indexOf(n.value))return{id:e,text:e}},id:function(e){return e.id},formatResult:function(e){return e.text},formatSelection:function(e){return e.text},escapeMarkup:function(e){return e}})}}},_validateRegex:function(e){return null!==/^\/(.*)\/([gui]{0,3})$/.exec(e)}},OC.Plugins.register("OCA.WorkflowEngine.CheckPlugins",OCA.WorkflowEngine.Plugins.RequestUserAgentPlugin)},function(e,n){OCA.WorkflowEngine=OCA.WorkflowEngine||{},OCA.WorkflowEngine.Plugins=OCA.WorkflowEngine.Plugins||{},OCA.WorkflowEngine.Plugins.UserGroupMembershipPlugin={getCheck:function(){return{class:"OCA\\WorkflowEngine\\Check\\UserGroupMembership",name:t("workflowengine","User group membership"),operators:[{operator:"is",name:t("workflowengine","is member of")},{operator:"!is",name:t("workflowengine","is not member of")}]}},render:function(e,n,t){"OCA\\WorkflowEngine\\Check\\UserGroupMembership"===n.class&&($(e).css("width","400px"),$(e).select2({data:{results:t,text:"displayname"},initSelection:function(e,n){var o=e.val();o&&t.length>0?n({id:o,displayname:t.find(function(e){return e.id===o}).displayname}):o?n({id:o,displayname:o}):n()},formatResult:function(e){return"<span>"+escapeHTML(e.displayname)+"</span>"},formatSelection:function(e){return'<span title="'+escapeHTML(e.id)+'">'+escapeHTML(e.displayname)+"</span>"}}))}},OC.Plugins.register("OCA.WorkflowEngine.CheckPlugins",OCA.WorkflowEngine.Plugins.UserGroupMembershipPlugin)}]);
  22. //# sourceMappingURL=workflowengine.js.map