diff --git a/assets/dist/scripts/charcoal.admin.js b/assets/dist/scripts/charcoal.admin.js index db602f9dc0..df73864c68 100644 --- a/assets/dist/scripts/charcoal.admin.js +++ b/assets/dist/scripts/charcoal.admin.js @@ -1340,6 +1340,7 @@ Charcoal.Admin.Widget = function (opts) { if (typeof opts.id === 'string') { this.set_element($('#' + opts.id)); this.set_id(opts.id); + this.widget_id = opts.widget_id || opts.id; } if (typeof opts.type === 'string') { @@ -1363,13 +1364,27 @@ Charcoal.Admin.Widget.prototype.set_opts = function (opts) { return this; }; +/** + * Add option + * @param {String} ident + * @param {Mixed} val + * @return this (chainable) + */ +Charcoal.Admin.Widget.prototype.add_opts = function (ident, val) { + if (typeof ident === 'string') { + this._opts[ident] = val; + } + + return this; +}; + /** * If a ident is specified, the method tries to return * the options pointed out. * If no ident is specified, the method returns * the whole opts object * - * @param {String} ident | falcultative + * @param {String} [ident] * @return {Object|Mixed|false} */ Charcoal.Admin.Widget.prototype.opts = function (ident) { @@ -1497,7 +1512,11 @@ Charcoal.Admin.Widget.prototype.reload = function (callback) { contentType: 'application/json', success: function (response) { if (typeof response.widget_id === 'string') { - that.set_id(response.widget_id); + var wid = response.widget_id; + that.set_id(wid); + that.add_opts('id', wid); + that.add_opts('widget_id', wid); + that.widget_id = wid; that.anim_out(function () { that.element().replaceWith(response.widget_html); that.set_element($('#' + that.id())); @@ -3474,8 +3493,8 @@ Charcoal.Admin.Widget_Table.prototype.bind_events = function () } }).disableSelection(); - $('.js-page-switch').on('click', function (e) { - e.preventDefault(); + $('.js-page-switch', that.table_selector).on('click', function (event) { + event.preventDefault(); var $this = $(this); var page_num = $this.data('page-num'); diff --git a/assets/dist/scripts/charcoal.admin.min.js b/assets/dist/scripts/charcoal.admin.min.js index 88089cb115..398c46d5f2 100644 --- a/assets/dist/scripts/charcoal.admin.min.js +++ b/assets/dist/scripts/charcoal.admin.min.js @@ -1,6 +1,6 @@ -/*! @locomotivemtl/charcoal-admin 27-09-2017 */ +/*! @locomotivemtl/charcoal-admin 05-10-2017 */ -$.fn.enable=function(){return this.each(function(){$(this).removeAttr("disabled").prop("disabled",!1)}),this},$.fn.disable=function(){return this.each(function(){$(this).attr("disabled",!0).prop("disabled",!0)}),this},RegExp.escape||(RegExp.escape=function(a){return a.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&")}),Array.prototype.find||Object.defineProperty(Array.prototype,"find",{value:function(a){if(null==this)throw new TypeError('"this" is null or not defined');if("function"!=typeof a)throw new TypeError("predicate must be a function");for(var b=Object(this),c=b.length>>>0,d=arguments[1],e=0;e1&&(d.forEach(function(a,b){d[b]=a.charAt(0).toUpperCase()+a.slice(1)}),a=d.join("_")),c[b]=a.charAt(0).toUpperCase()+a.slice(1)}),a=b.join("_")},a.parseNumber=function(a){return/^(\-|\+)?([0-9]+(\.[0-9]+)?|Infinity)$/.test(a)?Number(a):a},a.loadScript=function(a,b){this.cache(a,function(b){$.ajax({url:a,dataType:"script",success:b.resolve,error:b.reject})}).then(b)},a.cache=function(a,b,c){return this.cachePool[a]||"function"==typeof b&&(this.cachePool[a]=$.Deferred(function(a){b(a)}).promise()),"function"==typeof this.cachePool[a]?this.cachePool[a].done(c):this.cachePool[a]},a.parseJqXhrArgs=function(){var a={failed:!0,jqXHR:null,textStatus:"",errorThrown:"",response:null};return arguments[2]&&"string"===$.type(arguments[2])?(a.jqXHR=arguments[0]||null,a.textStatus=arguments[1]||null,a.errorThrown=arguments[2]||null,a.response=arguments[3]||a.jqXHR.responseJSON||null,"object"===$.type(a.response)?a.failed=!a.response.success:a.failed=!0):(a.response=arguments[0]||null,a.textStatus=arguments[1]||null,a.jqXHR=arguments[2]||null,a.errorThrown=null,null===a.response&&(a.response=a.jqXHR.responseJSON),"object"===$.type(a.response)?a.failed=!a.response.success:a.failed=!1),a},a}(),function(a,b,c){"use strict";var d=a(b),e=a.Deferred(),f=1,g=function(){this.isReady=!1,this.components={},d.on("ready",a.proxy(this.render,this))};g.prototype.add_property_input=function(a){this.add_component("property_inputs",a)},g.prototype.add_widget=function(a){this.add_component("widgets",a)},g.prototype.add_template=function(a){this.add_component("templates",a)},g.prototype.add_component=function(a,b){var c=Charcoal.Admin.get_object_name(b.type);"function"==typeof Charcoal.Admin[c]?(b.ident=c,this.components[a]=this.components[a]||[],this.components[a].push(b)):console.error("Was not able to store "+c+" in "+a+" sub-array")},g.prototype.get_property_input=function(a){return this.get_component("property_inputs",a)},g.prototype.get_widget=function(a){return this.get_component("widgets",a)},g.prototype.get_template=function(a){return this.get_component("templates",a)},g.prototype.get_component=function(a,b){if(!this.isReady)throw new Error("Components must be rendered.");if(a in this.components)return this.components[a].find(function(a){return a._id===b})},g.prototype.ready=function(a){return e.promise().done(a),this},g.prototype.render=function(){var b=a.Event("render.charcoal.components",{relatedTarget:this});if(d.trigger(b),!b.isDefaultPrevented()){for(var c in this.components){var g=Charcoal;switch(c){case"widgets":g=Charcoal.Admin.Widget;break;case"property_inputs":g=Charcoal.Admin.Property;break;case"templates":g=Charcoal.Admin.Template}for(var h=0,i=this.components[c].length;h0)){e.resolveWith(this);var l=a.Event("rendered.charcoal.components",{relatedTarget:this});return d.trigger(l),this}}},g.prototype.prepare_submit=function(){return this.prepare_inputs(),this.prepare_widgets(),!0},g.prototype.prepare_inputs=function(){var a=void 0!==this.components.property_inputs?this.components.property_inputs:[];if(!a.length)return!0;for(var b,c=a.length,d=0;d=0;h--)d=b.alias[h],g[d]=c;return this},k.prototype.push=function(){var b=arguments[0],c=arguments;this.validContext(b)?c=h.slice.call(arguments,1):b="global";for(var d,e=0;e0},k.prototype.getMessagesMap=function(){if(!this.hasMessages())return{};for(var a,b,c=this.getMessages(),d={},e=0;e"+d[a].join("

")+"

",type:b.type,buttons:c})}return this.empty(),this},k.prototype.call=k.prototype.dispatch,k.prototype.empty=function(){i(),this.actions=[],this.storage=[]},k.prototype.reset=k.prototype.empty;var l=function(a,c){if(b.feedback(),!this.validLevel(a))throw new TypeError("Feedback level required. Must be one of: "+e.join(", "));return this.setLevel(a),this.validMessage(c)&&this.setMessage(c),this};l.createFromObject=function(a){var b=a.level||null,c=a.message||a.msg||null;return b||c?new l(b,c):null},l.prototype={toString:function(){return this.message()},level:function(){return this._level||null},setLevel:function(b){var c=a.type(b);if("string"!==c)throw new TypeError("Feedback level must be a string, received "+c);if(-1===a.inArray(b,e))throw new TypeError('Unsupported feedback level, received "'+b+'". Must be one of: '+e.join(", "));return b in g&&(b=g[b]),this._level=b,this},validLevel:function(b){return"string"===a.type(b)&&a.inArray(b,e)>-1},message:function(){return this._message||null},setMessage:function(b){var c=a.type(b);if("string"!==c)throw new TypeError("Feedback message must be a string, received "+c);return this._message=b,this},validMessage:function(b){return"string"===a.type(b)}},i(),b.Feedback=k,b.FeedbackEntry=l}(jQuery,Charcoal.Admin,document),Charcoal.Admin.Widget=function(a){return this._element=void 0,this._id=void 0,this._type=void 0,this._opts=void 0,a?("string"==typeof a.id&&(this.set_element($("#"+a.id)),this.set_id(a.id)),"string"==typeof a.type&&(this.set_type(a.type),this.widget_type=a.widget_type||a.type),this.set_opts(a),this):this},Charcoal.Admin.Widget.prototype.set_opts=function(a){return this._opts=a,this},Charcoal.Admin.Widget.prototype.opts=function(a){return"string"==typeof a?void 0!==this._opts[a]&&this._opts[a]:this._opts},Charcoal.Admin.Widget.prototype.init=function(){return this},Charcoal.Admin.Widget.prototype.set_id=function(a){this._id=a},Charcoal.Admin.Widget.prototype.id=function(){return this._id},Charcoal.Admin.Widget.prototype.set_type=function(a){this._type=a},Charcoal.Admin.Widget.prototype.type=function(){return this._type},Charcoal.Admin.Widget.prototype.set_element=function(a){return this._element=a,this},Charcoal.Admin.Widget.prototype.element=function(){return this._element},Charcoal.Admin.Widget.prototype.widget_options=function(){return this.opts()},Charcoal.Admin.Widget.prototype.widget_type=function(){return this.type()},Charcoal.Admin.Widget.prototype.save=function(){return!0},Charcoal.Admin.Widget.prototype.anim_out=function(a){return"function"!=typeof a&&(a=function(){}),this.element().fadeOut(400,a),this},Charcoal.Admin.Widget.prototype.reload=function(a){var b=this,c=Charcoal.Admin.admin_url()+"widget/load",d={widget_type:b.widget_type||b.type(),widget_options:b.widget_options()};$.ajax({type:"POST",url:c,data:JSON.stringify(d),dataType:"json",contentType:"application/json",success:function(c){"string"==typeof c.widget_id&&(b.set_id(c.widget_id),b.anim_out(function(){b.element().replaceWith(c.widget_html),b.set_element($("#"+b.id())),b.element().hide().fadeIn(),b.init()})),"function"==typeof a&&a.call(b,c)}})},Charcoal.Admin.Widget.prototype.dialog=function(a,b){var c=a.title||"",d=a.type||BootstrapDialog.TYPE_DEFAULT,e=a.size||BootstrapDialog.SIZE_NORMAL,f=a.cssClass||"",g=a.showHeader||!0,h=a.showFooter||!0,i=a.dialog_options||{};delete a.title,delete a.type,delete a.size,delete a.cssClass,delete a.dialog_options;var j={title:c,type:d,size:e,cssClass:f,nl2br:!1,showHeader:g,showFooter:h,onshown:function(){Charcoal.Admin.manager().render()}},k=$.extend({},j,i),l='';return k.message=function(c){var d,e=Charcoal.Admin.admin_url()+"widget/load",f=a,i=$(l.replaceMap({"{type}":"warning","{text}":widgetL10n.loading}));return g||c.getModalHeader().addClass("hidden"),h||c.getModalFooter().addClass("hidden"),c.getModalBody().on("click.charcoal.bs.dialog",'[data-dismiss="dialog"]',{dialog:c},function(a){a.data.dialog.close()}),d=$.ajax({method:"POST",url:e,data:f,dataType:"json"}),d.then(function(a,b,c){return a&&a.success?$.Deferred().resolve(a,b,c):a.feedbacks?$.Deferred().reject(c,b,a.feedbacks):$.Deferred().reject(c,b,widgetL10n.loadingFailed)}).done(function(a){c.setMessage(a.widget_html),"function"==typeof b&&b(a),$('[data-toggle="tooltip"]',c.getModalBody()).tooltip()}).fail(function(a,b,d){c.setType(BootstrapDialog.TYPE_DANGER),c.setMessage(widgetL10n.loadingFailed);var e="";"string"===$.type(d)&&a.responseJSON&&a.responseJSON.feedbacks&&(d=a.responseJSON.feedbacks),$.isArray(d)?$.each(d,function(a,b){b.message&&("error"===b.level&&(b.level="danger"),e+=l.replaceMap({"{type}":b.level,"{text}":b.message}))}):"string"===$.type(d)&&(e=l.replaceMap({"{type}":"danger","{text}":d})),e&&c.setMessage(e),$('[data-toggle="tooltip"]',c.getModalBody()).tooltip()}),i},new BootstrapDialog.show(k)},Charcoal.Admin.Widget.prototype.confirm=function(a,b,c){var d={type:BootstrapDialog.TYPE_DANGER,callback:function(a){a?"function"==typeof b&&b():"function"==typeof c&&c()}},e=$.extend(d,a);BootstrapDialog.confirm(e)},Charcoal.Admin.Widget_Attachment=function(){this.glyphs={embed:"glyphicon-blackboard",video:"glyphicon-film",image:"glyphicon-picture",file:"glyphicon-file",link:"glyphicon-link",text:"glyphicon-font",gallery:"glyphicon-duplicate",container:"glyphicon-list",accordion:"glyphicon-list"};var a=this;return $(document).on("switch_language.charcoal",function(){var b=a.opts();b.widget_options.lang=Charcoal.Admin.lang(),a.set_opts(b),a.reload()}),this.dirty=!1,this},Charcoal.Admin.Widget_Attachment.prototype=Object.create(Charcoal.Admin.Widget.prototype),Charcoal.Admin.Widget_Attachment.prototype.constructor=Charcoal.Admin.Widget_Attachment,Charcoal.Admin.Widget_Attachment.prototype.parent=Charcoal.Admin.Widget.prototype,Charcoal.Admin.Widget_Attachment.prototype.init=function(){var a=this.element().find(".js-attachment-sortable > .js-grid-container");return a.length&&(this.element().on("hidden.bs.collapse",'[data-toggle="collapse"]',function(){a.sortable("refreshPositions")}),a.sortable({handle:'[draggable="true"]',placeholder:"panel c-attachment_placeholder",start:function(a,b){b.item.children(".panel-heading").find('[data-toggle="collapse"]').hasClass("collapsed")||b.item.children(".panel-collapse").collapse("hide")}}).disableSelection()),this.listeners(),this},Charcoal.Admin.Widget_Attachment.prototype.is_dirty=function(){return this.dirty},Charcoal.Admin.Widget_Attachment.prototype.set_dirty_state=function(a){return this.dirty=a,this},Charcoal.Admin.Widget_Attachment.prototype.listeners=function(){var a=this,b=this.element().find(".c-attachments_container > .js-grid-container");this.element().off("click").on("click.charcoal.attachments",".js-attachments-collapse",function(){var a=b.children(".js-attachment");b.hasClass("js-attachment-preview-only")&&a.children(".panel-heading.sr-only").removeClass("sr-only").addClass("sr-only-off"),a.children(".panel-collapse.in").collapse("hide")}).on("click.charcoal.attachments",".js-attachments-expand",function(){var a=b.children(".js-attachment");b.hasClass("js-attachment-preview-only")&&a.children(".panel-heading.sr-only-off").removeClass("sr-only-off").addClass("sr-only"),a.children(".panel-collapse:not(.in)").collapse("show")}).on("click.charcoal.attachments",".js-add-attachment",function(b){b.preventDefault();var c=$(this).data("type");if(!c)return!1;var d=$(this).data("id");if(d)a.add({id:d,type:c}),a.join(function(){a.reload()});else{var e=$(this).data("title")||attachmentWidgetL10n.editObject,f=$(this).data("skip-form");a.create_attachment(c,0,null,{title:e,skipForm:f},function(b){b.success&&(b.obj.id=b.obj_id,a.add(b.obj),a.join(function(){a.reload()}))})}}).on("click.charcoal.attachments",".js-attachment-actions a",function(b){var c=$(this);if(c.data("action")){b.preventDefault();switch(c.data("action")){case"edit":var d=c.data("type"),e=c.data("id");if(!d||!e)break;var f=c.data("title")||attachmentWidgetL10n.editObject;a.create_attachment(d,e,null,{title:f},function(b){b.success&&a.reload()});break;case"delete":if(!c.data("id"))break;a.confirm({title:attachmentWidgetL10n.confirmRemoval,message:commonL10n.confirmAction,btnOKLabel:commonL10n.removeObject,callback:function(b){b&&a.remove_join(c.data("id"),function(){a.reload()})}});break;case"add-object":var g=c.data("title"),h=c.data("attachment"),i=c.data("type"),j=c.data("id"),k=c.data("group"),l=c.data("skip-form"),m={id:j,type:i,group:k,skipForm:l};a.create_attachment(h,0,{title:g},m,function(b){b.success&&a.add_object_to_container({id:b.obj_id,type:b.obj.type},m)})}}})},Charcoal.Admin.Widget_Attachment.prototype.select_attachment=function(a){if(!a.data("id")||!a.data("type"))return this},Charcoal.Admin.Widget_Attachment.prototype.create_attachment=function(a,b,c,d,e){b||(b=0),d||(d={});var f=this;if(!c){var g=f.opts();c={obj_type:g.data.obj_type,obj_id:g.data.obj_id,group:g.data.group}}if(d.skipForm)return this.xhr=$.ajax({type:"POST",url:"object/save",data:{obj_type:a,obj_id:b,pivot:c}}),this.xhr.done(function(a){a.feedbacks&&Charcoal.Admin.feedback(a.feedbacks).dispatch(),e(a)}),void Charcoal.Admin.manager().render();var h={size:BootstrapDialog.SIZE_WIDE,cssClass:"-quick-form",widget_type:"charcoal/admin/widget/quickForm",widget_options:{obj_type:a,obj_id:b,form_data:{pivot:c}}},i={},j=$.extend({},h,d,i),k=this.dialog(j,function(c){if(c.success){if(!c.widget_id)return!1;Charcoal.Admin.manager().add_widget({id:c.widget_id,type:"charcoal/admin/widget/quick-form",data:{obj_type:a},obj_id:b,save_callback:function(a){e(a),k.close()}}),Charcoal.Admin.manager().render()}})},Charcoal.Admin.Widget_Attachment.prototype.add_object_to_container=function(a,b,c){var d=this,e={obj_type:b.type,obj_id:b.id,attachments:[{attachment_id:a.id,attachment_type:a.type,position:0}],group:c||b.group||""};$.post("add-join",e,function(){d.reload()},"json")},Charcoal.Admin.Widget_Attachment.prototype.add=function(a){if(!a)return!1;this.set_dirty_state(!0);var b=this.element().find(".js-attachment-template").clone();return b.find(".js-attachment").data("id",a.id).data("type",a.type),this.element().find(".c-attachments_container > .js-grid-container").append(b),this},Charcoal.Admin.Widget_Attachment.prototype.save=function(){if(this.is_dirty())return!1;this.join()},Charcoal.Admin.Widget_Attachment.prototype.join=function(a){var b=this,c=b.opts(),d={obj_type:c.data.obj_type,obj_id:c.data.obj_id,attachments:[],group:c.data.group};this.element().find(".c-attachments_container").find(".js-attachment").each(function(a){var b=$(this),c=b.data("id"),e=b.data("type");d.attachments.push({attachment_id:c,attachment_type:e,position:a})}),$.post("join",d,function(){"function"==typeof a&&a(),b.set_dirty_state(!1)},"json")},Charcoal.Admin.Widget_Attachment.prototype.remove_join=function(a,b){if(!a)return!1;var c=this,d=c.opts(),e={obj_type:d.data.obj_type,obj_id:d.data.obj_id,attachment_id:a,group:d.data.group};$.post("remove-join",e,function(){"function"==typeof b&&b(),c.set_dirty_state(!1)},"json")},Charcoal.Admin.Widget_Attachment.prototype.widget_options=function(){return this.opts("widget_options")},Charcoal.Admin.Widget_Form=function(a){this.widget_type="charcoal/admin/widget/form",this.widget_id=null,this.obj_type=null,this.obj_id=null,this.save_action="object/save",this.update_action="object/update",this.form_selector=null,this.form_working=!1,this.submitted_via=null,this.suppress_feedback=!1,this.is_new_object=!1,this.xhr=null;var b=Charcoal.Admin.queryParams();"tab_ident"in b&&$('.js-group-tabs[data-tab-ident="'+b.tab_ident+'"]').tab("show");var c=$("[data-lang]:not(.hidden)").data("lang");c&&Charcoal.Admin.setLang(c),this.set_properties(a).bind_events()},Charcoal.Admin.Widget_Form.prototype=Object.create(Charcoal.Admin.Widget.prototype),Charcoal.Admin.Widget_Form.prototype.constructor=Charcoal.Admin.Widget_Form,Charcoal.Admin.Widget_Form.prototype.parent=Charcoal.Admin.Widget.prototype,Charcoal.Admin.Widget_Form.prototype.set_properties=function(a){return this.widget_id=a.id||this.widget_id,this.obj_type=a.data.obj_type||this.obj_type,this.obj_id=Charcoal.Admin.parseNumber(a.data.obj_id||this.obj_id),this.form_selector=a.data.form_selector||this.form_selector,this.isTab=a.data.tab,this},Charcoal.Admin.Widget_Form.prototype.bind_events=function(){var a=this,b=$(".c-form-sidebar",this.form_selector);$(a.form_selector).on("submit.charcoal.form",function(b){console.log("form.submit",b),b.preventDefault(),a.submit_form(this)}).find(":submit").on("click.charcoal.form",function(b){console.log("click.submit",b),a.submitted_via=this}),$(".js-obj-delete",b).on("click.charcoal.form",function(b){b.preventDefault(),a.delete_object(this)}),$(".js-reset-form",b).on("click.charcoal.form",function(b){b.preventDefault(),$(a.form_selector)[0].reset()}),$(".js-lang-switch button",b).on("click.charcoal.form",function(b){b.preventDefault();var c=$(this),d=c.attr("data-lang-switch");a.switch_language(d)})},Charcoal.Admin.Widget_Form.prototype.submit_form=function(a){if(!this.form_working){this.form_working=!0,this.is_new_object=!this.obj_id;var b,c,d;if(c=$(a),b=c.find('[type="submit"]'),b.prop("disabled"))return!1;Charcoal.Admin.manager().prepare_submit(),d=new FormData(a),this.submitted_via&&this.submitted_via.name&&d.append(this.submitted_via.name,this.submitted_via.value||!0),this.disable_form(c,b),this.xhr=$.ajax({type:"POST",url:this.request_url(),data:d,dataType:"json",processData:!1,contentType:!1}),this.xhr.then($.proxy(this.request_done,this,c,b)).done($.proxy(this.request_success,this,c,b)).fail($.proxy(this.request_failed,this,c,b)).always($.proxy(this.request_complete,this,c,b))}},Charcoal.Admin.Widget_Form.prototype.request_done=function(a,b,c,d,e){return c&&c.success?$.Deferred().resolve(c,d,e):c.feedbacks?$.Deferred().reject(e,d,c.feedbacks):$.Deferred().reject(e,d,commonL10n.errorOccurred)},Charcoal.Admin.Widget_Form.prototype.request_success=function(a,b,c){if(c.feedbacks&&Charcoal.Admin.feedback(c.feedbacks),c.next_url&&Charcoal.Admin.feedback().add_action({label:commonL10n.continue,callback:function(){window.location.href=Charcoal.Admin.admin_url()+c.next_url}}),this.is_new_object)if(this.suppress_feedback=!0,c.next_url)window.location.href=Charcoal.Admin.admin_url()+c.next_url;else{var d=new URLSearchParams(window.location.search);window.location.href=Charcoal.Admin.admin_url()+"object/edit?"+(d.has("main_menu")?"main_menu="+d.get("main_menu")+"&":"")+(d.has("sidemenu")?"sidemenu="+d.get("sidemenu")+"&":"")+"obj_type="+this.obj_type+"&obj_id="+c.obj_id}},Charcoal.Admin.Widget_Form.prototype.request_failed=function(a,b,c,d,e){if(c.responseJSON&&c.responseJSON.feedbacks)Charcoal.Admin.feedback(c.responseJSON.feedbacks);else{var f=this.is_new_object?formWidgetL10n.createFailed:formWidgetL10n.updateFailed,g=e||commonL10n.errorOccurred;Charcoal.Admin.feedback([{message:commonL10n.errorTemplate.replaceMap({"[[ errorMessage ]]":f,"[[ errorThrown ]]":g}),level:"error"}])}},Charcoal.Admin.Widget_Form.prototype.request_complete=function(a,b){this.suppress_feedback||(Charcoal.Admin.feedback().dispatch(),this.enable_form(a,b)),this.submitted_via=null,this.form_working=this.is_new_object=this.suppress_feedback=!1},Charcoal.Admin.Widget_Form.prototype.disable_form=function(a,b){return a&&a.prop("disabled",!0),b&&b.prop("disabled",!0),this.submitted_via&&this.disable_button(this.submitted_via),this},Charcoal.Admin.Widget_Form.prototype.enable_form=function(a,b){return a&&a.prop("disabled",!1),b&&b.prop("disabled",!1),this.submitted_via&&this.enable_button(this.submitted_via),this},Charcoal.Admin.Widget_Form.prototype.disable_button=function(a){return a instanceof jQuery||(a=$(a)),a.prop("disabled",!0).children(".glyphicon").removeClass("hidden").next(".btn-label").addClass("sr-only"),this},Charcoal.Admin.Widget_Form.prototype.enable_button=function(a){return a instanceof jQuery||(a=$(a)),a.prop("disabled",!1).children(".glyphicon").addClass("hidden").next(".btn-label").removeClass("sr-only"),this},Charcoal.Admin.Widget_Form.prototype.request_url=function(){return this.is_new_object?Charcoal.Admin.admin_url()+this.save_action:Charcoal.Admin.admin_url()+this.update_action},Charcoal.Admin.Widget_Form.prototype.delete_object=function(){var a=this,b=new URLSearchParams(window.location.search),c=Charcoal.Admin.admin_url()+"object/collection?"+(b.has("main_menu")?"main_menu="+b.get("main_menu")+"&":"")+(b.has("sidemenu")?"sidemenu="+b.get("sidemenu")+"&":"")+"obj_type="+this.obj_type;BootstrapDialog.confirm({title:formWidgetL10n.confirmDeletion,type:BootstrapDialog.TYPE_DANGER,message:$("

"+commonL10n.confirmAction+"

"+commonL10n.cantUndo+"

"),btnOKLabel:commonL10n.delete,callback:function(b){if(b){var d=Charcoal.Admin.admin_url()+"object/delete",e={obj_type:a.obj_type,obj_id:a.obj_id};$.ajax({method:"POST",url:d,data:e,dataType:"json"}).done(function(a){a.success?window.location.href=c:window.alert(formWidgetL10n.deleteFailed)})}}})},Charcoal.Admin.Widget_Form.prototype.switch_language=function(a){Charcoal.Admin.lang()!==a&&(Charcoal.Admin.setLang(a),$("[data-lang][data-lang!="+a+"]").addClass("hidden"),$("[data-lang][data-lang="+a+"]").removeClass("hidden"),$("[data-lang-switch][data-lang-switch!="+a+"]").removeClass("btn-info").addClass("btn-default"),$("[data-lang-switch][data-lang-switch="+a+"]").removeClass("btn-default").addClass("btn-info"),$(document).triggerHandler({type:"switch_language.charcoal"}))},Charcoal.Admin.Widget_Map=function(){return this._controller=void 0,this.widget_type="charcoal/admin/widget/map",this},Charcoal.Admin.Widget_Map.prototype=Object.create(Charcoal.Admin.Widget.prototype),Charcoal.Admin.Widget_Map.prototype.constructor=Charcoal.Admin.Widget_Map,Charcoal.Admin.Widget_Map.prototype.parent=Charcoal.Admin.Widget.prototype,Charcoal.Admin.Widget_Map.prototype.init=function(){var a=this;return"undefined"==typeof google?(window._tmp_google_onload_function=function(){a.activate_map()},$.getScript("https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false&language=fr&callback=_tmp_google_onload_function",function(){})):a.activate_map(),this},Charcoal.Admin.Widget_Map.prototype.activate_map=function(){var a={strokeColor:"#000000",strokeOpacity:.8,strokeWeight:3,fillColor:"#ffffff",fillOpacity:.35,hover:{strokeColor:"#000000",strokeOpacity:1,strokeWeight:2,fillColor:"#ffffff",fillOpacity:.5},focused:{fillOpacity:.8}},b={default_styles:a,use_clusterer:!1,map:{center:{x:this.opts("coords")[0],y:this.opts("coords")[1]},zoom:14,mapType:"roadmap",coordsType:"inpage",map_mode:"default"},places:{first:{type:"marker",coords:this.coords()}}};this._controller=new window.BB.gmap.controller(this.element().find(".js-map-maker-map").get(0),b),this.controller().set_styles([{featureType:"poi",elementType:"all",stylers:[{visibility:"off"}]}]),this.controller().remove_focus(),this.controller().init()},Charcoal.Admin.Widget_Map.prototype.controller=function(){return this._controller},Charcoal.Admin.Widget_Map.prototype.coords=function(){return this.opts("coords")},Charcoal.Admin.Widget_Quick_Form=function(a){return this.widget_type="charcoal/admin/widget/quick-form",this.save_callback=a.save_callback||"",this.cancel_callback=a.cancel_callback||"",this.save_action=a.save_action||"object/save",this.update_action=a.update_action||"object/update",this.extra_form_data=a.extra_form_data||{},this.form_working=!1,this.suppress_feedback=a.suppress_feedback||!1,this.is_new_object=!1,this.xhr=null,this.obj_id=Charcoal.Admin.parseNumber(a.obj_id)||0,this},Charcoal.Admin.Widget_Quick_Form.prototype=Object.create(Charcoal.Admin.Widget.prototype),Charcoal.Admin.Widget_Quick_Form.prototype.constructor=Charcoal.Admin.Widget_Quick_Form,Charcoal.Admin.Widget_Quick_Form.prototype.parent=Charcoal.Admin.Widget.prototype,Charcoal.Admin.Widget_Quick_Form.prototype.init=function(){this.bind_events()},Charcoal.Admin.Widget_Quick_Form.prototype.bind_events=function(){var a=this;$(document).on("submit","#"+this.id(),function(b){b.preventDefault(),a.submit_form(this)}),$("#"+this.id()).on("click.charcoal.bs.dialog",'[data-dismiss="dialog"]',function(b){$.isFunction(a.cancel_callback)&&a.cancel_callback(b)})},Charcoal.Admin.Widget_Quick_Form.prototype.submit_form=function(a){if(!this.form_working){this.form_working=!0,this.is_new_object=!this.obj_id;var b,c,d;if(c=$(a),b=c.find('[type="submit"]'),b.prop("disabled"))return!1;Charcoal.Admin.manager().prepare_submit(),d=new FormData(a),this.disable_form(c,b);var e=this.extra_form_data;for(var f in e)e.hasOwnProperty(f)&&d.append(f,e[f]);this.xhr=$.ajax({type:"POST",url:this.request_url(),data:d,dataType:"json",processData:!1,contentType:!1}),this.xhr.then($.proxy(this.request_done,this,c,b)).done($.proxy(this.request_success,this,c,b)).fail($.proxy(this.request_failed,this,c,b)).always($.proxy(this.request_complete,this,c,b))}},Charcoal.Admin.Widget_Quick_Form.prototype.disable_form=Charcoal.Admin.Widget_Form.prototype.disable_form,Charcoal.Admin.Widget_Quick_Form.prototype.enable_form=Charcoal.Admin.Widget_Form.prototype.enable_form,Charcoal.Admin.Widget_Quick_Form.prototype.request_url=Charcoal.Admin.Widget_Form.prototype.request_url,Charcoal.Admin.Widget_Quick_Form.prototype.request_done=Charcoal.Admin.Widget_Form.prototype.request_done,Charcoal.Admin.Widget_Quick_Form.prototype.request_failed=Charcoal.Admin.Widget_Form.prototype.request_failed,Charcoal.Admin.Widget_Quick_Form.prototype.request_complete=Charcoal.Admin.Widget_Form.prototype.request_complete,Charcoal.Admin.Widget_Quick_Form.prototype.request_success=function(a,b,c){c.feedbacks&&!this.suppress_feedback&&Charcoal.Admin.feedback(c.feedbacks),c.next_url&&Charcoal.Admin.feedback().add_action({label:commonL10n.continue,callback:function(){window.location.href=Charcoal.Admin.admin_url()+c.next_url}}),this.enable_form(a,b),this.form_working=!1,"function"==typeof this.save_callback&&this.save_callback(c)},Charcoal.Admin.Widget_Relation=function(){return this.dirty=!1,this},Charcoal.Admin.Widget_Relation.prototype=Object.create(Charcoal.Admin.Widget.prototype), -Charcoal.Admin.Widget_Relation.prototype.constructor=Charcoal.Admin.Widget_Relation,Charcoal.Admin.Widget_Relation.prototype.parent=Charcoal.Admin.Widget.prototype,Charcoal.Admin.Widget_Relation.prototype.init=function(){if("function"!=typeof $.fn.sortable){return Charcoal.Admin.loadScript("https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js",this.init.bind(this)),this}var a=this.element().find(".js-relation-sortable .js-grid-container");return this.element().on("hidden.bs.collapse",'[data-toggle="collapse"]',function(){a.sortable("refreshPositions")}),a.sortable({handle:'[draggable="true"]',placeholder:"panel c-attachment_placeholder",start:function(a,b){b.item.children(".panel-heading").find('[data-toggle="collapse"]').hasClass("collapsed")||b.item.children(".panel-collapse").collapse("hide")}}).disableSelection(),this.listeners(),this},Charcoal.Admin.Widget_Relation.prototype.is_dirty=function(){return this.dirty},Charcoal.Admin.Widget_Relation.prototype.set_dirty_state=function(a){return this.dirty=a,this},Charcoal.Admin.Widget_Relation.prototype.listeners=function(){var a=this;this.element().off("click").on("click.charcoal.relation",".js-add-relation",function(b){b.preventDefault();var c=$(this).data("type");if(!c)return!1;var d=$(this).data("id");if(d)a.add({id:d,type:c}),a.create_relation(function(){a.reload()});else{var e=$(this).data("title")||relationWidgetL10n.editObject;a.create_relation_dialog({title:e,widget_options:{form_data:{target_object_type:c,target_object_id:null}}},function(b){b.success&&(b.obj.id=b.obj_id,a.add(b.obj),a.create_relation(function(){a.reload()}))})}}).on("click.charcoal.relation",".js-relation-actions a",function(b){var c=$(this);if(c.data("action")){b.preventDefault();switch(c.data("action")){case"edit":var d=c.data("type"),e=c.data("id");if(!d||!e)break;var f=c.data("title")||relationWidgetL10n.editObject;a.create_relation_dialog({title:f,widget_options:{form_data:{target_object_type:d,target_object_id:null}}},function(b){b.success&&a.reload()});break;case"unlink":if(!c.data("id"))break;a.confirm({title:relationWidgetL10n.confirmRemoval,message:commonL10n.confirmAction,btnOKLabel:commonL10n.removeObject,callback:function(b){b&&a.remove_relation(c.data("id"),function(){a.reload()})}})}}})},Charcoal.Admin.Widget_Relation.prototype.create_relation_dialog=function(a,b){a=a||{};var c=this.opts().data,d={size:BootstrapDialog.SIZE_WIDE,cssClass:"-quick-form",widget_type:"charcoal/admin/widget/quickForm",widget_options:{obj_type:"charcoal/relation/pivot",obj_id:0,form_data:{group:c.group,source_object_type:c.obj_type,source_object_id:c.obj_id,target_object_type:"",target_object_id:0}}},e={},f=$.extend(!0,{},d,a,e),g=this.dialog(f,function(a){if(a.success){if(!a.widget_id)return!1;Charcoal.Admin.manager().add_widget({id:a.widget_id,type:"charcoal/admin/widget/quick-form",data:{obj_type:f.widget_options.type},obj_id:f.widget_options.id,save_callback:function(a){b(a),g.close()}}),Charcoal.Admin.manager().render()}})},Charcoal.Admin.Widget_Relation.prototype.add=function(a){if(!a)return!1;this.set_dirty_state(!0);var b=this.element().find(".js-relation-template").clone();return b.find(".js-relation").attr({"data-id":a.target_object_id,"data-type":a.target_object_type}),this.element().find(".js-relation-sortable").find(".js-grid-container").append(b),this},Charcoal.Admin.Widget_Relation.prototype.save=function(){if(this.is_dirty())return!1;this.create_relation()},Charcoal.Admin.Widget_Relation.prototype.create_relation=function(a){var b=this,c=b.opts(),d={obj_type:c.data.obj_type,obj_id:c.data.obj_id,group:c.data.group,pivots:[]};this.element().find(".js-relation-container").find(".js-relation").each(function(a){var b=$(this),c=b.attr("data-id"),e=b.attr("data-type");d.pivots.push({target_object_id:c,target_object_type:e,position:a})}),$.post("relation/link",d,function(){"function"==typeof a&&a(),b.set_dirty_state(!1)},"json")},Charcoal.Admin.Widget_Relation.prototype.remove_relation=function(a,b){if(!a)return!1;var c=this,d={pivot_id:a};$.post("relation/unlink",d,function(){"function"==typeof b&&b(),c.set_dirty_state(!1)},"json")},Charcoal.Admin.Widget_Relation.prototype.widget_options=function(){return this.opts("widget_options")},Charcoal.Admin.Widget_Search=function(a){return this._elem=void 0,!!a&&(void 0!==a.id&&(this.set_element($("#"+a.id)),"object"==typeof a.data&&(this.opts=a,this)))},Charcoal.Admin.Widget_Search.prototype=Object.create(Charcoal.Admin.Widget.prototype),Charcoal.Admin.Widget_Search.prototype.constructor=Charcoal.Admin.Widget_Search,Charcoal.Admin.Widget_Search.prototype.parent=Charcoal.Admin.Widget.prototype,Charcoal.Admin.Widget_Search.prototype.set_remote_widget=function(){},Charcoal.Admin.Widget_Search.prototype.init=function(){var a=this.element(),b=this;a.on("click",".js-search",function(a){a.preventDefault(),b.submit()}),a.on("click",".js-undo",function(a){a.preventDefault(),b.undo()})},Charcoal.Admin.Widget_Search.prototype.submit=function(){for(var a=Charcoal.Admin.manager(),b=a.components.widgets,c=0,d=b.length;c"+widgetL10n.loading+"");return a.getModalBody().on("click.charcoal.bs.dialog",'[data-dismiss="dialog"]',{dialog:a},function(a){a.data.dialog.close()}),$.ajax({method:"POST",url:b,data:c,dataType:"json"}).done(function(b){b.success?a.setMessage(b.widget_html):(a.setType(BootstrapDialog.TYPE_DANGER),a.setMessage(commonL10n.errorOccurred))}),d}})},Charcoal.Admin.Widget_Table.Table_Row=function(a,b){this.widget_table=a,this.element=b,this.obj_id=this.element.getAttribute("data-id"),this.obj_type=this.widget_table.obj_type,this.load_url=Charcoal.Admin.admin_url()+"widget/load",this.inline_url=Charcoal.Admin.admin_url()+"widget/table/inline",this.delete_url=Charcoal.Admin.admin_url()+"object/delete",this.bind_events()},Charcoal.Admin.Widget_Table.Table_Row.prototype.bind_events=function(){var a=this;$(".js-obj-quick-edit",a.element).on("click",function(b){b.preventDefault(),a.quick_edit()}),$(".js-obj-inline-edit",a.element).on("click",function(b){b.preventDefault(),a.inline_edit()}),$(".js-obj-delete",a.element).on("click",function(b){b.preventDefault(),a.delete_object()})},Charcoal.Admin.Widget_Table.Table_Row.prototype.quick_edit=function(){var a={widget_type:"charcoal/admin/widget/objectForm",widget_options:{obj_type:this.obj_type,obj_id:this.obj_id}};$.post(this.load_url,a,function(a){var b=BootstrapDialog.show({title:tableWidgetL10n.quickEdit,message:"…",nl2br:!1});b.getModalBody().on("click.charcoal.bs.dialog",'[data-dismiss="dialog"]',{dialog:b},function(a){a.data.dialog.close()}),a.success?b.setMessage(a.widget_html):(b.setType(BootstrapDialog.TYPE_DANGER),b.setMessage(commonL10n.errorOccurred))},"json")},Charcoal.Admin.Widget_Table.Table_Row.prototype.inline_edit=function(){var a=this,b={obj_type:a.obj_type,obj_id:a.obj_id};$.post(a.inline_url,b,function(b){if(b.success){var c,d=b.properties;for(c in d){$(a.element).find(".property-"+c).html(d[c])}}},"json")},Charcoal.Admin.Widget_Table.Table_Row.prototype.delete_object=function(){var a=this;BootstrapDialog.confirm({title:tableWidgetL10n.confirmDeletion,type:BootstrapDialog.TYPE_DANGER,message:$("

"+commonL10n.confirmAction+"

"+commonL10n.cantUndo+"

"),btnOKLabel:commonL10n.delete,callback:function(b){if(b){var c=a.delete_url,d={obj_type:a.obj_type,obj_id:a.obj_id};$.ajax({method:"POST",url:c,data:d,dataType:"json"}).done(function(b){b.success?$(a.element).remove():window.alert(tableWidgetL10n.deleteFailed)})}}})},Charcoal.Admin.Property=function(a){return this._ident=void 0,this._val=void 0,this._type=void 0,this._input_type=void 0,"string"==typeof a.ident&&this.set_ident(a.ident),void 0!==a.val&&this.set_val(a.val),void 0!==a.type&&this.set_type(a.type),void 0!==a.input_type&&this.set_input_type(a.input_type),this.data=a,this},Charcoal.Admin.Property.prototype.set_ident=function(a){this._ident=a},Charcoal.Admin.Property.prototype.set_val=function(a){this._val=a},Charcoal.Admin.Property.prototype.set_type=function(a){this._type=a},Charcoal.Admin.Property.prototype.set_input_type=function(a){this._input_type=a},Charcoal.Admin.Property.prototype.ident=function(){return this._ident},Charcoal.Admin.Property.prototype.val=function(){return this._val},Charcoal.Admin.Property.prototype.type=function(){return this._type},Charcoal.Admin.Property.prototype.input_type=function(){return this._input_type},Charcoal.Admin.Property.prototype.element=function(){if(!this._element){if(!this.data.id)return!1;this._element=$("#"+this.data.id)}return this._element},Charcoal.Admin.Property.prototype.validate=function(){},Charcoal.Admin.Property.prototype.save=function(){return this},Charcoal.Admin.Property.prototype.error=function(a){window.console.error(a)},Charcoal.Admin.Property_Input_Audio=function(a){a.input_type="charcoal/admin/property/input/audio",Charcoal.Admin.Property.call(this,a),this.text_properties={},this.recording_properties={},this.file_properties={},this.initialized_types=[],this.active_pane=a.data.active_pane||"text",this._recorder=void 0,this.init()},Charcoal.Admin.Property_Input_Audio.prototype=Object.create(Charcoal.Admin.Property.prototype),Charcoal.Admin.Property_Input_Audio.prototype.constructor=Charcoal.Admin.Property_Input_Audio,Charcoal.Admin.Property_Input_Audio.prototype.parent=Charcoal.Admin.Property.prototype,Charcoal.Admin.Property_Input_Audio.prototype.init=function(){var a=this.data;void 0===a.id&&console.error("Missing ID"),this.text_properties.$voice_message=$(".js-text-voice-message",this.element()),this.recording_properties.audio_context=null,this.recording_properties.audio_recorder=null,this.recording_properties.animation_frame=null,this.recording_properties.analyser_context=null,this.recording_properties.canvas_width=0,this.recording_properties.canvas_height=0,this.recording_properties.recording_index=0,this.recording_properties.current_recording=null,this.recording_properties.audio_player=null,this.recording_properties.hidden_input_id=a.data.hidden_input_id,this.recording_properties.$analyser_canvas=$(".js-recording-analyser",this.element()),this.recording_properties.$waves_canvas=$(".js-recording-waves",this.element()),this.recording_properties.record_button_class="js-recording-record",this.recording_properties.$record_button=$(".js-recording-record",this.element()),this.recording_properties.stop_button_class="js-recording-stop",this.recording_properties.$stop_button=$(".js-recording-stop",this.element()),this.recording_properties.playback_button_class="js-recording-playback",this.recording_properties.$playback_button=$(".js-recording-playback",this.element()),this.recording_properties.reset_button_class="js-recording-reset",this.recording_properties.$reset_button=$(".js-recording-reset",this.element()),this.recording_properties.$timer=$(".js-recording-timer",this.element()),this.file_properties.$file_audio=$(".js-file-audio",this.element()),this.file_properties.$file_reset=$(".js-file-reset",this.element()),this.file_properties.$file_input=$(".js-file-input",this.element()),this.file_properties.$file_input_hiden=$(".js-file-input-hidden",this.element()),this.file_properties.reset_button_class="js-file-reset",this.set_nav(this.active_pane).bind_nav_controls()},Charcoal.Admin.Property_Input_Audio.prototype.bind_nav_controls=function(){var a=this;this.element().on("click",".js-toggle-pane",function(){var b=$(this);a.set_nav(b.attr("data-pane"))})},Charcoal.Admin.Property_Input_Audio.prototype.set_nav=function(a){if(a){var b=$(".js-toggle-pane"),c=$(".js-pane"),d=c.filter('[data-pane="'+a+'"]');if(!d.hasClass("-active")){var e=b.filter('[data-pane="'+a+'"]');b.removeClass("-active"),e.addClass("-active"),c.removeClass("-active"),c.addClass("hidden"),d.removeClass("hidden"),d.addClass("-active"),this.prepare_pane(a)}}return this},Charcoal.Admin.Property_Input_Audio.prototype.prepare_pane=function(a){var b="init_"+a;"function"==typeof Charcoal.Admin.Property_Input_Audio.prototype[b]&&this[b]()},Charcoal.Admin.Property_Input_Audio.prototype.init_text=function(){if(-1===this.initialized_types.indexOf("text")){this.initialized_types.push("text");var a=this.text_properties.$voice_message.val();a=this.text_strip_tags(a),this.text_properties.$voice_message.val(a)}},Charcoal.Admin.Property_Input_Audio.prototype.text_strip_tags=function(a,b){b=((String(b)||"").toLowerCase().match(/<[a-z][a-z0-9]*>/g)||[]).join("");var c=/<\/?([a-z][a-z0-9]*)\b[^>]*>/gi,d=/|<\?(?:php)?[\s\S]*?\?>/gi;return a.replace(d,"").replace(c,function(a,c){return b.indexOf("<"+c.toLowerCase()+">")>-1?a:""})},Charcoal.Admin.Property_Input_Audio.prototype.init_file=function(){-1===this.initialized_types.indexOf("file")&&(this.initialized_types.push("file"),this.file_bind_events())},Charcoal.Admin.Property_Input_Audio.prototype.file_bind_events=function(){var a=this;a.element().on("click","."+a.file_properties.reset_button_class,function(){a.file_reset_input()})},Charcoal.Admin.Property_Input_Audio.prototype.file_reset_input=function(){this.file_properties.$file_audio.attr("src","").addClass("hide"),this.file_properties.$file_reset.addClass("hide"),this.file_properties.$file_input.removeClass("hide").wrap("
").closest("form").get(0).reset(),this.file_properties.$file_input.unwrap(),this.file_properties.$file_input_hiden.val("")},Charcoal.Admin.Property_Input_Audio.prototype.init_recording=function(){if(-1===this.initialized_types.indexOf("recording")){var a=this;a.initialized_types.push("recording"),window.navigator.getUserMedia||(window.navigator.getUserMedia=window.navigator.webkitGetUserMedia||window.navigator.mozGetUserMedia),window.navigator.cancelAnimationFrame||(window.navigator.cancelAnimationFrame=window.navigator.webkitCancelAnimationFrame||window.navigator.mozCancelAnimationFrame),window.navigator.requestAnimationFrame||(window.navigator.requestAnimationFrame=window.navigator.webkitRequestAnimationFrame||window.navigator.mozRequestAnimationFrame),window.AudioContext||(window.AudioContext=window.AudioContext||window.webkitAudioContext),window.navigator.getUserMedia({audio:{mandatory:{googEchoCancellation:!1,googAutoGainControl:!1,googNoiseSuppression:!1,googHighpassFilter:!1},optional:[]}},function(b){a.recording_bind_events(),a.recording_got_stream(b)},function(a){window.alert(audioPropertyL10n.captureFailed+" "+commonL10n.errorOccurred),window.console.log(a)})}},Charcoal.Admin.Property_Input_Audio.prototype.recording_bind_events=function(){var a=this;a.element().on("click","."+a.recording_properties.record_button_class,function(){a.recording_manage_recorder()}),a.element().on("click","."+a.recording_properties.stop_button_class,function(){a.recording_manage_recorder("stop")}),a.element().on("click","."+a.recording_properties.playback_button_class,function(){0!==a.recording_properties.recording_index&&null!==a.recording_properties.audio_player&&a.recording_toggle_playback()}),a.element().on("click","."+a.recording_properties.reset_button_class,function(){a.recording_reset_audio()})},Charcoal.Admin.Property_Input_Audio.prototype.recording_got_stream=function(a){var b=this;b.recording_properties.audio_context=new window.AudioContext,b.recording_properties.audio_player=new window.Audio_Player({on_ended:function(){b.recording_manage_button_states("pause_playback")},on_timeupdate:function(a){b.recording_render_timer(a)},on_loadedmetadata:function(a){b.recording_render_timer(a)}});var c=b.recording_properties.audio_context.createGain(),d=b.recording_properties.audio_context.createMediaStreamSource(a),e=null;d.connect(c),window.analyserNode=b.recording_properties.audio_context.createAnalyser(),window.analyserNode.fftSize=2048,c.connect(window.analyserNode),b.recording_properties.audio_recorder=new window.Recorder(c),e=b.recording_properties.audio_context.createGain(),e.gain.value=0,c.connect(e),e.connect(b.recording_properties.audio_context.destination),b.recording_update_analysers()},Charcoal.Admin.Property_Input_Audio.prototype.recording_manage_button_states=function(a){switch(a){case"start_recording":this.recording_properties.$record_button.addClass("is-recording"),this.recording_properties.$stop_button.prop("disabled",!1),this.recording_properties.$playback_button.prop("disabled",!0),this.recording_properties.$reset_button.prop("disabled",!1);break;case"pause_recording":this.recording_properties.$record_button.removeClass("is-recording"),this.recording_properties.$stop_button.prop("disabled",!1),this.recording_properties.$playback_button.prop("disabled",!0),this.recording_properties.$reset_button.prop("disabled",!1);break;case"stop_recording":this.recording_properties.$record_button.removeClass("is-recording"),this.recording_properties.$stop_button.prop("disabled",!0),this.recording_properties.$playback_button.prop("disabled",!1),this.recording_properties.$reset_button.prop("disabled",!1);break;case"start_playback":this.recording_properties.$playback_button.addClass("is-playing");break;case"pause_playback":this.recording_properties.$playback_button.removeClass("is-playing");break;case"reset":this.recording_properties.$record_button.removeClass("is-recording"),this.recording_properties.$stop_button.prop("disabled",!0),this.recording_properties.$playback_button.prop("disabled",!0).removeClass("is-playing"),this.recording_properties.$reset_button.prop("disabled",!0)}},Charcoal.Admin.Property_Input_Audio.prototype.recording_render_timer=function(a){var b="";if(a){var c=0,d=0,e=a.duration-a.currentTime;c=Math.floor(e/60),d=Math.round(e)%60,b+=(c<10?"0":"")+String(c)+":",b+=(d<10?"0":"")+String(d)}else b="00:00";this.recording_properties.$timer.text(b)},Charcoal.Admin.Property_Input_Audio.prototype.recording_manage_recorder=function(a){var b=this;if("stop"===a)return b.recording_properties.audio_recorder.stop(),b.recording_properties.audio_recorder.get_buffers(function(a){b.recording_got_buffers(a),b.recording_properties.audio_recorder.clear(),b.recording_display_canvas("waves")}),void b.recording_manage_button_states("stop_recording");if(b.recording_properties.audio_recorder.is_recording())b.recording_properties.audio_recorder.stop(),b.recording_manage_button_states("pause_recording");else{if(!b.recording_properties.audio_recorder)return;b.recording_properties.audio_recorder.record(),b.recording_manage_button_states("start_recording"),b.recording_display_canvas("analyser")}},Charcoal.Admin.Property_Input_Audio.prototype.recording_toggle_playback=function(){if(this.recording_properties.audio_player.is_playing())this.recording_properties.audio_player.pause(),this.recording_manage_button_states("pause_playback");else{if(!this.recording_properties.audio_player)return;this.recording_properties.audio_player.play(),this.recording_manage_button_states("start_playback")}},Charcoal.Admin.Property_Input_Audio.prototype.recording_reset_audio=function(){var a=this.recording_properties.$analyser_canvas[0];a.getContext("2d").clearRect(0,0,a.canvas_width,a.canvas_height);var b=this.recording_properties.$waves_canvas[0];b.getContext("2d").clearRect(0,0,b.canvas_width,b.canvas_height),this.recording_properties.audio_player.load(),this.recording_properties.audio_player.src(""),this.recording_properties.audio_recorder.stop(),this.recording_properties.audio_recorder.clear(),this.recording_manage_button_states("reset"),this.recording_display_canvas("analyser"),this.recording_render_timer();var c=document.getElementById(this.recording_properties.hidden_input_id);c&&(c.value="")},Charcoal.Admin.Property_Input_Audio.prototype.recording_got_buffers=function(a){var b=this.recording_properties.$waves_canvas[0],c=this;c.recording_draw_buffer(b.width,b.height,b.getContext("2d"),a[0]),c.recording_properties.audio_recorder.export_wav(function(a){c.recording_done_encoding(a)})},Charcoal.Admin.Property_Input_Audio.prototype.recording_draw_buffer=function(a,b,c,d){var e=Math.ceil(d.length/a),f=b/2;c.fillStyle="#DDDDDD",c.clearRect(0,0,a,b);for(var g=0;gi&&(i=k)}c.fillRect(g,(1+h)*f,1,Math.max(1,(i-h)*f))}},Charcoal.Admin.Property_Input_Audio.prototype.recording_done_encoding=function(a){var b=new window.FileReader,c=null,d=this;b.readAsDataURL(a),b.onloadend=function(){c=b.result,d.recording_properties.recording_index++,d.recording_manage_audio_data(c)}},Charcoal.Admin.Property_Input_Audio.prototype.recording_manage_audio_data=function(a){if(a){var b=document.getElementById(this.recording_properties.hidden_input_id);b&&(b.value=a),this.recording_properties.audio_player.src(a),this.recording_properties.audio_player.load()}},Charcoal.Admin.Property_Input_Audio.prototype.recording_display_canvas=function(a){switch(a){case"waves":this.recording_properties.$analyser_canvas.addClass("hidden"),this.recording_properties.$waves_canvas.removeClass("hidden");break;default:this.recording_properties.$analyser_canvas.removeClass("hidden"),this.recording_properties.$waves_canvas.addClass("hidden")}},Charcoal.Admin.Property_Input_Audio.prototype.recording_cancel_analyser_update=function(){window.cancelAnimationFrame(this.recording_properties.animation_frame),this.recording_properties.animation_frame=null},Charcoal.Admin.Property_Input_Audio.prototype.recording_update_analysers=function(){this.recording_properties.analyser_context||(this.recording_properties.analyser_context=this.recording_properties.$analyser_canvas[0].getContext("2d"));var a=this,b=a.recording_properties.analyser_context,c=a.recording_properties.$analyser_canvas[0];if(a.recording_properties.canvas_width=c.width,a.recording_properties.canvas_height=c.height,b.lineCap="round",a.recording_properties.audio_recorder.is_recording()){var d=Math.round(a.recording_properties.canvas_width/5),e=new window.Uint8Array(window.analyserNode.frequencyBinCount),f=0;window.analyserNode.getByteFrequencyData(e),f=window.analyserNode.frequencyBinCount/d,b.clearRect(0,0,a.recording_properties.canvas_width,a.recording_properties.canvas_height);for(var g=0;g0},this.element=function(){return this._element};var c=this;c.element().addEventListener("ended",function(){c.callbacks.on_ended()}),c.element().addEventListener("pause",function(){c.callbacks.on_pause()}),c.element().addEventListener("playing",function(){c.callbacks.on_playing()}),c.element().addEventListener("timeupdate",function(){c.callbacks.on_timeupdate(c.element())}),c.element().addEventListener("loadedmetadata",function(){c.callbacks.on_loadedmetadata(c.element())})};a.Audio_Player=b}(window),Charcoal.Admin.Property_Input_ColorPicker=function(a){this.input_type="charcoal/admin/property/input/colorpicker",this.input_id=null,this.colorpicker_selector=null,this.colorpicker_options=null,this.set_properties(a).create_colorpicker()},Charcoal.Admin.Property_Input_ColorPicker.prototype=Object.create(Charcoal.Admin.Property.prototype),Charcoal.Admin.Property_Input_ColorPicker.prototype.constructor=Charcoal.Admin.Property_Input_ColorPicker,Charcoal.Admin.Property_Input_ColorPicker.prototype.parent=Charcoal.Admin.Property.prototype,Charcoal.Admin.Property_Input_ColorPicker.prototype.set_properties=function(a){this.input_id=a.id||this.input_id,this.colorpicker_selector=a.data.colorpicker_selector||this.colorpicker_selector,this.colorpicker_options=a.data.colorpicker_options||this.colorpicker_options;var b={};return this.colorpicker_options=$.extend({},b,this.colorpicker_options),this},Charcoal.Admin.Property_Input_ColorPicker.prototype.create_colorpicker=function(){return $(this.colorpicker_selector).minicolors(this.colorpicker_options),this},Charcoal.Admin.Property_Input_DateTimePicker=function(a){this.input_type="charcoal/admin/property/input/datetimepicker",this.input_id=null,this.datetimepicker_selector=null,this.datetimepicker_options=null,this.set_properties(a).create_datetimepicker()},Charcoal.Admin.Property_Input_DateTimePicker.prototype=Object.create(Charcoal.Admin.Property.prototype),Charcoal.Admin.Property_Input_DateTimePicker.prototype.constructor=Charcoal.Admin.Property_Input_DateTimePicker,Charcoal.Admin.Property_Input_DateTimePicker.prototype.parent=Charcoal.Admin.Property.prototype,Charcoal.Admin.Property_Input_DateTimePicker.prototype.set_properties=function(a){this.input_id=a.id||this.input_id,this.datetimepicker_selector=a.data.datetimepicker_selector||this.datetimepicker_selector,this.datetimepicker_options=a.data.datetimepicker_options||this.datetimepicker_options;var b={};return this.datetimepicker_options=$.extend({},b,this.datetimepicker_options),this},Charcoal.Admin.Property_Input_DateTimePicker.prototype.create_datetimepicker=function(){ -return $(this.datetimepicker_selector).datetimepicker(this.datetimepicker_options),this},Charcoal.Admin.Property_Input_DualSelect=function(a){this.input_type="charcoal/admin/property/input/dualselect",this.input_id=null,this.dualselect_selector=null,this.dualselect_options={},this._dualselect=null,this.set_properties(a).init()},Charcoal.Admin.Property_Input_DualSelect.prototype=Object.create(Charcoal.Admin.Property.prototype),Charcoal.Admin.Property_Input_DualSelect.prototype.constructor=Charcoal.Admin.Property_Input_DualSelect,Charcoal.Admin.Property_Input_DualSelect.prototype.parent=Charcoal.Admin.Property.prototype,Charcoal.Admin.Property_Input_DualSelect.prototype.init=function(){this.create_dualselect()},Charcoal.Admin.Property_Input_DualSelect.prototype.set_properties=function(a){this.input_id=a.id||this.input_id,this.dualselect_selector=a.dualselect_selector||a.data.dualselect_selector||this.dualselect_selector,this.dualselect_options=a.dualselect_options||a.data.dualselect_options||this.dualselect_options;var b={keepRenderingSort:!1};return a.data.dualselect_options.searchable&&(this.dualselect_options.search={left:this.dualselect_selector+"_searchLeft",right:this.dualselect_selector+"_searchRight"}),this.dualselect_options=$.extend({},b,this.dualselect_options),this},Charcoal.Admin.Property_Input_DualSelect.prototype.create_dualselect=function(){return $(this.dualselect_selector).multiselect(this.dualselect_options),this},Charcoal.Admin.Property_Input_DualSelect.prototype.set_dualselect=function(a){return this._dualselect=a,this},Charcoal.Admin.Property_Input_DualSelect.prototype.dualselect=function(){return this._dualselect},Charcoal.Admin.Property_Input_DualSelect.prototype.destroy=function(){var a=this.dualselect();a&&a.remove()},Charcoal.Admin.Property_Input_File=function(a){return this.EVENT_NAMESPACE=".charcoal.property.file",this.input_type="charcoal/admin/property/input/file",this.opts=a,this.data=a.data,this.dialog=null,this.set_input_id(this.opts.id),this.init(),this},Charcoal.Admin.Property_Input_File.prototype=Object.create(Charcoal.Admin.Property.prototype),Charcoal.Admin.Property_Input_File.prototype.constructor=Charcoal.Admin.Property_Input_File,Charcoal.Admin.Property_Input_File.prototype.parent=Charcoal.Admin.Property.prototype,Charcoal.Admin.Property_Input_File.prototype.init=function(){if(!this.input_id)return this;this.$input=$("#"+this.input_id),this.$file=this.$input.find('input[type="file"]'),this.$hidden=this.$input.find('input[type="hidden"]'),this.$preview=this.$input.find(".js-preview"),window.elFinderCallback||(window.elFinderCallback={}),this.set_listeners()},Charcoal.Admin.Property_Input_File.prototype.set_listeners=function(){if(void 0===this.$input)return this;this.$input.on("click"+this.EVENT_NAMESPACE,".js-remove-file",this.remove_file.bind(this)).on("click"+this.EVENT_NAMESPACE,".js-elfinder",this.load_elfinder.bind(this)),this.$file.on("change"+this.EVENT_NAMESPACE,this.change_file.bind(this)),window.elFinderCallback[this.input_id]=this.elfinder_callback.bind(this)},Charcoal.Admin.Property_Input_File.prototype.remove_file=function(a){a.preventDefault(),this.$hidden.val(""),this.$input.find(".form-control-static").empty(),this.$input.find(".hide-if-no-file").addClass("hidden")},Charcoal.Admin.Property_Input_File.prototype.change_file=function(a){var b,c;b=a.dataTransfer||a.target,c=b&&b.files&&b.files[0],URL.createObjectURL(c),this.$input.find(".hide-if-no-file").removeClass("hidden"),this.$input.find(".form-control-static").html(c),this.$preview.empty()},Charcoal.Admin.Property_Input_File.prototype.load_elfinder=function(a){a.preventDefault(),this.dialog=BootstrapDialog.show({title:this.data.dialog_title||"",size:BootstrapDialog.SIZE_WIDE,cssClass:"-elfinder",message:$('')})},Charcoal.Admin.Property_Input_File.prototype.elfinder_callback=function(a){this.dialog&&this.dialog.close(),a&&a.path&&(this.$input.find(".hide-if-no-file").removeClass("hidden"),this.$input.find(".form-control-static").html(a.name),this.$hidden.val(decodeURI(a.url).replace(Charcoal.Admin.base_url(),"")),this.$preview.empty())},Charcoal.Admin.Property_Input_File.prototype.set_input_id=function(a){return this.input_id=a,this},Charcoal.Admin.Property_Input_File.prototype.set_input_name=function(a){return this.input_name=a,this},Charcoal.Admin.Property_Input_File.prototype.set_input_val=function(a){return this.input_val=a,this},Charcoal.Admin.Property_Input_Image=function(a){return this.EVENT_NAMESPACE=".charcoal.property.image",this.input_type="charcoal/admin/property/input/image",this.opts=a,this.data=a.data,this.set_input_id(this.opts.id),this.init(),this},Charcoal.Admin.Property_Input_Image.prototype=Object.create(Charcoal.Admin.Property_Input_File.prototype),Charcoal.Admin.Property_Input_Image.prototype.constructor=Charcoal.Admin.Property_Input_Image;Charcoal.Admin.Property_Input_Image.prototype.parent=Charcoal.Admin.Property.prototype,Charcoal.Admin.Property_Input_Image.prototype.remove_file=function(a){a.preventDefault(),this.$hidden.val(""),this.$preview.empty(),this.$input.find(".form-control-static").empty(),this.$input.find(".hide-if-no-file").addClass("hidden")},Charcoal.Admin.Property_Input_Image.prototype.change_file=function(a){var b,c,d,e;b=new File,c=a.dataTransfer||a.target,d=c&&c.files&&c.files[0],e=URL.createObjectURL(d),b.src=e,this.$input.find(".hide-if-no-file").removeClass("hidden"),this.$input.find(".form-control-static").html(d),this.$preview.empty().append(b)},Charcoal.Admin.Property_Input_Image.prototype.elfinder_callback=function(a){if(this.dialog&&this.dialog.close(),a&&a.path){var b=$('');this.$input.find(".hide-if-no-file").removeClass("hidden"),this.$input.find(".form-control-static").html(a.name),this.$hidden.val(decodeURI(a.url).replace(Charcoal.Admin.base_url(),"")),this.$preview.empty().append(b)}},Charcoal.Admin.Property_Input_Map_Widget=function(a){a.input_type="charcoal/admin/property/input/map-widget",Charcoal.Admin.Property.call(this,a);var b=this;this._controller=void 0,this._object_inc=0,"undefined"==typeof google?(window._tmp_google_onload_function=function(){b.init()},$.getScript("https://maps.googleapis.com/maps/api/js?sensor=false&callback=_tmp_google_onload_function&key="+a.data.api_key,function(){})):b.init()},Charcoal.Admin.Property_Input_Map_Widget.prototype=Object.create(Charcoal.Admin.Property.prototype),Charcoal.Admin.Property_Input_Map_Widget.prototype.constructor=Charcoal.Admin.Property_Input_Map_Widget,Charcoal.Admin.Property_Input_Map_Widget.prototype.parent=Charcoal.Admin.Property.prototype,Charcoal.Admin.Property_Input_Map_Widget.prototype.init=function(){if(void 0!==window._tmp_google_onload_function&&delete window._tmp_google_onload_function,"undefined"==typeof BB||"undefined"==typeof google)return console.error("Plugins not loaded"),!1;var a=this.data;void 0===a.id&&console.error("Missing ID");var b={strokeColor:"#000000",strokeOpacity:.8,strokeWeight:3,fillColor:"#ffffff",fillOpacity:.35,hover:{strokeColor:"#000000",strokeOpacity:1,strokeWeight:2,fillColor:"#ffffff",fillOpacity:.5},focused:{fillOpacity:.8}},c={default_styles:b,use_clusterer:!1,map:{center:{x:45.3712923,y:-73.9820994},zoom:14,mapType:"roadmap",coordsType:"inpage",map_mode:"default"}};c=$.extend(!0,c,a.data);var d=this.element().find("input[type=hidden]").val();if(d){var e=JSON.parse(d),f={},g=0;for(var h in e)g++,f[h]=e[h],f[h].styles=$.extend(e[h].styles,b);f&&(c.places=f),g&&(this._object_inc=g)}this._controller=new window.BB.gmap.controller(this.element().find(".js-map-maker-map").get(0),c),this.controller().init().ready(function(a){a.fit_bounds(),a.remove_focus()}),this.controller().set_styles([{featureType:"poi",elementType:"all",stylers:[{visibility:"off"}]}]),this.controller().remove_focus(),this.controls()},Charcoal.Admin.Property_Input_Map_Widget.prototype.controller=function(){return this._controller},Charcoal.Admin.Property_Input_Map_Widget.prototype.object_index=function(){return++this._object_inc},Charcoal.Admin.Property_Input_Map_Widget.prototype.controls=function(){var a=this,b="object";this.element().on("click",".js-add-marker",function(c){c.preventDefault();for(var d=b+a.object_index();a.controller().get_place(d);)d=b+a.object_index();a.controller().create_new("marker",d)}),this.element().on("click",".js-display-marker-toolbox",function(b){if(b.preventDefault(),$(this).hasClass("-active"))return $(this).removeClass("-active"),a.hide_marker_toolbar(),!1;$(this).siblings(".-active").removeClass("-active"),$(this).addClass("-active"),a.display_marker_toolbar()}),this.element().on("click",".js-add-line",function(c){if(c.preventDefault(),$(this).hasClass("-active"))return $(this).removeClass("-active"),!1;$(this).siblings(".-active").removeClass("-active"),$(this).addClass("-active");for(var d=b+a.object_index();a.controller().get_place(d);)d=b+a.object_index();a.controller().create_new("line",d)}),this.element().on("click",".js-add-polygon",function(c){if(c.preventDefault(),$(this).hasClass("-active"))return $(this).removeClass("-active"),!1;$(this).siblings(".-active").removeClass("-active"),$(this).addClass("-active");for(var d=b+a.object_index();a.controller().get_place(d);)d=b+a.object_index();a.controller().create_new("polygon",d)}),this.element().on("click",".js-add_place_by_address",function(b){b.preventDefault();var c=a.element().find(".js-address").val();if(!c)return!1;a.controller().add_place_by_address("object"+a.object_index(),c,{type:"marker",draggable:!0,editable:!0,loaded_callback:function(b){a.controller().map().setCenter(b.object().getPosition())}})}),this.element().on("click",".js-reset",function(b){b.preventDefault(),a.controller().reset()}),a.controller().on("focus",function(b){var c=b.data("type");switch(a.element().find(".js-add-polygon").removeClass("-active"),a.element().find(".js-display-marker-toolbox").removeClass("-active"),a.element().find(".js-add-line").removeClass("-active"),c){case"marker":a.element().find(".js-display-marker-toolbox").addClass("-active");break;case"polygon":a.element().find(".js-add-polygon").addClass("-active");break;case"line":a.element().find(".js-add-line").addClass("-active")}})},Charcoal.Admin.Property_Input_Map_Widget.prototype.display_marker_toolbar=function(){$(".c-map-maker").addClass("maker_header-open")},Charcoal.Admin.Property_Input_Map_Widget.prototype.hide_marker_toolbar=function(){$(".c-map-maker").removeClass("maker_header-open")},Charcoal.Admin.Property_Input_Map_Widget.prototype.save=function(){var a=this.controller().export(),b="object"==typeof a.places?a.places:{};return this.element().find("input[type=hidden]").val(JSON.stringify(b)),this},Charcoal.Admin.Property_Input_SelectPicker=function(a){this.input_type="charcoal/admin/property/input/select",this.input_id=null,this.select_selector=null,this.select_options=null,this.set_properties(a).create_select()},Charcoal.Admin.Property_Input_SelectPicker.prototype=Object.create(Charcoal.Admin.Property.prototype),Charcoal.Admin.Property_Input_SelectPicker.prototype.constructor=Charcoal.Admin.Property_Input_SelectPicker,Charcoal.Admin.Property_Input_SelectPicker.prototype.parent=Charcoal.Admin.Property.prototype,Charcoal.Admin.Property_Input_SelectPicker.prototype.set_properties=function(a){this.input_id=a.id||this.input_id,this.select_selector=a.data.select_selector||this.select_selector,this.select_options=a.data.select_options||this.select_options;var b={};return this.select_options=$.extend({},b,this.select_options),this},Charcoal.Admin.Property_Input_SelectPicker.prototype.create_select=function(){return $(this.select_selector).selectpicker(this.select_options),this},function(){var a=function(a){this.input_type="charcoal/admin/property/input/selectize",this.input_id=null,this.obj_type=null,this.copy_items=!1,this.title=null,this.translations=null,this.pattern=null,this.multiple=!1,this.separator=",",this.selectize=null,this.selectize_selector=null,this.form_ident=null,this.selectize_options={},this.choice_obj_map={},this.selectize_property_ident=null,this.selectize_obj_type=null,this.selectize_templates={},this.clipboard=null,this.allow_update=null,this.set_properties(a).init()};a.prototype=Object.create(Charcoal.Admin.Property.prototype),a.constructor=Charcoal.Admin.Property_Input_Selectize,a.parent=Charcoal.Admin.Property.prototype,a.prototype.init=function(){this.init_selectize(),this.init_clipboard(),this.init_allow_update(),this.init_allow_create();var a=this;this.selectize.on("update_item",function(b){a.create_item(null,b.callback,{id:b.value,step:0})})},a.prototype.set_properties=function(a){this.input_id=a.id||this.input_id,this.obj_type=a.data.obj_type||this.obj_type,this.copy_items=a.data.copy_items||this.copy_items,this.allow_update=a.data.allow_update||this.allow_update,this.allow_create=a.data.allow_create||this.allow_create,this.title=a.data.title||this.title,this.translations=a.data.translations||this.translations,this.pattern=a.data.pattern||this.pattern,this.multiple=a.data.multiple||this.multiple,this.separator=a.data.multiple_separator||this.multiple_separator||",",this.form_ident=a.data.form_ident||this.form_ident,this.selectize_selector=a.data.selectize_selector||this.selectize_selector,this.selectize_options=a.data.selectize_options||this.selectize_options,this.choice_obj_map=a.data.choice_obj_map||this.choice_obj_map,this.selectize_property_ident=a.data.selectize_property_ident||this.selectize_property_ident,this.selectize_obj_type=a.data.selectize_obj_type||this.selectize_obj_type,this.selectize_templates=a.data.selectize_templates||this.selectize_templates,this.$input=$(this.selectize_selector||"#"+this.input_id);var b;b=this.multiple?{drag_drop:{},charcoal_item:{}}:{charcoal_item:{}};var c=this.obj_type,d={plugins:b,formData:{},delimiter:this.separator,persist:!0,preload:"focus",openOnFocus:!0,labelField:"label",searchField:["value","label"],dropdownParent:this.$input.closest(".form-field"),render:{},createFilter:function(a){for(var b in this.options)if(b=this.options[b],b.label===a)return!1;return!0},onInitialize:function(){var a=this;a.sifter.iterator(this.items,function(b){var c=a.options[b],d=a.getItem(b);c.color&&d.css("background-color",c.color)})}};if(this.selectize_templates.item&&(d.render.item=function(a,b){return a.item_render?'
'+a.item_render+"
":'
'+b(a[d.labelField])+"
"}),this.selectize_templates.option&&(d.render.option=function(a,b){return a.option_render?'
'+a.option_render+"
":'
'+b(a[d.labelField])+"
"}),c?(d.create=this.create_item.bind(this),d.load=this.load_items.bind(this)):(d.plugins.create_on_enter={},d.create=function(a){return{value:a,label:a}}),this.selectize_options.splitOn){var e=this.selectize_options.splitOn;if("array"===$.type(e)){for(var f=e.length-1;f>=0;f--)switch(e[f]){case"comma":e[f]="\\s*,\\s*";break;case"tab":e[f]="\\t+";break;default:e[f]=e[f].replace(/[-\/\\^$*+?.()|[\]{}]/g,"\\$&")}e=e.join("|")}this.selectize_options.splitOn=new RegExp(e)}return this.selectize_options=$.extend(!0,{},d,this.selectize_options),this},a.prototype.create_item=function(a,b,c){var d={};c=c||{};var e=this.pattern,f=this,g=this.obj_type,h=this.title,i=this.translations,j=this.selectize_options,k=c.step||0,l=this.form_ident,m=null,n=c.id||null,o=this.selectize_property_ident,p=this.selectize_obj_type;l&&"object"==typeof l&&(!n&&l.create?(l=l.create,h+=" - "+i.statusTemplate.replaceMap({"[[ current ]]":1,"[[ total ]]":2}),k=1,m="Next"):n&&l.update?(l=l.update,2===k&&(h+=" - "+i.statusTemplate.replaceMap({"[[ current ]]":2,"[[ total ]]":2}),m="Finish")):l=null),$.isEmptyObject(j.formData)?(e?a&&(d[e]=a):a&&(d[this.choice_obj_map.label]=a),d.form_ident=l,d.submit_label=m):a&&(d=$.extend({},j.formData),$.each(d,function(b,c){":input"===c&&(d[b]=a)}));var q={title:h,size:BootstrapDialog.SIZE_WIDE,cssClass:"-quick-form",dialog_options:{onhide:function(){b({return:!1})}},widget_type:"charcoal/admin/widget/quickForm",widget_options:{obj_type:g,obj_id:n,form_data:d}};k>0&&(q.type=BootstrapDialog.TYPE_PRIMARY);var r=this.dialog(q,function(c){if(c.success){if(!c.widget_id)return!1;Charcoal.Admin.manager().add_widget({id:c.widget_id,type:"charcoal/admin/widget/quick-form",data:{obj_type:g},obj_id:n,extra_form_data:{selectize_obj_type:p,selectize_prop_ident:o},save_action:"selectize/save",update_action:"selectize/update",suppress_feedback:1===k,save_callback:function(c){var d={class:"new"},e=c.selectize[0];e&&$.extend(!0,d,e),b(d),r.close(),1===k&&f.create_item(a,b,{id:e.value,step:2})}}),Charcoal.Admin.manager().render()}})},a.prototype.load_items=function(a,b){var c=this.obj_type,d=this.selectize_property_ident,e=this.selectize_obj_type,f={obj_type:c,selectize_obj_type:e,selectize_prop_ident:d};$.ajax({url:Charcoal.Admin.admin_url()+"selectize/load",data:f,type:"GET",error:function(){b()},success:function(a){var c=[],d=a.selectize;for(var e in d)d.hasOwnProperty(e)&&(e=d[e],c.push(e));b(c)}})},a.prototype.dialog=Charcoal.Admin.Widget.prototype.dialog,a.prototype.init_selectize=function(){var a=this.$input.selectize(this.selectize_options);this.selectize=a[0].selectize},a.prototype.init_allow_create=function(){if(this.allow_create){var a=this.selectize,b=this;$(this.selectize_selector+"_create").on("click",function(){b.create_item(null,function(b){b&&b.value&&(a.addOption(b),a.addItem(b.value))})})}},a.prototype.init_allow_update=function(){switch(this.selectize.settings.mode){case"single":this.allow_update_single();break;case"multiple":this.allow_update_multiple()}},a.prototype.allow_update_single=function(){if(this.allow_update){var a=this.selectize,b=this;$(this.selectize_selector+"_update").on("click",function(){var c=a.items;c&&b.create_item(null,function(b){b&&b.value&&a.updateOption(c[0],b)},{id:c[0],step:0})})}},a.prototype.allow_update_multiple=function(){if(this.allow_update){var a=this.selectize,b=$(this.selectize_selector+"_update"),c=null,d=this;b[0].disabled=!0,b.on("click",function(){c&&d.create_item(null,function(b){b&&b.value&&a.updateOption(c,b)},{id:c,step:0})}),a.on("blur",function(){setTimeout(function(){b[0].disabled=!0},500)}),a.$control.on("mousedown","*:not(input)",function(d){c=$(d.target).eq(0).data("value"),a.$control.find(".active:not(input)")&&(b[0].disabled=!1)})}},a.prototype.init_clipboard=function(){if(this.copy_items){var a=this.selectize;this.clipboard=new Clipboard(this.selectize_selector+"_copy",{text:function(){return a.$input.val()}})}},Charcoal.Admin.Property_Input_Selectize=a}(jQuery,document),Selectize.define("btn_remove",function(a){a=$.extend({label:'',title:"Remove",className:"btn-remove",append:!0},a),this.require("buttons");"single"!==this.settings.mode&&function(a,b){var c=a;c.addButton(a,b,function(a){if(a.preventDefault(),!c.isLocked){var b=$(a.currentTarget).parent();c.setActiveItem(b),c.deleteSelection()&&c.setCaret(c.items.length)}})}(this,a)}),Selectize.define("btn_update",function(a){a=$.extend({label:'',title:"Update",className:"btn-update",append:!0},a),this.require("buttons");"single"!==this.settings.mode&&function(a,b){var c=a;c.addButton(a,b,function(a){if(a.preventDefault(),!c.isLocked){var b=$(a.currentTarget).parent();c.setActiveItem(b),c.trigger("update_item",{item:b,value:b.eq(0).data("value"),callback:function(a){a&&a.value&&c.updateOption(a.value,a)}})}})}(this,a)}),Selectize.define("buttons",function(){var a=function(a){return(a+"").replace(/&/g,"&").replace(//g,">").replace(/"/g,""")};this.buttonOffset=40,this.currentButtonOffset=0,this.addButton=function(b,c,d){var e=b,f=''+c.label+"";e.currentButtonOffset+=e.buttonOffset;var g=function(a,b){var c=a.search(/(<\/[^>]+>\s*)$/);return a.substring(0,c)+b+a.substring(c)},h=function(a,b){var c=a.match(/(padding-right:.*;)/);if(c&&c[0]){var d=c[0].length+c.index;return a.substring(0,c.index)+"padding-right:"+(b+8)+"px;"+a.substring(d)}return(c=a.match(/(style=")/))&&c[0]?(c=c[0].length+c.index,a.substring(0,c)+"padding-right:"+(b+8)+"px;"+a.substring(c)):(c=a.match(/(<[^>]+)/),c&&c[0]?(c=c[0].length+c.index,a.substring(0,c)+'style="padding-right:'+(b+8)+'px;"'+a.substring(c)):void 0)};b.setup=function(){var a=e.setup;return function(){if(c.append){var i=e.settings.render.item;e.settings.render.item=function(){return g(h(i.apply(b,arguments),e.currentButtonOffset),f)}}a.apply(b,arguments),b.$control.on("mousedown","."+c.className,function(a){a.preventDefault(),e.$control.data("ui-sortable")&&(e.$control.sortable("disable"),$(document).on("mouseup.sortable",function(){$(document).off("mouseup.sortable"),e.$control.sortable("enable")}))}),b.$control.on("click","."+c.className,function(a){"function"==typeof d&&d(a)})}}()}}),Selectize.define("create_on_blur",function(){if("multi"===this.settings.mode){var a=this;this.onBlur=function(){var b=a.onBlur;return function(){return""!==this.$control_input.val().trim()&&a.createItem(this.$control_input.val()),b.apply(this,arguments)}}()}}),Selectize.define("create_on_enter",function(){if("multi"===this.settings.mode){var a=this;this.onKeyUp=function(){var b=a.onKeyUp;return function(c){return 13===c.keyCode&&""!==this.$control_input.val().trim()&&a.createItem(this.$control_input.val()),b.apply(this,arguments)}}()}}),function(){var a=function(a){this.input_type="charcoal/admin/property/input/selectize",this.input_id=null,this.obj_type=null,this.copy_items=!1,this.title=null,this.translations=null,this.pattern=null,this.multiple=!1,this.separator=",",this.selectize=null,this.selectize_selector=null,this.form_ident=null,this.selectize_options={},this.choice_obj_map={},this.clipboard=null,this.allow_update=!1,this.set_properties(a).init()};a.prototype=Object.create(Charcoal.Admin.Property_Input_Selectize.prototype),a.constructor=Charcoal.Admin.Property_Input_Selectize,a.parent=Object.create(Charcoal.Admin.Property_Input_Selectize.prototype),a.prototype.set_properties=function(a){this.input_id=a.id||this.input_id,this.obj_type=a.data.obj_type||this.obj_type,this.copy_items=a.data.copy_items||this.copy_items,this.allow_update=a.data.allow_update||this.allow_update,this.title=a.data.title||this.title,this.translations=a.data.translations||this.translations,this.pattern=a.data.pattern||this.pattern,this.multiple=a.data.multiple||this.multiple,this.separator=a.data.multiple_separator||this.multiple_separator||",",this.form_ident=a.data.form_ident||this.form_ident,this.selectize_selector=a.data.selectize_selector||this.selectize_selector,this.selectize_options=a.data.selectize_options||this.selectize_options,this.choice_obj_map=a.data.choice_obj_map||this.choice_obj_map,this.$input=$(this.selectize_selector||"#"+this.input_id);var b;b=this.multiple?{drag_drop:{},charcoal_item:{}}:{charcoal_item:{}};var c=this.obj_type,d={plugins:b,formData:{},delimiter:this.separator,persist:!0,preload:"focus",openOnFocus:!0,searchField:["value","label","email"],dropdownParent:this.$input.closest(".form-field"),createFilter:function(a){for(var b in this.options)if(b=this.options[b],b.label===a)return!1;return!0},onInitialize:function(){var a=this;a.sifter.iterator(this.items,function(b){var c=a.options[b],d=a.getItem(b);c.color&&d.css("background-color",c.color)})},render:{item:function(a,b){return'
'+(a.label?''+b(a.label)+"":"")+(a.email?'":"")+"
"},option:function(a,b){return'
'+(a.label?''+b(a.label)+"":"")+(a.email?''+b(a.email)+"":"")+"
"}}};if(c?(d.create=this.create_item.bind(this),d.load=this.load_items.bind(this)):(d.plugins.create_on_enter={},d.create=function(a){return{value:a,label:a}}),this.selectize_options.splitOn){var e=this.selectize_options.splitOn;if("array"===$.type(e)){for(var f=e.length-1;f>=0;f--)switch(e[f]){case"comma":e[f]="\\s*,\\s*";break;case"tab":e[f]="\\t+";break;default:e[f]=e[f].replace(/[-\/\\^$*+?.()|[\]{}]/g,"\\$&")}e=e.join("|")}this.selectize_options.splitOn=new RegExp(e)}return this.selectize_options=$.extend(!0,{},d,this.selectize_options),this},Charcoal.Admin.Property_Input_Selectize_Email=a}(jQuery,document),Selectize.define("charcoal_item",function(a){a=$.extend({classField:"class",colorField:"color"},a);var b=this;this.settings.onItemAdd=function(){var c=null;return b.settings.hasOwnProperty("onItemAdd")&&(c=b.settings.onItemAdd),function(d,e){var f=b.options[d];if(f.hasOwnProperty(a.colorField)&&e.css("background-color",f[a.colorField]),f.hasOwnProperty(a.classField)&&e.addClass(f[a.classField]),c)return c.apply(this,arguments)}}()}),function(){var a=function(a){this.input_type="charcoal/admin/property/input/selectize/list",this.input_id=null,this.obj_type=null,this.copy_items=!1,this.title=null,this.translations=null,this.pattern=null,this.multiple=!1,this.separator=",",this.selectize=null,this.selectize_selector=null,this.form_ident=null,this.selectize_options={},this.clipboard=null,this.allow_update=!1,this.set_properties(a).init()};a.prototype=Object.create(Charcoal.Admin.Property_Input_Selectize.prototype),a.constructor=Charcoal.Admin.Property_Input_Selectize,a.parent=Charcoal.Admin.Property_Input_Selectize.prototype,a.prototype.set_properties=function(a){this.input_id=a.id||this.input_id,this.obj_type=a.data.obj_type||this.obj_type,this.copy_items=a.data.copy_items||this.copy_items,this.allow_update=a.data.allow_update||this.allow_update,this.title=a.data.title||this.title,this.translations=a.data.translations||this.translations,this.pattern=a.data.pattern||this.pattern,this.multiple=a.data.multiple||this.multiple,this.separator=a.data.multiple_separator||this.multiple_separator||",",this.form_ident=a.data.form_ident||this.form_ident,this.selectize_selector=a.data.selectize_selector||this.selectize_selector,this.selectize_options=a.data.selectize_options||this.selectize_options,this.$input=$(this.selectize_selector||"#"+this.input_id);var b;b=this.multiple?{drag_drop:{},charcoal_item:{}}:{charcoal_item:{}};var c=this.obj_type,d={plugins:b,formData:{},delimiter:this.separator,persist:!0,preload:"focus",openOnFocus:!0,searchField:["value","label"],dropdownParent:this.$input.closest(".form-field"),createFilter:function(a){for(var b in this.options)if(b=this.options[b],b.label===a)return!1;return!0},onInitialize:function(){var a=this;a.sifter.iterator(this.items,function(b){var c=a.options[b],d=a.getItem(b);c.color&&d.css("background-color",c.color)})}};if(c?(d.create=this.create_item.bind(this),d.load=this.load_items.bind(this)):(d.plugins.create_on_enter={},d.create=function(a){return{value:a,label:a}}),this.selectize_options.splitOn){var e=this.selectize_options.splitOn;if("array"===$.type(e)){for(var f=e.length-1;f>=0;f--)switch(e[f]){case"comma":e[f]="\\s*,\\s*";break;case"tab":e[f]="\\t+";break;default:e[f]=e[f].replace(/[-\/\\^$*+?.()|[\]{}]/g,"\\$&")}e=e.join("|")}this.selectize_options.splitOn=new RegExp(e)}return this.selectize_options=$.extend(!0,{},d,this.selectize_options),this},Charcoal.Admin.Property_Input_Selectize_List=a}(jQuery,document),Charcoal.Admin.Property_Input_Selectize_Search=function(a){this.input_type="charcoal/admin/property/input/selectize/search",this.input_id=null,this.obj_type=null,this.copy_items=!1,this.title=null,this.multiple=!1,this.separator=",",this._tags=null,this.selectize=null,this.selectize_selector=null,this.selectize_options={},this.clipboard=null,this.set_properties(a).init()},Charcoal.Admin.Property_Input_Selectize_Search.prototype=Object.create(Charcoal.Admin.Property.prototype),Charcoal.Admin.Property_Input_Selectize_Search.prototype.constructor=Charcoal.Admin.Property_Input_Selectize_Search,Charcoal.Admin.Property_Input_Selectize_Search.prototype.parent=Charcoal.Admin.Property.prototype,Charcoal.Admin.Property_Input_Selectize_Search.prototype.init=function(){if("function"!=typeof $.fn.sortable){return Charcoal.Admin.loadScript("https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js",this.init.bind(this)),this}this.init_selectize()},Charcoal.Admin.Property_Input_Selectize_Search.prototype.set_properties=function(a){this.input_id=a.id||this.input_id,this.obj_type=a.data.obj_type||this.obj_type,this.copy_items=a.data.copy_items||this.copy_items,this.title=a.data.title||this.title,this.multiple=a.data.multiple||this.multiple,this.separator=a.data.multiple_separator||this.multiple_separator||",",this.selectize_selector=a.data.selectize_selector||this.selectize_selector,this.selectize_options=a.data.selectize_options||this.selectize_options,this.$input=$(this.selectize_selector||"#"+this.input_id);var b;this.multiple&&(b=["remove_button","drag_drop"]);var c={plugins:b,formData:{},delimiter:this.separator,persist:!1,preload:!0,openOnFocus:!0};return this.selectize_options=$.extend({},c,this.selectize_options),this},Charcoal.Admin.Property_Input_Selectize_Search.prototype.init_selectize=function(){var a=this.$input.selectize(this.selectize_options);this.selectize=a[0].selectize},Charcoal.Admin.Property_Input_Selectize_Tags=function(a){this.input_type="charcoal/admin/property/input/selectize/tags",this.input_id=null,this.obj_type=null,this.copy_items=!1,this.title=null,this.multiple=!1,this.separator=",",this._tags=null,this.selectize=null,this.selectize_selector=null,this.selectize_options={},this.clipboard=null,this.set_properties(a).init()},Charcoal.Admin.Property_Input_Selectize_Tags.prototype=Object.create(Charcoal.Admin.Property.prototype),Charcoal.Admin.Property_Input_Selectize_Tags.prototype.constructor=Charcoal.Admin.Property_Input_Selectize_Tags,Charcoal.Admin.Property_Input_Selectize_Tags.prototype.parent=Charcoal.Admin.Property.prototype,Charcoal.Admin.Property_Input_Selectize_Tags.prototype.init=function(){if("function"!=typeof $.fn.sortable){return Charcoal.Admin.loadScript("https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js",this.init.bind(this)),this}this.init_selectize(),this.init_clipboard()},Charcoal.Admin.Property_Input_Selectize_Tags.prototype.set_properties=function(a){this.input_id=a.id||this.input_id,this.obj_type=a.data.obj_type||this.obj_type,this.copy_items=a.data.copy_items||this.copy_items,this.title=a.data.title||this.title,this.multiple=a.data.multiple||this.multiple,this.separator=a.data.multiple_separator||this.multiple_separator||",",this.selectize_selector=a.data.selectize_selector||this.selectize_selector,this.selectize_options=a.data.selectize_options||this.selectize_options,this.$input=$(this.selectize_selector||"#"+this.input_id);var b;b=this.multiple?["remove_button","drag_drop","charcoal_item"]:["charcoal_item"];var c=this.obj_type,d={plugins:b,formData:{},delimiter:this.separator,persist:!1,preload:!0,openOnFocus:!0,dropdownParent:this.$input.closest(".form-field"),createFilter:function(a){for(var b in this.options)if(b=this.options[b],b.text===a)return!1;return!0},onInitialize:function(){var a=this;a.sifter.iterator(this.items,function(b){var c=a.options[b],d=a.getItem(b);c.color&&d.css("background-color",c.color)})}};if(c?(d.create=this.create_tag.bind(this),d.load=this.load_tags.bind(this)):(d.plugins.push("create_on_enter"),d.create=function(a){return{value:a,text:a}}),this.selectize_options=$.extend({},d,this.selectize_options),this.selectize_options.splitOn){var e=this.selectize_options.splitOn;if("array"===$.type(e)){for(var f=e.length-1;f>=0;f--)switch(e[f]){case"comma":e[f]="\\s*,\\s*";break;case"tab":e[f]="\\t+";break;default:e[f]=e[f].replace(/[-\/\\^$*+?.()|[\]{}]/g,"\\$&")} -e=e.join("|")}this.selectize_options.splitOn=new RegExp(e)}return this},Charcoal.Admin.Property_Input_Selectize_Tags.prototype.create_tag=function(a,b){var c=this.obj_type,d=this.id,e=this.title,f=this.selectize_options,g={};$.isEmptyObject(f.formData)?g={name:a}:(g=$.extend({},f.formData),$.each(g,function(b,c){":input"===c&&(g[b]=a)}));var h={title:e,size:BootstrapDialog.SIZE_WIDE,cssClass:"-quick-form",dialog_options:{onhide:function(){b({return:!1})}},widget_type:"charcoal/admin/widget/quickForm",widget_options:{obj_type:c,obj_id:d,form_data:g}};this.dialog(h,function(a){if(a.success){if(!a.widget_id)return!1;Charcoal.Admin.manager().add_widget({id:a.widget_id,type:"charcoal/admin/widget/quick-form",data:{obj_type:c},obj_id:d,save_callback:function(a){var c=a.obj.id;"name"in a.obj&&a.obj.name&&(c=a.obj.name[Charcoal.Admin.lang()]||a.obj.name),b({value:a.obj.id,text:c,color:a.obj.color,class:"new"}),BootstrapDialog.closeAll()}})}})},Charcoal.Admin.Property_Input_Selectize_Tags.prototype.load_tags=function(a,b){var c=this.obj_type;if(!a.length)return b();$.ajax({url:Charcoal.Admin.admin_url()+"object/load",data:{obj_type:c},type:"GET",error:function(){b()},success:function(a){var c=[];for(var d in a.collection){d=a.collection[d];var e=d.id;"name"in d&&d.name&&(e=d.name[Charcoal.Admin.lang()]||d.name),c.push({value:d.id,text:e,color:d.color})}b(c)}})},Charcoal.Admin.Property_Input_Selectize_Tags.prototype.dialog=Charcoal.Admin.Widget.prototype.dialog,Charcoal.Admin.Property_Input_Selectize_Tags.prototype.onKeyDown=function(a){var b=this,c=!1,d=/Mac/.test(navigator.userAgent);if(b.isLocked&&9!==a.keyCode&&a.preventDefault(),"undefined"===$.type(b.isCmdDown)&&(c=!0,b.isCmdDown=a[d?"metaKey":"ctrlKey"]),b.isCmdDown&&67===a.keyCode){if(c&&(b.isCmdDown=void 0),b.$activeItems.length)for(var e=[],f=0,g=b.$activeItems.length;f0;a--)this.add_item();return this},Charcoal.Admin.Property_Input_Text.prototype.split_val=function(a){var b=this.split_on||this.multiple_separator;a=a||this.$input;var c=a.val(),d=c.split(b),e=0,f=d.length;if(1===f)return!1;for(;e-1&&(!b.multiple_max||b.currentValAmount-1&&(!b.multiple_min||b.currentValAmount>b.multiple_min)&&""===$(this).val()&&(a.preventDefault(),b.remove_item($(this))),f.indexOf(g)>-1&&(a.preventDefault(),$(this).prev("input").focus()),e.indexOf(g)>-1&&(a.preventDefault(),$(this).next("input").focus())}),a.on("keyup",function(){b.split_val($(this))})},Charcoal.Admin.Property_Input_Text.prototype.insert_item=function(a,b){var c=this.input_clone(b);return c.insertAfter(a),this.bind_keyboard_events(c),c.focus(),this.currentValAmount++,c},Charcoal.Admin.Property_Input_Text.prototype.add_item=function(a){var b=this.input_clone(a);return this.$container.append(b),this.bind_keyboard_events(b),b.focus(),this.currentValAmount++,b},Charcoal.Admin.Property_Input_Text.prototype.remove_item=function(a){var b=a.prev("input"),c=a.next("input");return!(!b.length&&!c.length)&&(b.length?b.focus():c.length&&c.focus(),this.remove_item_listeners(a),a.remove(),this.currentValAmount--,this)},Charcoal.Admin.Property_Input_Text.prototype.remove_item_listeners=function(a){return a.off("keydown"),a.off("keyup"),this},Charcoal.Admin.Property_Input_Text.prototype.input_clone=function(a){var b=this.$input,c=b.attr("class"),d=b.attr("type"),e=this.min_length,f=this.max_length,g=this.required,h=this.readonly,i=this.input_name,j=$("");return d&&j.attr("type",d),c&&j.attr("class",c),e&&j.attr("minlength",e),f&&j.attr("maxlength",f),g&&j.attr("required","required"),h&&j.attr("readonly","readonly"),a&&j.val(a),j.attr("name",i),j},Charcoal.Admin.Property_Input_Text.prototype.set_input_id=function(a){return this.input_id=a,this},Charcoal.Admin.Property_Input_Text.prototype.set_input_name=function(a){return this.input_name=a,this},Charcoal.Admin.Property_Input_Text.prototype.set_input_val=function(a){return this.input_val=a,this},Charcoal.Admin.Property_Input_Text.prototype.set_readonly=function(a){return a||(a=!1),this.readonly=a,this},Charcoal.Admin.Property_Input_Text.prototype.set_required=function(a){return a||(a=!1),this.required=a,this},Charcoal.Admin.Property_Input_Text.prototype.set_min_length=function(a){return a||(a=0),this.min_length=a,this},Charcoal.Admin.Property_Input_Text.prototype.set_max_length=function(a){return a||(a=0),this.max_length=a,this},Charcoal.Admin.Property_Input_Text.prototype.set_size=function(a){return a||(a=0),this.size=a,this},Charcoal.Admin.Property_Input_Text.prototype.set_multiple=function(a){return a||(a=!1),this.multiple=a,this},Charcoal.Admin.Property_Input_Text.prototype.set_multiple_min=function(a){return a||(a=!1),this.multiple_min=a,this},Charcoal.Admin.Property_Input_Text.prototype.set_multiple_max=function(a){return a||(a=!1),this.multiple_max=a,this},Charcoal.Admin.Property_Input_Text.prototype.set_multiple_separator=function(a){return a||(a=","),this.multiple_separator=a,this},Charcoal.Admin.Property_Input_Text.prototype.set_split_on=function(a){if(a){if("array"===$.type(a)){for(var b=a.length-1;b>=0;b--)switch(a[b]){case"comma":a[b]="\\s*,\\s*";break;case"tab":a[b]="\\t+";break;case"newline":a[b]="[\\n\\r]+";break;default:a[b]=a[b].replace(/[-\/\\^$*+?.()|[\]{}]/g,"\\$&")}a=a.join("|")}a=new RegExp(a)}else a=this.multiple_separator;return this.split_on=a,this},Charcoal.Admin.Property_Input_Tinymce=function(a){this.input_type="charcoal/admin/property/input/tinymce",this.input_id=null,this.data=a.data,this.editor_options=null,this._editor=null,window.elFinderCallback||(window.elFinderCallback={}),this.set_properties(a),this.init()},Charcoal.Admin.Property_Input_Tinymce.prototype=Object.create(Charcoal.Admin.Property.prototype),Charcoal.Admin.Property_Input_Tinymce.prototype.constructor=Charcoal.Admin.Property_Input_Tinymce,Charcoal.Admin.Property_Input_Tinymce.prototype.parent=Charcoal.Admin.Property.prototype,Charcoal.Admin.Property_Input_Tinymce.prototype.init=function(){this.create_tinymce()},Charcoal.Admin.Property_Input_Tinymce.prototype.base_url=function(){return Charcoal.Admin.base_url()+"assets/admin/scripts/vendors/tinymce"},Charcoal.Admin.Property_Input_Tinymce.prototype.set_properties=function(a){this.input_id=a.input_id||this.input_id,this.editor_options=a.editor_options||a.data.editor_options||this.editor_options,window.elFinderCallback[this.input_id]=this.elfinder_callback.bind(this);var b=Charcoal.Admin.locale().match(/([a-zA-Z]{2})(_|-)([a-zA-Z]{2})/)[0]||"en";b=b.replace("-","_"),b.match(/en_/)&&(b="en");var c={language:b,plugins:["advlist","anchor","autolink","autoresize","charcoal","charmap","code","colorpicker","contextmenu","fullscreen","hr","image","link","lists","media","nonbreaking","noneditable","paste","placeholder","searchreplace","tabfocus","table","visualblocks","visualchars","wordcount"],toolbar:"undo redo | styleselect | bold italic | forecolor backcolor | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image anchor",browser_spellcheck:!0,end_container_on_empty_block:!0,entity_encoding:"raw",allow_conditional_comments:!0,convert_fonts_to_spans:!0,forced_root_block:"p",allow_script_urls:!1,document_base_url:Charcoal.Admin.base_url(),relative_urls:!0,remove_script_host:!1,autoresize_min_height:"150px",autoresize_max_height:"400px",contextmenu:"link image inserttable | cell row column deletetable",file_picker_callback:$.proxy(this.elfinder_browser,null,this),image_advtab:!0,importcss_append:!0,media_alt_source:!1,nonbreaking_force_tab:!1,paste_data_images:!0,paste_as_text:!0,paste_merge_formats:!0,root_lang_attr:$("#"+this.input_id).closest("[data-lang]").data("lang"),table_grid:!0,table_tab_navigation:!0,visualblocks_default_state:!1};return"plugins"in c&&"plugins"in this.editor_options&&($.each(this.editor_options.plugins,function(a,b){var d,e=0===b.indexOf("!");if(e&&(b=b.slice(1)),e)for(;(d=c.plugins.indexOf(b))>-1;)delete c.plugins[d];else-1===c.plugins.indexOf(b)&&c.plugins.push(b)}),delete this.editor_options.plugins),this.editor_options=$.extend({},c,this.editor_options),this.editor_options.selector="#"+this.input_id,this.editor_options.setup=function(a){a.on("change",function(){window.tinymce.triggerSave()})},this},Charcoal.Admin.Property_Input_Tinymce.prototype.create_tinymce=function(){var a=this;if("object"!=typeof window.tinyMCE){var b=this.base_url()+"/tinymce.min.js";return Charcoal.Admin.loadScript(b,this.create_tinymce.bind(this)),this}window.tinyMCE.dom.Event.domLoaded=!0,window.tinyMCE.baseURI=new window.tinyMCE.util.URI(this.base_url()),window.tinyMCE.baseURL=this.base_url(),window.tinyMCE.suffix=".min",window.tinyMCE.PluginManager.get(this.input_id)||(window.tinyMCE.PluginManager.add(this.input_id,function(b){a.set_editor(b)}),"array"!==$.type(this.editor_options.plugins)&&(this.editor_options.plugins=[]),this.editor_options.plugins.push(this.input_id)),window.tinyMCE.init(this.editor_options)},Charcoal.Admin.Property_Input_Tinymce.prototype.elfinder_callback=function(a,b){parent.tinyMCE.activeEditor.windowManager.getParams().oninsert(a,b),parent.tinyMCE.activeEditor.windowManager.close()},Charcoal.Admin.Property_Input_Tinymce.prototype.elfinder_browser=function(a,b,c,d){var e=this;return window.tinyMCE.activeEditor.windowManager.open({file:a.data.elfinder_url+"&"+$.param(d),title:a.data.dialog_title||"",width:900,height:450,resizable:"yes"},{oninsert:function(a,c){var f,g,h,i;for(f=a.url,g=/\/[^\/]+?\/\.\.\//;f.match(g);)f=f.replace(g,"/");i=e.selection.getContent(),0===i.length&&"A"===e.selection.getNode().nodeName&&(i=e.selection.getNode().textContent),h=a.name+" ("+c.formatSize(a.size)+")","file"===d.filetype&&b(f,{text:i||h,title:h}),"image"===d.filetype&&b(f,{alt:h}),"media"===d.filetype&&b(f)}}),!1},Charcoal.Admin.Property_Input_Tinymce.prototype.set_editor=function(a){return this._editor=a,this},Charcoal.Admin.Property_Input_Tinymce.prototype.editor=function(){return this._editor},Charcoal.Admin.Property_Input_Tinymce.prototype.destroy=function(){var a=this.editor();a&&a.remove()},Charcoal.Admin.Template=function(a){window.alert("Template "+a)},Charcoal.Admin.Template_Login=function(a){this.template_type="charcoal/admin/template/login",this.init(a)},Charcoal.Admin.Template_Login.prototype=Object.create(Charcoal.Admin.Template.prototype),Charcoal.Admin.Template_Login.prototype.constructor=Charcoal.Admin.Template_Login,Charcoal.Admin.Template_Login.prototype.parent=Charcoal.Admin.Template.prototype,Charcoal.Admin.Template_Login.prototype.init=function(a){window.console.debug(a),this.bind_events()},Charcoal.Admin.Template_Login.prototype.bind_events=function(){$("#login-form").on("submit.charcoal.login",function(a){a.preventDefault();var b=$(this),c=b.prop("action")||window.location.href,d=b.serialize();$.post(c,d,function(a){window.console.debug(a),a.success?window.location.href=a.next_url:BootstrapDialog.show({title:authL10n.login,message:commonL10n.authFailed,type:BootstrapDialog.TYPE_DANGER})},"json").fail(function(){BootstrapDialog.show({title:authL10n.login,message:commonL10n.authFailed,type:BootstrapDialog.TYPE_DANGER})})})},Charcoal.Admin.Template_MenuHeader=function(){$(".js-toggle-class").click(function(a){a.preventDefault();var b=$(this),c=b.data("class"),d=b.data("target");$(d).toggleClass(c)}),$(document).on("click",".js-accordion-header",function(a){a.preventDefault(),$(this).toggleClass("is-open").siblings(".js-accordion-content").stop().slideToggle()})},Charcoal.Admin.Template_Account_LostPassword=function(a){this.template_type="charcoal/admin/template/account/lost-password",this.init(a)},Charcoal.Admin.Template_Account_LostPassword.prototype=Object.create(Charcoal.Admin.Template.prototype),Charcoal.Admin.Template_Account_LostPassword.prototype.constructor=Charcoal.Admin.Template_Account_LostPassword,Charcoal.Admin.Template_Account_LostPassword.prototype.parent=Charcoal.Admin.Template.prototype,Charcoal.Admin.Template_Account_LostPassword.prototype.init=function(a){window.console.debug(a),this.bind_events()},Charcoal.Admin.Template_Account_LostPassword.prototype.bind_events=function(){$("#lost-password-form").on("submit.charcoal.password",function(a){a.preventDefault();var b=$(this),c=b.prop("action")||window.location.href,d=b.serialize();$.post(c,d,function(a){window.console.debug(a),BootstrapDialog.show({title:authL10n.lostPassword,message:authL10n.lostPassSuccess,type:BootstrapDialog.TYPE_SUCCESS,onhidden:function(){window.location.reload()}})},"json").fail(function(){BootstrapDialog.show({title:authL10n.lostPassword,message:authL10n.lostPassFailed,type:BootstrapDialog.TYPE_DANGER,onhidden:function(){window.grecaptcha.reset()}})})})},Charcoal.Admin.Template_Account_ResetPassword=function(a){this.template_type="charcoal/admin/template/account/reset-password",this.init(a)},Charcoal.Admin.Template_Account_ResetPassword.prototype=Object.create(Charcoal.Admin.Template.prototype),Charcoal.Admin.Template_Account_ResetPassword.prototype.constructor=Charcoal.Admin.Template_Account_ResetPassword,Charcoal.Admin.Template_Account_ResetPassword.prototype.parent=Charcoal.Admin.Template.prototype,Charcoal.Admin.Template_Account_ResetPassword.prototype.init=function(a){window.console.debug(a),this.bind_events()},Charcoal.Admin.Template_Account_ResetPassword.prototype.bind_events=function(){$("#reset-password-form").on("submit.charcoal.password",function(a){a.preventDefault();var b=$(this),c=b.prop("action")||window.location.href,d=b.serialize();$.post(c,d,function(a){window.console.debug(a),BootstrapDialog.show({title:authL10n.passwordReset,message:authL10n.resetPassSuccess,type:BootstrapDialog.TYPE_SUCCESS,onhidden:function(){window.location.href=Charcoal.Admin.admin_url()+"login"}})},"json").fail(function(){BootstrapDialog.show({title:authL10n.passwordReset,message:authL10n.resetPassFailed,type:BootstrapDialog.TYPE_DANGER,onhidden:function(){window.grecaptcha.reset()}})})})}; \ No newline at end of file +$.fn.enable=function(){return this.each(function(){$(this).removeAttr("disabled").prop("disabled",!1)}),this},$.fn.disable=function(){return this.each(function(){$(this).attr("disabled",!0).prop("disabled",!0)}),this},RegExp.escape||(RegExp.escape=function(a){return a.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&")}),Array.prototype.find||Object.defineProperty(Array.prototype,"find",{value:function(a){if(null==this)throw new TypeError('"this" is null or not defined');if("function"!=typeof a)throw new TypeError("predicate must be a function");for(var b=Object(this),c=b.length>>>0,d=arguments[1],e=0;e1&&(d.forEach(function(a,b){d[b]=a.charAt(0).toUpperCase()+a.slice(1)}),a=d.join("_")),c[b]=a.charAt(0).toUpperCase()+a.slice(1)}),a=b.join("_")},a.parseNumber=function(a){return/^(\-|\+)?([0-9]+(\.[0-9]+)?|Infinity)$/.test(a)?Number(a):a},a.loadScript=function(a,b){this.cache(a,function(b){$.ajax({url:a,dataType:"script",success:b.resolve,error:b.reject})}).then(b)},a.cache=function(a,b,c){return this.cachePool[a]||"function"==typeof b&&(this.cachePool[a]=$.Deferred(function(a){b(a)}).promise()),"function"==typeof this.cachePool[a]?this.cachePool[a].done(c):this.cachePool[a]},a.parseJqXhrArgs=function(){var a={failed:!0,jqXHR:null,textStatus:"",errorThrown:"",response:null};return arguments[2]&&"string"===$.type(arguments[2])?(a.jqXHR=arguments[0]||null,a.textStatus=arguments[1]||null,a.errorThrown=arguments[2]||null,a.response=arguments[3]||a.jqXHR.responseJSON||null,"object"===$.type(a.response)?a.failed=!a.response.success:a.failed=!0):(a.response=arguments[0]||null,a.textStatus=arguments[1]||null,a.jqXHR=arguments[2]||null,a.errorThrown=null,null===a.response&&(a.response=a.jqXHR.responseJSON),"object"===$.type(a.response)?a.failed=!a.response.success:a.failed=!1),a},a}(),function(a,b,c){"use strict";var d=a(b),e=a.Deferred(),f=1,g=function(){this.isReady=!1,this.components={},d.on("ready",a.proxy(this.render,this))};g.prototype.add_property_input=function(a){this.add_component("property_inputs",a)},g.prototype.add_widget=function(a){this.add_component("widgets",a)},g.prototype.add_template=function(a){this.add_component("templates",a)},g.prototype.add_component=function(a,b){var c=Charcoal.Admin.get_object_name(b.type);"function"==typeof Charcoal.Admin[c]?(b.ident=c,this.components[a]=this.components[a]||[],this.components[a].push(b)):console.error("Was not able to store "+c+" in "+a+" sub-array")},g.prototype.get_property_input=function(a){return this.get_component("property_inputs",a)},g.prototype.get_widget=function(a){return this.get_component("widgets",a)},g.prototype.get_template=function(a){return this.get_component("templates",a)},g.prototype.get_component=function(a,b){if(!this.isReady)throw new Error("Components must be rendered.");if(a in this.components)return this.components[a].find(function(a){return a._id===b})},g.prototype.ready=function(a){return e.promise().done(a),this},g.prototype.render=function(){var b=a.Event("render.charcoal.components",{relatedTarget:this});if(d.trigger(b),!b.isDefaultPrevented()){for(var c in this.components){var g=Charcoal;switch(c){case"widgets":g=Charcoal.Admin.Widget;break;case"property_inputs":g=Charcoal.Admin.Property;break;case"templates":g=Charcoal.Admin.Template}for(var h=0,i=this.components[c].length;h0)){e.resolveWith(this);var l=a.Event("rendered.charcoal.components",{relatedTarget:this});return d.trigger(l),this}}},g.prototype.prepare_submit=function(){return this.prepare_inputs(),this.prepare_widgets(),!0},g.prototype.prepare_inputs=function(){var a=void 0!==this.components.property_inputs?this.components.property_inputs:[];if(!a.length)return!0;for(var b,c=a.length,d=0;d=0;h--)d=b.alias[h],g[d]=c;return this},k.prototype.push=function(){var b=arguments[0],c=arguments;this.validContext(b)?c=h.slice.call(arguments,1):b="global";for(var d,e=0;e0},k.prototype.getMessagesMap=function(){if(!this.hasMessages())return{};for(var a,b,c=this.getMessages(),d={},e=0;e"+d[a].join("

")+"

",type:b.type,buttons:c})}return this.empty(),this},k.prototype.call=k.prototype.dispatch,k.prototype.empty=function(){i(),this.actions=[],this.storage=[]},k.prototype.reset=k.prototype.empty;var l=function(a,c){if(b.feedback(),!this.validLevel(a))throw new TypeError("Feedback level required. Must be one of: "+e.join(", "));return this.setLevel(a),this.validMessage(c)&&this.setMessage(c),this};l.createFromObject=function(a){var b=a.level||null,c=a.message||a.msg||null;return b||c?new l(b,c):null},l.prototype={toString:function(){return this.message()},level:function(){return this._level||null},setLevel:function(b){var c=a.type(b);if("string"!==c)throw new TypeError("Feedback level must be a string, received "+c);if(-1===a.inArray(b,e))throw new TypeError('Unsupported feedback level, received "'+b+'". Must be one of: '+e.join(", "));return b in g&&(b=g[b]),this._level=b,this},validLevel:function(b){return"string"===a.type(b)&&a.inArray(b,e)>-1},message:function(){return this._message||null},setMessage:function(b){var c=a.type(b);if("string"!==c)throw new TypeError("Feedback message must be a string, received "+c);return this._message=b,this},validMessage:function(b){return"string"===a.type(b)}},i(),b.Feedback=k,b.FeedbackEntry=l}(jQuery,Charcoal.Admin,document),Charcoal.Admin.Widget=function(a){return this._element=void 0,this._id=void 0,this._type=void 0,this._opts=void 0,a?("string"==typeof a.id&&(this.set_element($("#"+a.id)),this.set_id(a.id),this.widget_id=a.widget_id||a.id),"string"==typeof a.type&&(this.set_type(a.type),this.widget_type=a.widget_type||a.type),this.set_opts(a),this):this},Charcoal.Admin.Widget.prototype.set_opts=function(a){return this._opts=a,this},Charcoal.Admin.Widget.prototype.add_opts=function(a,b){return"string"==typeof a&&(this._opts[a]=b),this},Charcoal.Admin.Widget.prototype.opts=function(a){return"string"==typeof a?void 0!==this._opts[a]&&this._opts[a]:this._opts},Charcoal.Admin.Widget.prototype.init=function(){return this},Charcoal.Admin.Widget.prototype.set_id=function(a){this._id=a},Charcoal.Admin.Widget.prototype.id=function(){return this._id},Charcoal.Admin.Widget.prototype.set_type=function(a){this._type=a},Charcoal.Admin.Widget.prototype.type=function(){return this._type},Charcoal.Admin.Widget.prototype.set_element=function(a){return this._element=a,this},Charcoal.Admin.Widget.prototype.element=function(){return this._element},Charcoal.Admin.Widget.prototype.widget_options=function(){return this.opts()},Charcoal.Admin.Widget.prototype.widget_type=function(){return this.type()},Charcoal.Admin.Widget.prototype.save=function(){return!0},Charcoal.Admin.Widget.prototype.anim_out=function(a){return"function"!=typeof a&&(a=function(){}),this.element().fadeOut(400,a),this},Charcoal.Admin.Widget.prototype.reload=function(a){var b=this,c=Charcoal.Admin.admin_url()+"widget/load",d={widget_type:b.widget_type||b.type(),widget_options:b.widget_options()};$.ajax({type:"POST",url:c,data:JSON.stringify(d),dataType:"json",contentType:"application/json",success:function(c){if("string"==typeof c.widget_id){var d=c.widget_id;b.set_id(d),b.add_opts("id",d),b.add_opts("widget_id",d),b.widget_id=d,b.anim_out(function(){b.element().replaceWith(c.widget_html),b.set_element($("#"+b.id())),b.element().hide().fadeIn(),b.init()})}"function"==typeof a&&a.call(b,c)}})},Charcoal.Admin.Widget.prototype.dialog=function(a,b){var c=a.title||"",d=a.type||BootstrapDialog.TYPE_DEFAULT,e=a.size||BootstrapDialog.SIZE_NORMAL,f=a.cssClass||"",g=a.showHeader||!0,h=a.showFooter||!0,i=a.dialog_options||{};delete a.title,delete a.type,delete a.size,delete a.cssClass,delete a.dialog_options;var j={title:c,type:d,size:e,cssClass:f,nl2br:!1,showHeader:g,showFooter:h,onshown:function(){Charcoal.Admin.manager().render()}},k=$.extend({},j,i),l='';return k.message=function(c){var d,e=Charcoal.Admin.admin_url()+"widget/load",f=a,i=$(l.replaceMap({"{type}":"warning","{text}":widgetL10n.loading}));return g||c.getModalHeader().addClass("hidden"),h||c.getModalFooter().addClass("hidden"),c.getModalBody().on("click.charcoal.bs.dialog",'[data-dismiss="dialog"]',{dialog:c},function(a){a.data.dialog.close()}),d=$.ajax({method:"POST",url:e,data:f,dataType:"json"}),d.then(function(a,b,c){return a&&a.success?$.Deferred().resolve(a,b,c):a.feedbacks?$.Deferred().reject(c,b,a.feedbacks):$.Deferred().reject(c,b,widgetL10n.loadingFailed)}).done(function(a){c.setMessage(a.widget_html),"function"==typeof b&&b(a),$('[data-toggle="tooltip"]',c.getModalBody()).tooltip()}).fail(function(a,b,d){c.setType(BootstrapDialog.TYPE_DANGER),c.setMessage(widgetL10n.loadingFailed);var e="";"string"===$.type(d)&&a.responseJSON&&a.responseJSON.feedbacks&&(d=a.responseJSON.feedbacks),$.isArray(d)?$.each(d,function(a,b){b.message&&("error"===b.level&&(b.level="danger"),e+=l.replaceMap({"{type}":b.level,"{text}":b.message}))}):"string"===$.type(d)&&(e=l.replaceMap({"{type}":"danger","{text}":d})),e&&c.setMessage(e),$('[data-toggle="tooltip"]',c.getModalBody()).tooltip()}),i},new BootstrapDialog.show(k)},Charcoal.Admin.Widget.prototype.confirm=function(a,b,c){var d={type:BootstrapDialog.TYPE_DANGER,callback:function(a){a?"function"==typeof b&&b():"function"==typeof c&&c()}},e=$.extend(d,a);BootstrapDialog.confirm(e)},Charcoal.Admin.Widget_Attachment=function(){this.glyphs={embed:"glyphicon-blackboard",video:"glyphicon-film",image:"glyphicon-picture",file:"glyphicon-file",link:"glyphicon-link",text:"glyphicon-font",gallery:"glyphicon-duplicate",container:"glyphicon-list",accordion:"glyphicon-list"};var a=this;return $(document).on("switch_language.charcoal",function(){var b=a.opts();b.widget_options.lang=Charcoal.Admin.lang(),a.set_opts(b),a.reload()}),this.dirty=!1,this},Charcoal.Admin.Widget_Attachment.prototype=Object.create(Charcoal.Admin.Widget.prototype),Charcoal.Admin.Widget_Attachment.prototype.constructor=Charcoal.Admin.Widget_Attachment,Charcoal.Admin.Widget_Attachment.prototype.parent=Charcoal.Admin.Widget.prototype,Charcoal.Admin.Widget_Attachment.prototype.init=function(){var a=this.element().find(".js-attachment-sortable > .js-grid-container");return a.length&&(this.element().on("hidden.bs.collapse",'[data-toggle="collapse"]',function(){a.sortable("refreshPositions")}),a.sortable({handle:'[draggable="true"]',placeholder:"panel c-attachment_placeholder",start:function(a,b){b.item.children(".panel-heading").find('[data-toggle="collapse"]').hasClass("collapsed")||b.item.children(".panel-collapse").collapse("hide")}}).disableSelection()),this.listeners(),this},Charcoal.Admin.Widget_Attachment.prototype.is_dirty=function(){return this.dirty},Charcoal.Admin.Widget_Attachment.prototype.set_dirty_state=function(a){return this.dirty=a,this},Charcoal.Admin.Widget_Attachment.prototype.listeners=function(){var a=this,b=this.element().find(".c-attachments_container > .js-grid-container");this.element().off("click").on("click.charcoal.attachments",".js-attachments-collapse",function(){var a=b.children(".js-attachment");b.hasClass("js-attachment-preview-only")&&a.children(".panel-heading.sr-only").removeClass("sr-only").addClass("sr-only-off"),a.children(".panel-collapse.in").collapse("hide")}).on("click.charcoal.attachments",".js-attachments-expand",function(){var a=b.children(".js-attachment");b.hasClass("js-attachment-preview-only")&&a.children(".panel-heading.sr-only-off").removeClass("sr-only-off").addClass("sr-only"),a.children(".panel-collapse:not(.in)").collapse("show")}).on("click.charcoal.attachments",".js-add-attachment",function(b){b.preventDefault();var c=$(this).data("type");if(!c)return!1;var d=$(this).data("id");if(d)a.add({id:d,type:c}),a.join(function(){a.reload()});else{var e=$(this).data("title")||attachmentWidgetL10n.editObject,f=$(this).data("skip-form");a.create_attachment(c,0,null,{title:e,skipForm:f},function(b){b.success&&(b.obj.id=b.obj_id,a.add(b.obj),a.join(function(){a.reload()}))})}}).on("click.charcoal.attachments",".js-attachment-actions a",function(b){var c=$(this);if(c.data("action")){b.preventDefault();switch(c.data("action")){case"edit":var d=c.data("type"),e=c.data("id");if(!d||!e)break;var f=c.data("title")||attachmentWidgetL10n.editObject;a.create_attachment(d,e,null,{title:f},function(b){b.success&&a.reload()});break;case"delete":if(!c.data("id"))break;a.confirm({title:attachmentWidgetL10n.confirmRemoval,message:commonL10n.confirmAction,btnOKLabel:commonL10n.removeObject,callback:function(b){b&&a.remove_join(c.data("id"),function(){a.reload()})}});break;case"add-object":var g=c.data("title"),h=c.data("attachment"),i=c.data("type"),j=c.data("id"),k=c.data("group"),l=c.data("skip-form"),m={id:j,type:i,group:k,skipForm:l};a.create_attachment(h,0,{title:g},m,function(b){b.success&&a.add_object_to_container({id:b.obj_id,type:b.obj.type},m)})}}})},Charcoal.Admin.Widget_Attachment.prototype.select_attachment=function(a){if(!a.data("id")||!a.data("type"))return this},Charcoal.Admin.Widget_Attachment.prototype.create_attachment=function(a,b,c,d,e){b||(b=0),d||(d={});var f=this;if(!c){var g=f.opts();c={obj_type:g.data.obj_type,obj_id:g.data.obj_id,group:g.data.group}}if(d.skipForm)return this.xhr=$.ajax({type:"POST",url:"object/save",data:{obj_type:a,obj_id:b,pivot:c}}),this.xhr.done(function(a){a.feedbacks&&Charcoal.Admin.feedback(a.feedbacks).dispatch(),e(a)}),void Charcoal.Admin.manager().render();var h={size:BootstrapDialog.SIZE_WIDE,cssClass:"-quick-form",widget_type:"charcoal/admin/widget/quickForm",widget_options:{obj_type:a,obj_id:b,form_data:{pivot:c}}},i={},j=$.extend({},h,d,i),k=this.dialog(j,function(c){if(c.success){if(!c.widget_id)return!1;Charcoal.Admin.manager().add_widget({id:c.widget_id,type:"charcoal/admin/widget/quick-form",data:{obj_type:a},obj_id:b,save_callback:function(a){e(a),k.close()}}),Charcoal.Admin.manager().render()}})},Charcoal.Admin.Widget_Attachment.prototype.add_object_to_container=function(a,b,c){var d=this,e={obj_type:b.type,obj_id:b.id,attachments:[{attachment_id:a.id,attachment_type:a.type,position:0}],group:c||b.group||""};$.post("add-join",e,function(){d.reload()},"json")},Charcoal.Admin.Widget_Attachment.prototype.add=function(a){if(!a)return!1;this.set_dirty_state(!0);var b=this.element().find(".js-attachment-template").clone();return b.find(".js-attachment").data("id",a.id).data("type",a.type),this.element().find(".c-attachments_container > .js-grid-container").append(b),this},Charcoal.Admin.Widget_Attachment.prototype.save=function(){if(this.is_dirty())return!1;this.join()},Charcoal.Admin.Widget_Attachment.prototype.join=function(a){var b=this,c=b.opts(),d={obj_type:c.data.obj_type,obj_id:c.data.obj_id,attachments:[],group:c.data.group};this.element().find(".c-attachments_container").find(".js-attachment").each(function(a){var b=$(this),c=b.data("id"),e=b.data("type");d.attachments.push({attachment_id:c,attachment_type:e,position:a})}),$.post("join",d,function(){"function"==typeof a&&a(),b.set_dirty_state(!1)},"json")},Charcoal.Admin.Widget_Attachment.prototype.remove_join=function(a,b){if(!a)return!1;var c=this,d=c.opts(),e={obj_type:d.data.obj_type,obj_id:d.data.obj_id,attachment_id:a,group:d.data.group};$.post("remove-join",e,function(){"function"==typeof b&&b(),c.set_dirty_state(!1)},"json")},Charcoal.Admin.Widget_Attachment.prototype.widget_options=function(){return this.opts("widget_options")},Charcoal.Admin.Widget_Form=function(a){this.widget_type="charcoal/admin/widget/form",this.widget_id=null,this.obj_type=null,this.obj_id=null,this.save_action="object/save",this.update_action="object/update",this.form_selector=null,this.form_working=!1,this.submitted_via=null,this.suppress_feedback=!1,this.is_new_object=!1,this.xhr=null;var b=Charcoal.Admin.queryParams();"tab_ident"in b&&$('.js-group-tabs[data-tab-ident="'+b.tab_ident+'"]').tab("show");var c=$("[data-lang]:not(.hidden)").data("lang");c&&Charcoal.Admin.setLang(c),this.set_properties(a).bind_events()},Charcoal.Admin.Widget_Form.prototype=Object.create(Charcoal.Admin.Widget.prototype),Charcoal.Admin.Widget_Form.prototype.constructor=Charcoal.Admin.Widget_Form,Charcoal.Admin.Widget_Form.prototype.parent=Charcoal.Admin.Widget.prototype,Charcoal.Admin.Widget_Form.prototype.set_properties=function(a){return this.widget_id=a.id||this.widget_id,this.obj_type=a.data.obj_type||this.obj_type,this.obj_id=Charcoal.Admin.parseNumber(a.data.obj_id||this.obj_id),this.form_selector=a.data.form_selector||this.form_selector,this.isTab=a.data.tab,this},Charcoal.Admin.Widget_Form.prototype.bind_events=function(){var a=this,b=$(".c-form-sidebar",this.form_selector);$(a.form_selector).on("submit.charcoal.form",function(b){console.log("form.submit",b),b.preventDefault(),a.submit_form(this)}).find(":submit").on("click.charcoal.form",function(b){console.log("click.submit",b),a.submitted_via=this}),$(".js-obj-delete",b).on("click.charcoal.form",function(b){b.preventDefault(),a.delete_object(this)}),$(".js-reset-form",b).on("click.charcoal.form",function(b){b.preventDefault(),$(a.form_selector)[0].reset()}),$(".js-lang-switch button",b).on("click.charcoal.form",function(b){b.preventDefault();var c=$(this),d=c.attr("data-lang-switch");a.switch_language(d)})},Charcoal.Admin.Widget_Form.prototype.submit_form=function(a){if(!this.form_working){this.form_working=!0,this.is_new_object=!this.obj_id;var b,c,d;if(c=$(a),b=c.find('[type="submit"]'),b.prop("disabled"))return!1;Charcoal.Admin.manager().prepare_submit(),d=new FormData(a),this.submitted_via&&this.submitted_via.name&&d.append(this.submitted_via.name,this.submitted_via.value||!0),this.disable_form(c,b),this.xhr=$.ajax({type:"POST",url:this.request_url(),data:d,dataType:"json",processData:!1,contentType:!1}),this.xhr.then($.proxy(this.request_done,this,c,b)).done($.proxy(this.request_success,this,c,b)).fail($.proxy(this.request_failed,this,c,b)).always($.proxy(this.request_complete,this,c,b))}},Charcoal.Admin.Widget_Form.prototype.request_done=function(a,b,c,d,e){return c&&c.success?$.Deferred().resolve(c,d,e):c.feedbacks?$.Deferred().reject(e,d,c.feedbacks):$.Deferred().reject(e,d,commonL10n.errorOccurred)},Charcoal.Admin.Widget_Form.prototype.request_success=function(a,b,c){if(c.feedbacks&&Charcoal.Admin.feedback(c.feedbacks),c.next_url&&Charcoal.Admin.feedback().add_action({label:commonL10n.continue,callback:function(){window.location.href=Charcoal.Admin.admin_url()+c.next_url}}),this.is_new_object)if(this.suppress_feedback=!0,c.next_url)window.location.href=Charcoal.Admin.admin_url()+c.next_url;else{var d=new URLSearchParams(window.location.search);window.location.href=Charcoal.Admin.admin_url()+"object/edit?"+(d.has("main_menu")?"main_menu="+d.get("main_menu")+"&":"")+(d.has("sidemenu")?"sidemenu="+d.get("sidemenu")+"&":"")+"obj_type="+this.obj_type+"&obj_id="+c.obj_id}},Charcoal.Admin.Widget_Form.prototype.request_failed=function(a,b,c,d,e){if(c.responseJSON&&c.responseJSON.feedbacks)Charcoal.Admin.feedback(c.responseJSON.feedbacks);else{var f=this.is_new_object?formWidgetL10n.createFailed:formWidgetL10n.updateFailed,g=e||commonL10n.errorOccurred;Charcoal.Admin.feedback([{message:commonL10n.errorTemplate.replaceMap({"[[ errorMessage ]]":f,"[[ errorThrown ]]":g}),level:"error"}])}},Charcoal.Admin.Widget_Form.prototype.request_complete=function(a,b){this.suppress_feedback||(Charcoal.Admin.feedback().dispatch(),this.enable_form(a,b)),this.submitted_via=null,this.form_working=this.is_new_object=this.suppress_feedback=!1},Charcoal.Admin.Widget_Form.prototype.disable_form=function(a,b){return a&&a.prop("disabled",!0),b&&b.prop("disabled",!0),this.submitted_via&&this.disable_button(this.submitted_via),this},Charcoal.Admin.Widget_Form.prototype.enable_form=function(a,b){return a&&a.prop("disabled",!1),b&&b.prop("disabled",!1),this.submitted_via&&this.enable_button(this.submitted_via),this},Charcoal.Admin.Widget_Form.prototype.disable_button=function(a){return a instanceof jQuery||(a=$(a)),a.prop("disabled",!0).children(".glyphicon").removeClass("hidden").next(".btn-label").addClass("sr-only"),this},Charcoal.Admin.Widget_Form.prototype.enable_button=function(a){return a instanceof jQuery||(a=$(a)),a.prop("disabled",!1).children(".glyphicon").addClass("hidden").next(".btn-label").removeClass("sr-only"),this},Charcoal.Admin.Widget_Form.prototype.request_url=function(){return this.is_new_object?Charcoal.Admin.admin_url()+this.save_action:Charcoal.Admin.admin_url()+this.update_action},Charcoal.Admin.Widget_Form.prototype.delete_object=function(){var a=this,b=new URLSearchParams(window.location.search),c=Charcoal.Admin.admin_url()+"object/collection?"+(b.has("main_menu")?"main_menu="+b.get("main_menu")+"&":"")+(b.has("sidemenu")?"sidemenu="+b.get("sidemenu")+"&":"")+"obj_type="+this.obj_type;BootstrapDialog.confirm({title:formWidgetL10n.confirmDeletion,type:BootstrapDialog.TYPE_DANGER,message:$("

"+commonL10n.confirmAction+"

"+commonL10n.cantUndo+"

"),btnOKLabel:commonL10n.delete,callback:function(b){if(b){var d=Charcoal.Admin.admin_url()+"object/delete",e={obj_type:a.obj_type,obj_id:a.obj_id};$.ajax({method:"POST",url:d,data:e,dataType:"json"}).done(function(a){a.success?window.location.href=c:window.alert(formWidgetL10n.deleteFailed)})}}})},Charcoal.Admin.Widget_Form.prototype.switch_language=function(a){Charcoal.Admin.lang()!==a&&(Charcoal.Admin.setLang(a),$("[data-lang][data-lang!="+a+"]").addClass("hidden"),$("[data-lang][data-lang="+a+"]").removeClass("hidden"),$("[data-lang-switch][data-lang-switch!="+a+"]").removeClass("btn-info").addClass("btn-default"),$("[data-lang-switch][data-lang-switch="+a+"]").removeClass("btn-default").addClass("btn-info"),$(document).triggerHandler({type:"switch_language.charcoal"}))},Charcoal.Admin.Widget_Map=function(){return this._controller=void 0,this.widget_type="charcoal/admin/widget/map",this},Charcoal.Admin.Widget_Map.prototype=Object.create(Charcoal.Admin.Widget.prototype),Charcoal.Admin.Widget_Map.prototype.constructor=Charcoal.Admin.Widget_Map,Charcoal.Admin.Widget_Map.prototype.parent=Charcoal.Admin.Widget.prototype,Charcoal.Admin.Widget_Map.prototype.init=function(){var a=this;return"undefined"==typeof google?(window._tmp_google_onload_function=function(){a.activate_map()},$.getScript("https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false&language=fr&callback=_tmp_google_onload_function",function(){})):a.activate_map(),this},Charcoal.Admin.Widget_Map.prototype.activate_map=function(){var a={strokeColor:"#000000",strokeOpacity:.8,strokeWeight:3,fillColor:"#ffffff",fillOpacity:.35,hover:{strokeColor:"#000000",strokeOpacity:1,strokeWeight:2,fillColor:"#ffffff",fillOpacity:.5},focused:{fillOpacity:.8}},b={default_styles:a,use_clusterer:!1,map:{center:{x:this.opts("coords")[0],y:this.opts("coords")[1]},zoom:14,mapType:"roadmap",coordsType:"inpage",map_mode:"default"},places:{first:{type:"marker",coords:this.coords()}}};this._controller=new window.BB.gmap.controller(this.element().find(".js-map-maker-map").get(0),b),this.controller().set_styles([{featureType:"poi",elementType:"all",stylers:[{visibility:"off"}]}]),this.controller().remove_focus(),this.controller().init()},Charcoal.Admin.Widget_Map.prototype.controller=function(){return this._controller},Charcoal.Admin.Widget_Map.prototype.coords=function(){return this.opts("coords")},Charcoal.Admin.Widget_Quick_Form=function(a){return this.widget_type="charcoal/admin/widget/quick-form",this.save_callback=a.save_callback||"",this.cancel_callback=a.cancel_callback||"",this.save_action=a.save_action||"object/save",this.update_action=a.update_action||"object/update",this.extra_form_data=a.extra_form_data||{},this.form_working=!1,this.suppress_feedback=a.suppress_feedback||!1,this.is_new_object=!1,this.xhr=null,this.obj_id=Charcoal.Admin.parseNumber(a.obj_id)||0,this},Charcoal.Admin.Widget_Quick_Form.prototype=Object.create(Charcoal.Admin.Widget.prototype),Charcoal.Admin.Widget_Quick_Form.prototype.constructor=Charcoal.Admin.Widget_Quick_Form,Charcoal.Admin.Widget_Quick_Form.prototype.parent=Charcoal.Admin.Widget.prototype,Charcoal.Admin.Widget_Quick_Form.prototype.init=function(){this.bind_events()},Charcoal.Admin.Widget_Quick_Form.prototype.bind_events=function(){var a=this;$(document).on("submit","#"+this.id(),function(b){b.preventDefault(),a.submit_form(this)}),$("#"+this.id()).on("click.charcoal.bs.dialog",'[data-dismiss="dialog"]',function(b){$.isFunction(a.cancel_callback)&&a.cancel_callback(b)})},Charcoal.Admin.Widget_Quick_Form.prototype.submit_form=function(a){if(!this.form_working){this.form_working=!0,this.is_new_object=!this.obj_id;var b,c,d;if(c=$(a),b=c.find('[type="submit"]'),b.prop("disabled"))return!1;Charcoal.Admin.manager().prepare_submit(),d=new FormData(a),this.disable_form(c,b);var e=this.extra_form_data;for(var f in e)e.hasOwnProperty(f)&&d.append(f,e[f]);this.xhr=$.ajax({type:"POST",url:this.request_url(),data:d,dataType:"json",processData:!1,contentType:!1}),this.xhr.then($.proxy(this.request_done,this,c,b)).done($.proxy(this.request_success,this,c,b)).fail($.proxy(this.request_failed,this,c,b)).always($.proxy(this.request_complete,this,c,b))}},Charcoal.Admin.Widget_Quick_Form.prototype.disable_form=Charcoal.Admin.Widget_Form.prototype.disable_form,Charcoal.Admin.Widget_Quick_Form.prototype.enable_form=Charcoal.Admin.Widget_Form.prototype.enable_form,Charcoal.Admin.Widget_Quick_Form.prototype.request_url=Charcoal.Admin.Widget_Form.prototype.request_url,Charcoal.Admin.Widget_Quick_Form.prototype.request_done=Charcoal.Admin.Widget_Form.prototype.request_done,Charcoal.Admin.Widget_Quick_Form.prototype.request_failed=Charcoal.Admin.Widget_Form.prototype.request_failed,Charcoal.Admin.Widget_Quick_Form.prototype.request_complete=Charcoal.Admin.Widget_Form.prototype.request_complete,Charcoal.Admin.Widget_Quick_Form.prototype.request_success=function(a,b,c){c.feedbacks&&!this.suppress_feedback&&Charcoal.Admin.feedback(c.feedbacks),c.next_url&&Charcoal.Admin.feedback().add_action({label:commonL10n.continue,callback:function(){window.location.href=Charcoal.Admin.admin_url()+c.next_url}}),this.enable_form(a,b),this.form_working=!1,"function"==typeof this.save_callback&&this.save_callback(c)}, +Charcoal.Admin.Widget_Relation=function(){return this.dirty=!1,this},Charcoal.Admin.Widget_Relation.prototype=Object.create(Charcoal.Admin.Widget.prototype),Charcoal.Admin.Widget_Relation.prototype.constructor=Charcoal.Admin.Widget_Relation,Charcoal.Admin.Widget_Relation.prototype.parent=Charcoal.Admin.Widget.prototype,Charcoal.Admin.Widget_Relation.prototype.init=function(){if("function"!=typeof $.fn.sortable){return Charcoal.Admin.loadScript("https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js",this.init.bind(this)),this}var a=this.element().find(".js-relation-sortable .js-grid-container");return this.element().on("hidden.bs.collapse",'[data-toggle="collapse"]',function(){a.sortable("refreshPositions")}),a.sortable({handle:'[draggable="true"]',placeholder:"panel c-attachment_placeholder",start:function(a,b){b.item.children(".panel-heading").find('[data-toggle="collapse"]').hasClass("collapsed")||b.item.children(".panel-collapse").collapse("hide")}}).disableSelection(),this.listeners(),this},Charcoal.Admin.Widget_Relation.prototype.is_dirty=function(){return this.dirty},Charcoal.Admin.Widget_Relation.prototype.set_dirty_state=function(a){return this.dirty=a,this},Charcoal.Admin.Widget_Relation.prototype.listeners=function(){var a=this;this.element().off("click").on("click.charcoal.relation",".js-add-relation",function(b){b.preventDefault();var c=$(this).data("type");if(!c)return!1;var d=$(this).data("id");if(d)a.add({id:d,type:c}),a.create_relation(function(){a.reload()});else{var e=$(this).data("title")||relationWidgetL10n.editObject;a.create_relation_dialog({title:e,widget_options:{form_data:{target_object_type:c,target_object_id:null}}},function(b){b.success&&(b.obj.id=b.obj_id,a.add(b.obj),a.create_relation(function(){a.reload()}))})}}).on("click.charcoal.relation",".js-relation-actions a",function(b){var c=$(this);if(c.data("action")){b.preventDefault();switch(c.data("action")){case"edit":var d=c.data("type"),e=c.data("id");if(!d||!e)break;var f=c.data("title")||relationWidgetL10n.editObject;a.create_relation_dialog({title:f,widget_options:{form_data:{target_object_type:d,target_object_id:null}}},function(b){b.success&&a.reload()});break;case"unlink":if(!c.data("id"))break;a.confirm({title:relationWidgetL10n.confirmRemoval,message:commonL10n.confirmAction,btnOKLabel:commonL10n.removeObject,callback:function(b){b&&a.remove_relation(c.data("id"),function(){a.reload()})}})}}})},Charcoal.Admin.Widget_Relation.prototype.create_relation_dialog=function(a,b){a=a||{};var c=this.opts().data,d={size:BootstrapDialog.SIZE_WIDE,cssClass:"-quick-form",widget_type:"charcoal/admin/widget/quickForm",widget_options:{obj_type:"charcoal/relation/pivot",obj_id:0,form_data:{group:c.group,source_object_type:c.obj_type,source_object_id:c.obj_id,target_object_type:"",target_object_id:0}}},e={},f=$.extend(!0,{},d,a,e),g=this.dialog(f,function(a){if(a.success){if(!a.widget_id)return!1;Charcoal.Admin.manager().add_widget({id:a.widget_id,type:"charcoal/admin/widget/quick-form",data:{obj_type:f.widget_options.type},obj_id:f.widget_options.id,save_callback:function(a){b(a),g.close()}}),Charcoal.Admin.manager().render()}})},Charcoal.Admin.Widget_Relation.prototype.add=function(a){if(!a)return!1;this.set_dirty_state(!0);var b=this.element().find(".js-relation-template").clone();return b.find(".js-relation").attr({"data-id":a.target_object_id,"data-type":a.target_object_type}),this.element().find(".js-relation-sortable").find(".js-grid-container").append(b),this},Charcoal.Admin.Widget_Relation.prototype.save=function(){if(this.is_dirty())return!1;this.create_relation()},Charcoal.Admin.Widget_Relation.prototype.create_relation=function(a){var b=this,c=b.opts(),d={obj_type:c.data.obj_type,obj_id:c.data.obj_id,group:c.data.group,pivots:[]};this.element().find(".js-relation-container").find(".js-relation").each(function(a){var b=$(this),c=b.attr("data-id"),e=b.attr("data-type");d.pivots.push({target_object_id:c,target_object_type:e,position:a})}),$.post("relation/link",d,function(){"function"==typeof a&&a(),b.set_dirty_state(!1)},"json")},Charcoal.Admin.Widget_Relation.prototype.remove_relation=function(a,b){if(!a)return!1;var c=this,d={pivot_id:a};$.post("relation/unlink",d,function(){"function"==typeof b&&b(),c.set_dirty_state(!1)},"json")},Charcoal.Admin.Widget_Relation.prototype.widget_options=function(){return this.opts("widget_options")},Charcoal.Admin.Widget_Search=function(a){return this._elem=void 0,!!a&&(void 0!==a.id&&(this.set_element($("#"+a.id)),"object"==typeof a.data&&(this.opts=a,this)))},Charcoal.Admin.Widget_Search.prototype=Object.create(Charcoal.Admin.Widget.prototype),Charcoal.Admin.Widget_Search.prototype.constructor=Charcoal.Admin.Widget_Search,Charcoal.Admin.Widget_Search.prototype.parent=Charcoal.Admin.Widget.prototype,Charcoal.Admin.Widget_Search.prototype.set_remote_widget=function(){},Charcoal.Admin.Widget_Search.prototype.init=function(){var a=this.element(),b=this;a.on("click",".js-search",function(a){a.preventDefault(),b.submit()}),a.on("click",".js-undo",function(a){a.preventDefault(),b.undo()})},Charcoal.Admin.Widget_Search.prototype.submit=function(){for(var a=Charcoal.Admin.manager(),b=a.components.widgets,c=0,d=b.length;c"+widgetL10n.loading+"");return a.getModalBody().on("click.charcoal.bs.dialog",'[data-dismiss="dialog"]',{dialog:a},function(a){a.data.dialog.close()}),$.ajax({method:"POST",url:b,data:c,dataType:"json"}).done(function(b){b.success?a.setMessage(b.widget_html):(a.setType(BootstrapDialog.TYPE_DANGER),a.setMessage(commonL10n.errorOccurred))}),d}})},Charcoal.Admin.Widget_Table.Table_Row=function(a,b){this.widget_table=a,this.element=b,this.obj_id=this.element.getAttribute("data-id"),this.obj_type=this.widget_table.obj_type,this.load_url=Charcoal.Admin.admin_url()+"widget/load",this.inline_url=Charcoal.Admin.admin_url()+"widget/table/inline",this.delete_url=Charcoal.Admin.admin_url()+"object/delete",this.bind_events()},Charcoal.Admin.Widget_Table.Table_Row.prototype.bind_events=function(){var a=this;$(".js-obj-quick-edit",a.element).on("click",function(b){b.preventDefault(),a.quick_edit()}),$(".js-obj-inline-edit",a.element).on("click",function(b){b.preventDefault(),a.inline_edit()}),$(".js-obj-delete",a.element).on("click",function(b){b.preventDefault(),a.delete_object()})},Charcoal.Admin.Widget_Table.Table_Row.prototype.quick_edit=function(){var a={widget_type:"charcoal/admin/widget/objectForm",widget_options:{obj_type:this.obj_type,obj_id:this.obj_id}};$.post(this.load_url,a,function(a){var b=BootstrapDialog.show({title:tableWidgetL10n.quickEdit,message:"…",nl2br:!1});b.getModalBody().on("click.charcoal.bs.dialog",'[data-dismiss="dialog"]',{dialog:b},function(a){a.data.dialog.close()}),a.success?b.setMessage(a.widget_html):(b.setType(BootstrapDialog.TYPE_DANGER),b.setMessage(commonL10n.errorOccurred))},"json")},Charcoal.Admin.Widget_Table.Table_Row.prototype.inline_edit=function(){var a=this,b={obj_type:a.obj_type,obj_id:a.obj_id};$.post(a.inline_url,b,function(b){if(b.success){var c,d=b.properties;for(c in d){$(a.element).find(".property-"+c).html(d[c])}}},"json")},Charcoal.Admin.Widget_Table.Table_Row.prototype.delete_object=function(){var a=this;BootstrapDialog.confirm({title:tableWidgetL10n.confirmDeletion,type:BootstrapDialog.TYPE_DANGER,message:$("

"+commonL10n.confirmAction+"

"+commonL10n.cantUndo+"

"),btnOKLabel:commonL10n.delete,callback:function(b){if(b){var c=a.delete_url,d={obj_type:a.obj_type,obj_id:a.obj_id};$.ajax({method:"POST",url:c,data:d,dataType:"json"}).done(function(b){b.success?$(a.element).remove():window.alert(tableWidgetL10n.deleteFailed)})}}})},Charcoal.Admin.Property=function(a){return this._ident=void 0,this._val=void 0,this._type=void 0,this._input_type=void 0,"string"==typeof a.ident&&this.set_ident(a.ident),void 0!==a.val&&this.set_val(a.val),void 0!==a.type&&this.set_type(a.type),void 0!==a.input_type&&this.set_input_type(a.input_type),this.data=a,this},Charcoal.Admin.Property.prototype.set_ident=function(a){this._ident=a},Charcoal.Admin.Property.prototype.set_val=function(a){this._val=a},Charcoal.Admin.Property.prototype.set_type=function(a){this._type=a},Charcoal.Admin.Property.prototype.set_input_type=function(a){this._input_type=a},Charcoal.Admin.Property.prototype.ident=function(){return this._ident},Charcoal.Admin.Property.prototype.val=function(){return this._val},Charcoal.Admin.Property.prototype.type=function(){return this._type},Charcoal.Admin.Property.prototype.input_type=function(){return this._input_type},Charcoal.Admin.Property.prototype.element=function(){if(!this._element){if(!this.data.id)return!1;this._element=$("#"+this.data.id)}return this._element},Charcoal.Admin.Property.prototype.validate=function(){},Charcoal.Admin.Property.prototype.save=function(){return this},Charcoal.Admin.Property.prototype.error=function(a){window.console.error(a)},Charcoal.Admin.Property_Input_Audio=function(a){a.input_type="charcoal/admin/property/input/audio",Charcoal.Admin.Property.call(this,a),this.text_properties={},this.recording_properties={},this.file_properties={},this.initialized_types=[],this.active_pane=a.data.active_pane||"text",this._recorder=void 0,this.init()},Charcoal.Admin.Property_Input_Audio.prototype=Object.create(Charcoal.Admin.Property.prototype),Charcoal.Admin.Property_Input_Audio.prototype.constructor=Charcoal.Admin.Property_Input_Audio,Charcoal.Admin.Property_Input_Audio.prototype.parent=Charcoal.Admin.Property.prototype,Charcoal.Admin.Property_Input_Audio.prototype.init=function(){var a=this.data;void 0===a.id&&console.error("Missing ID"),this.text_properties.$voice_message=$(".js-text-voice-message",this.element()),this.recording_properties.audio_context=null,this.recording_properties.audio_recorder=null,this.recording_properties.animation_frame=null,this.recording_properties.analyser_context=null,this.recording_properties.canvas_width=0,this.recording_properties.canvas_height=0,this.recording_properties.recording_index=0,this.recording_properties.current_recording=null,this.recording_properties.audio_player=null,this.recording_properties.hidden_input_id=a.data.hidden_input_id,this.recording_properties.$analyser_canvas=$(".js-recording-analyser",this.element()),this.recording_properties.$waves_canvas=$(".js-recording-waves",this.element()),this.recording_properties.record_button_class="js-recording-record",this.recording_properties.$record_button=$(".js-recording-record",this.element()),this.recording_properties.stop_button_class="js-recording-stop",this.recording_properties.$stop_button=$(".js-recording-stop",this.element()),this.recording_properties.playback_button_class="js-recording-playback",this.recording_properties.$playback_button=$(".js-recording-playback",this.element()),this.recording_properties.reset_button_class="js-recording-reset",this.recording_properties.$reset_button=$(".js-recording-reset",this.element()),this.recording_properties.$timer=$(".js-recording-timer",this.element()),this.file_properties.$file_audio=$(".js-file-audio",this.element()),this.file_properties.$file_reset=$(".js-file-reset",this.element()),this.file_properties.$file_input=$(".js-file-input",this.element()),this.file_properties.$file_input_hiden=$(".js-file-input-hidden",this.element()),this.file_properties.reset_button_class="js-file-reset",this.set_nav(this.active_pane).bind_nav_controls()},Charcoal.Admin.Property_Input_Audio.prototype.bind_nav_controls=function(){var a=this;this.element().on("click",".js-toggle-pane",function(){var b=$(this);a.set_nav(b.attr("data-pane"))})},Charcoal.Admin.Property_Input_Audio.prototype.set_nav=function(a){if(a){var b=$(".js-toggle-pane"),c=$(".js-pane"),d=c.filter('[data-pane="'+a+'"]');if(!d.hasClass("-active")){var e=b.filter('[data-pane="'+a+'"]');b.removeClass("-active"),e.addClass("-active"),c.removeClass("-active"),c.addClass("hidden"),d.removeClass("hidden"),d.addClass("-active"),this.prepare_pane(a)}}return this},Charcoal.Admin.Property_Input_Audio.prototype.prepare_pane=function(a){var b="init_"+a;"function"==typeof Charcoal.Admin.Property_Input_Audio.prototype[b]&&this[b]()},Charcoal.Admin.Property_Input_Audio.prototype.init_text=function(){if(-1===this.initialized_types.indexOf("text")){this.initialized_types.push("text");var a=this.text_properties.$voice_message.val();a=this.text_strip_tags(a),this.text_properties.$voice_message.val(a)}},Charcoal.Admin.Property_Input_Audio.prototype.text_strip_tags=function(a,b){b=((String(b)||"").toLowerCase().match(/<[a-z][a-z0-9]*>/g)||[]).join("");var c=/<\/?([a-z][a-z0-9]*)\b[^>]*>/gi,d=/|<\?(?:php)?[\s\S]*?\?>/gi;return a.replace(d,"").replace(c,function(a,c){return b.indexOf("<"+c.toLowerCase()+">")>-1?a:""})},Charcoal.Admin.Property_Input_Audio.prototype.init_file=function(){-1===this.initialized_types.indexOf("file")&&(this.initialized_types.push("file"),this.file_bind_events())},Charcoal.Admin.Property_Input_Audio.prototype.file_bind_events=function(){var a=this;a.element().on("click","."+a.file_properties.reset_button_class,function(){a.file_reset_input()})},Charcoal.Admin.Property_Input_Audio.prototype.file_reset_input=function(){this.file_properties.$file_audio.attr("src","").addClass("hide"),this.file_properties.$file_reset.addClass("hide"),this.file_properties.$file_input.removeClass("hide").wrap("").closest("form").get(0).reset(),this.file_properties.$file_input.unwrap(),this.file_properties.$file_input_hiden.val("")},Charcoal.Admin.Property_Input_Audio.prototype.init_recording=function(){if(-1===this.initialized_types.indexOf("recording")){var a=this;a.initialized_types.push("recording"),window.navigator.getUserMedia||(window.navigator.getUserMedia=window.navigator.webkitGetUserMedia||window.navigator.mozGetUserMedia),window.navigator.cancelAnimationFrame||(window.navigator.cancelAnimationFrame=window.navigator.webkitCancelAnimationFrame||window.navigator.mozCancelAnimationFrame),window.navigator.requestAnimationFrame||(window.navigator.requestAnimationFrame=window.navigator.webkitRequestAnimationFrame||window.navigator.mozRequestAnimationFrame),window.AudioContext||(window.AudioContext=window.AudioContext||window.webkitAudioContext),window.navigator.getUserMedia({audio:{mandatory:{googEchoCancellation:!1,googAutoGainControl:!1,googNoiseSuppression:!1,googHighpassFilter:!1},optional:[]}},function(b){a.recording_bind_events(),a.recording_got_stream(b)},function(a){window.alert(audioPropertyL10n.captureFailed+" "+commonL10n.errorOccurred),window.console.log(a)})}},Charcoal.Admin.Property_Input_Audio.prototype.recording_bind_events=function(){var a=this;a.element().on("click","."+a.recording_properties.record_button_class,function(){a.recording_manage_recorder()}),a.element().on("click","."+a.recording_properties.stop_button_class,function(){a.recording_manage_recorder("stop")}),a.element().on("click","."+a.recording_properties.playback_button_class,function(){0!==a.recording_properties.recording_index&&null!==a.recording_properties.audio_player&&a.recording_toggle_playback()}),a.element().on("click","."+a.recording_properties.reset_button_class,function(){a.recording_reset_audio()})},Charcoal.Admin.Property_Input_Audio.prototype.recording_got_stream=function(a){var b=this;b.recording_properties.audio_context=new window.AudioContext,b.recording_properties.audio_player=new window.Audio_Player({on_ended:function(){b.recording_manage_button_states("pause_playback")},on_timeupdate:function(a){b.recording_render_timer(a)},on_loadedmetadata:function(a){b.recording_render_timer(a)}});var c=b.recording_properties.audio_context.createGain(),d=b.recording_properties.audio_context.createMediaStreamSource(a),e=null;d.connect(c),window.analyserNode=b.recording_properties.audio_context.createAnalyser(),window.analyserNode.fftSize=2048,c.connect(window.analyserNode),b.recording_properties.audio_recorder=new window.Recorder(c),e=b.recording_properties.audio_context.createGain(),e.gain.value=0,c.connect(e),e.connect(b.recording_properties.audio_context.destination),b.recording_update_analysers()},Charcoal.Admin.Property_Input_Audio.prototype.recording_manage_button_states=function(a){switch(a){case"start_recording":this.recording_properties.$record_button.addClass("is-recording"),this.recording_properties.$stop_button.prop("disabled",!1),this.recording_properties.$playback_button.prop("disabled",!0),this.recording_properties.$reset_button.prop("disabled",!1);break;case"pause_recording":this.recording_properties.$record_button.removeClass("is-recording"),this.recording_properties.$stop_button.prop("disabled",!1),this.recording_properties.$playback_button.prop("disabled",!0),this.recording_properties.$reset_button.prop("disabled",!1);break;case"stop_recording":this.recording_properties.$record_button.removeClass("is-recording"),this.recording_properties.$stop_button.prop("disabled",!0),this.recording_properties.$playback_button.prop("disabled",!1),this.recording_properties.$reset_button.prop("disabled",!1);break;case"start_playback":this.recording_properties.$playback_button.addClass("is-playing");break;case"pause_playback":this.recording_properties.$playback_button.removeClass("is-playing");break;case"reset":this.recording_properties.$record_button.removeClass("is-recording"),this.recording_properties.$stop_button.prop("disabled",!0),this.recording_properties.$playback_button.prop("disabled",!0).removeClass("is-playing"),this.recording_properties.$reset_button.prop("disabled",!0)}},Charcoal.Admin.Property_Input_Audio.prototype.recording_render_timer=function(a){var b="";if(a){var c=0,d=0,e=a.duration-a.currentTime;c=Math.floor(e/60),d=Math.round(e)%60,b+=(c<10?"0":"")+String(c)+":",b+=(d<10?"0":"")+String(d)}else b="00:00";this.recording_properties.$timer.text(b)},Charcoal.Admin.Property_Input_Audio.prototype.recording_manage_recorder=function(a){var b=this;if("stop"===a)return b.recording_properties.audio_recorder.stop(),b.recording_properties.audio_recorder.get_buffers(function(a){b.recording_got_buffers(a),b.recording_properties.audio_recorder.clear(),b.recording_display_canvas("waves")}),void b.recording_manage_button_states("stop_recording");if(b.recording_properties.audio_recorder.is_recording())b.recording_properties.audio_recorder.stop(),b.recording_manage_button_states("pause_recording");else{if(!b.recording_properties.audio_recorder)return;b.recording_properties.audio_recorder.record(),b.recording_manage_button_states("start_recording"),b.recording_display_canvas("analyser")}},Charcoal.Admin.Property_Input_Audio.prototype.recording_toggle_playback=function(){if(this.recording_properties.audio_player.is_playing())this.recording_properties.audio_player.pause(),this.recording_manage_button_states("pause_playback");else{if(!this.recording_properties.audio_player)return;this.recording_properties.audio_player.play(),this.recording_manage_button_states("start_playback")}},Charcoal.Admin.Property_Input_Audio.prototype.recording_reset_audio=function(){var a=this.recording_properties.$analyser_canvas[0];a.getContext("2d").clearRect(0,0,a.canvas_width,a.canvas_height);var b=this.recording_properties.$waves_canvas[0];b.getContext("2d").clearRect(0,0,b.canvas_width,b.canvas_height),this.recording_properties.audio_player.load(),this.recording_properties.audio_player.src(""),this.recording_properties.audio_recorder.stop(),this.recording_properties.audio_recorder.clear(),this.recording_manage_button_states("reset"),this.recording_display_canvas("analyser"),this.recording_render_timer();var c=document.getElementById(this.recording_properties.hidden_input_id);c&&(c.value="")},Charcoal.Admin.Property_Input_Audio.prototype.recording_got_buffers=function(a){var b=this.recording_properties.$waves_canvas[0],c=this;c.recording_draw_buffer(b.width,b.height,b.getContext("2d"),a[0]),c.recording_properties.audio_recorder.export_wav(function(a){c.recording_done_encoding(a)})},Charcoal.Admin.Property_Input_Audio.prototype.recording_draw_buffer=function(a,b,c,d){var e=Math.ceil(d.length/a),f=b/2;c.fillStyle="#DDDDDD",c.clearRect(0,0,a,b);for(var g=0;gi&&(i=k)}c.fillRect(g,(1+h)*f,1,Math.max(1,(i-h)*f))}},Charcoal.Admin.Property_Input_Audio.prototype.recording_done_encoding=function(a){var b=new window.FileReader,c=null,d=this;b.readAsDataURL(a),b.onloadend=function(){c=b.result,d.recording_properties.recording_index++,d.recording_manage_audio_data(c)}},Charcoal.Admin.Property_Input_Audio.prototype.recording_manage_audio_data=function(a){if(a){var b=document.getElementById(this.recording_properties.hidden_input_id);b&&(b.value=a),this.recording_properties.audio_player.src(a),this.recording_properties.audio_player.load()}},Charcoal.Admin.Property_Input_Audio.prototype.recording_display_canvas=function(a){switch(a){case"waves":this.recording_properties.$analyser_canvas.addClass("hidden"),this.recording_properties.$waves_canvas.removeClass("hidden");break;default:this.recording_properties.$analyser_canvas.removeClass("hidden"),this.recording_properties.$waves_canvas.addClass("hidden")}},Charcoal.Admin.Property_Input_Audio.prototype.recording_cancel_analyser_update=function(){window.cancelAnimationFrame(this.recording_properties.animation_frame),this.recording_properties.animation_frame=null},Charcoal.Admin.Property_Input_Audio.prototype.recording_update_analysers=function(){this.recording_properties.analyser_context||(this.recording_properties.analyser_context=this.recording_properties.$analyser_canvas[0].getContext("2d"));var a=this,b=a.recording_properties.analyser_context,c=a.recording_properties.$analyser_canvas[0];if(a.recording_properties.canvas_width=c.width,a.recording_properties.canvas_height=c.height,b.lineCap="round",a.recording_properties.audio_recorder.is_recording()){var d=Math.round(a.recording_properties.canvas_width/5),e=new window.Uint8Array(window.analyserNode.frequencyBinCount),f=0;window.analyserNode.getByteFrequencyData(e),f=window.analyserNode.frequencyBinCount/d,b.clearRect(0,0,a.recording_properties.canvas_width,a.recording_properties.canvas_height);for(var g=0;g0},this.element=function(){return this._element};var c=this;c.element().addEventListener("ended",function(){c.callbacks.on_ended()}),c.element().addEventListener("pause",function(){c.callbacks.on_pause()}),c.element().addEventListener("playing",function(){c.callbacks.on_playing()}),c.element().addEventListener("timeupdate",function(){c.callbacks.on_timeupdate(c.element())}),c.element().addEventListener("loadedmetadata",function(){c.callbacks.on_loadedmetadata(c.element())})};a.Audio_Player=b}(window),Charcoal.Admin.Property_Input_ColorPicker=function(a){this.input_type="charcoal/admin/property/input/colorpicker",this.input_id=null,this.colorpicker_selector=null,this.colorpicker_options=null,this.set_properties(a).create_colorpicker()},Charcoal.Admin.Property_Input_ColorPicker.prototype=Object.create(Charcoal.Admin.Property.prototype),Charcoal.Admin.Property_Input_ColorPicker.prototype.constructor=Charcoal.Admin.Property_Input_ColorPicker,Charcoal.Admin.Property_Input_ColorPicker.prototype.parent=Charcoal.Admin.Property.prototype,Charcoal.Admin.Property_Input_ColorPicker.prototype.set_properties=function(a){this.input_id=a.id||this.input_id,this.colorpicker_selector=a.data.colorpicker_selector||this.colorpicker_selector,this.colorpicker_options=a.data.colorpicker_options||this.colorpicker_options;var b={};return this.colorpicker_options=$.extend({},b,this.colorpicker_options),this},Charcoal.Admin.Property_Input_ColorPicker.prototype.create_colorpicker=function(){return $(this.colorpicker_selector).minicolors(this.colorpicker_options),this},Charcoal.Admin.Property_Input_DateTimePicker=function(a){this.input_type="charcoal/admin/property/input/datetimepicker",this.input_id=null,this.datetimepicker_selector=null,this.datetimepicker_options=null,this.set_properties(a).create_datetimepicker()},Charcoal.Admin.Property_Input_DateTimePicker.prototype=Object.create(Charcoal.Admin.Property.prototype),Charcoal.Admin.Property_Input_DateTimePicker.prototype.constructor=Charcoal.Admin.Property_Input_DateTimePicker,Charcoal.Admin.Property_Input_DateTimePicker.prototype.parent=Charcoal.Admin.Property.prototype,Charcoal.Admin.Property_Input_DateTimePicker.prototype.set_properties=function(a){this.input_id=a.id||this.input_id,this.datetimepicker_selector=a.data.datetimepicker_selector||this.datetimepicker_selector,this.datetimepicker_options=a.data.datetimepicker_options||this.datetimepicker_options;var b={} +;return this.datetimepicker_options=$.extend({},b,this.datetimepicker_options),this},Charcoal.Admin.Property_Input_DateTimePicker.prototype.create_datetimepicker=function(){return $(this.datetimepicker_selector).datetimepicker(this.datetimepicker_options),this},Charcoal.Admin.Property_Input_DualSelect=function(a){this.input_type="charcoal/admin/property/input/dualselect",this.input_id=null,this.dualselect_selector=null,this.dualselect_options={},this._dualselect=null,this.set_properties(a).init()},Charcoal.Admin.Property_Input_DualSelect.prototype=Object.create(Charcoal.Admin.Property.prototype),Charcoal.Admin.Property_Input_DualSelect.prototype.constructor=Charcoal.Admin.Property_Input_DualSelect,Charcoal.Admin.Property_Input_DualSelect.prototype.parent=Charcoal.Admin.Property.prototype,Charcoal.Admin.Property_Input_DualSelect.prototype.init=function(){this.create_dualselect()},Charcoal.Admin.Property_Input_DualSelect.prototype.set_properties=function(a){this.input_id=a.id||this.input_id,this.dualselect_selector=a.dualselect_selector||a.data.dualselect_selector||this.dualselect_selector,this.dualselect_options=a.dualselect_options||a.data.dualselect_options||this.dualselect_options;var b={keepRenderingSort:!1};return a.data.dualselect_options.searchable&&(this.dualselect_options.search={left:this.dualselect_selector+"_searchLeft",right:this.dualselect_selector+"_searchRight"}),this.dualselect_options=$.extend({},b,this.dualselect_options),this},Charcoal.Admin.Property_Input_DualSelect.prototype.create_dualselect=function(){return $(this.dualselect_selector).multiselect(this.dualselect_options),this},Charcoal.Admin.Property_Input_DualSelect.prototype.set_dualselect=function(a){return this._dualselect=a,this},Charcoal.Admin.Property_Input_DualSelect.prototype.dualselect=function(){return this._dualselect},Charcoal.Admin.Property_Input_DualSelect.prototype.destroy=function(){var a=this.dualselect();a&&a.remove()},Charcoal.Admin.Property_Input_File=function(a){return this.EVENT_NAMESPACE=".charcoal.property.file",this.input_type="charcoal/admin/property/input/file",this.opts=a,this.data=a.data,this.dialog=null,this.set_input_id(this.opts.id),this.init(),this},Charcoal.Admin.Property_Input_File.prototype=Object.create(Charcoal.Admin.Property.prototype),Charcoal.Admin.Property_Input_File.prototype.constructor=Charcoal.Admin.Property_Input_File,Charcoal.Admin.Property_Input_File.prototype.parent=Charcoal.Admin.Property.prototype,Charcoal.Admin.Property_Input_File.prototype.init=function(){if(!this.input_id)return this;this.$input=$("#"+this.input_id),this.$file=this.$input.find('input[type="file"]'),this.$hidden=this.$input.find('input[type="hidden"]'),this.$preview=this.$input.find(".js-preview"),window.elFinderCallback||(window.elFinderCallback={}),this.set_listeners()},Charcoal.Admin.Property_Input_File.prototype.set_listeners=function(){if(void 0===this.$input)return this;this.$input.on("click"+this.EVENT_NAMESPACE,".js-remove-file",this.remove_file.bind(this)).on("click"+this.EVENT_NAMESPACE,".js-elfinder",this.load_elfinder.bind(this)),this.$file.on("change"+this.EVENT_NAMESPACE,this.change_file.bind(this)),window.elFinderCallback[this.input_id]=this.elfinder_callback.bind(this)},Charcoal.Admin.Property_Input_File.prototype.remove_file=function(a){a.preventDefault(),this.$hidden.val(""),this.$input.find(".form-control-static").empty(),this.$input.find(".hide-if-no-file").addClass("hidden")},Charcoal.Admin.Property_Input_File.prototype.change_file=function(a){var b,c;b=a.dataTransfer||a.target,c=b&&b.files&&b.files[0],URL.createObjectURL(c),this.$input.find(".hide-if-no-file").removeClass("hidden"),this.$input.find(".form-control-static").html(c),this.$preview.empty()},Charcoal.Admin.Property_Input_File.prototype.load_elfinder=function(a){a.preventDefault(),this.dialog=BootstrapDialog.show({title:this.data.dialog_title||"",size:BootstrapDialog.SIZE_WIDE,cssClass:"-elfinder",message:$('')})},Charcoal.Admin.Property_Input_File.prototype.elfinder_callback=function(a){this.dialog&&this.dialog.close(),a&&a.path&&(this.$input.find(".hide-if-no-file").removeClass("hidden"),this.$input.find(".form-control-static").html(a.name),this.$hidden.val(decodeURI(a.url).replace(Charcoal.Admin.base_url(),"")),this.$preview.empty())},Charcoal.Admin.Property_Input_File.prototype.set_input_id=function(a){return this.input_id=a,this},Charcoal.Admin.Property_Input_File.prototype.set_input_name=function(a){return this.input_name=a,this},Charcoal.Admin.Property_Input_File.prototype.set_input_val=function(a){return this.input_val=a,this},Charcoal.Admin.Property_Input_Image=function(a){return this.EVENT_NAMESPACE=".charcoal.property.image",this.input_type="charcoal/admin/property/input/image",this.opts=a,this.data=a.data,this.set_input_id(this.opts.id),this.init(),this},Charcoal.Admin.Property_Input_Image.prototype=Object.create(Charcoal.Admin.Property_Input_File.prototype);Charcoal.Admin.Property_Input_Image.prototype.constructor=Charcoal.Admin.Property_Input_Image,Charcoal.Admin.Property_Input_Image.prototype.parent=Charcoal.Admin.Property.prototype,Charcoal.Admin.Property_Input_Image.prototype.remove_file=function(a){a.preventDefault(),this.$hidden.val(""),this.$preview.empty(),this.$input.find(".form-control-static").empty(),this.$input.find(".hide-if-no-file").addClass("hidden")},Charcoal.Admin.Property_Input_Image.prototype.change_file=function(a){var b,c,d,e;b=new File,c=a.dataTransfer||a.target,d=c&&c.files&&c.files[0],e=URL.createObjectURL(d),b.src=e,this.$input.find(".hide-if-no-file").removeClass("hidden"),this.$input.find(".form-control-static").html(d),this.$preview.empty().append(b)},Charcoal.Admin.Property_Input_Image.prototype.elfinder_callback=function(a){if(this.dialog&&this.dialog.close(),a&&a.path){var b=$('');this.$input.find(".hide-if-no-file").removeClass("hidden"),this.$input.find(".form-control-static").html(a.name),this.$hidden.val(decodeURI(a.url).replace(Charcoal.Admin.base_url(),"")),this.$preview.empty().append(b)}},Charcoal.Admin.Property_Input_Map_Widget=function(a){a.input_type="charcoal/admin/property/input/map-widget",Charcoal.Admin.Property.call(this,a);var b=this;this._controller=void 0,this._object_inc=0,"undefined"==typeof google?(window._tmp_google_onload_function=function(){b.init()},$.getScript("https://maps.googleapis.com/maps/api/js?sensor=false&callback=_tmp_google_onload_function&key="+a.data.api_key,function(){})):b.init()},Charcoal.Admin.Property_Input_Map_Widget.prototype=Object.create(Charcoal.Admin.Property.prototype),Charcoal.Admin.Property_Input_Map_Widget.prototype.constructor=Charcoal.Admin.Property_Input_Map_Widget,Charcoal.Admin.Property_Input_Map_Widget.prototype.parent=Charcoal.Admin.Property.prototype,Charcoal.Admin.Property_Input_Map_Widget.prototype.init=function(){if(void 0!==window._tmp_google_onload_function&&delete window._tmp_google_onload_function,"undefined"==typeof BB||"undefined"==typeof google)return console.error("Plugins not loaded"),!1;var a=this.data;void 0===a.id&&console.error("Missing ID");var b={strokeColor:"#000000",strokeOpacity:.8,strokeWeight:3,fillColor:"#ffffff",fillOpacity:.35,hover:{strokeColor:"#000000",strokeOpacity:1,strokeWeight:2,fillColor:"#ffffff",fillOpacity:.5},focused:{fillOpacity:.8}},c={default_styles:b,use_clusterer:!1,map:{center:{x:45.3712923,y:-73.9820994},zoom:14,mapType:"roadmap",coordsType:"inpage",map_mode:"default"}};c=$.extend(!0,c,a.data);var d=this.element().find("input[type=hidden]").val();if(d){var e=JSON.parse(d),f={},g=0;for(var h in e)g++,f[h]=e[h],f[h].styles=$.extend(e[h].styles,b);f&&(c.places=f),g&&(this._object_inc=g)}this._controller=new window.BB.gmap.controller(this.element().find(".js-map-maker-map").get(0),c),this.controller().init().ready(function(a){a.fit_bounds(),a.remove_focus()}),this.controller().set_styles([{featureType:"poi",elementType:"all",stylers:[{visibility:"off"}]}]),this.controller().remove_focus(),this.controls()},Charcoal.Admin.Property_Input_Map_Widget.prototype.controller=function(){return this._controller},Charcoal.Admin.Property_Input_Map_Widget.prototype.object_index=function(){return++this._object_inc},Charcoal.Admin.Property_Input_Map_Widget.prototype.controls=function(){var a=this,b="object";this.element().on("click",".js-add-marker",function(c){c.preventDefault();for(var d=b+a.object_index();a.controller().get_place(d);)d=b+a.object_index();a.controller().create_new("marker",d)}),this.element().on("click",".js-display-marker-toolbox",function(b){if(b.preventDefault(),$(this).hasClass("-active"))return $(this).removeClass("-active"),a.hide_marker_toolbar(),!1;$(this).siblings(".-active").removeClass("-active"),$(this).addClass("-active"),a.display_marker_toolbar()}),this.element().on("click",".js-add-line",function(c){if(c.preventDefault(),$(this).hasClass("-active"))return $(this).removeClass("-active"),!1;$(this).siblings(".-active").removeClass("-active"),$(this).addClass("-active");for(var d=b+a.object_index();a.controller().get_place(d);)d=b+a.object_index();a.controller().create_new("line",d)}),this.element().on("click",".js-add-polygon",function(c){if(c.preventDefault(),$(this).hasClass("-active"))return $(this).removeClass("-active"),!1;$(this).siblings(".-active").removeClass("-active"),$(this).addClass("-active");for(var d=b+a.object_index();a.controller().get_place(d);)d=b+a.object_index();a.controller().create_new("polygon",d)}),this.element().on("click",".js-add_place_by_address",function(b){b.preventDefault();var c=a.element().find(".js-address").val();if(!c)return!1;a.controller().add_place_by_address("object"+a.object_index(),c,{type:"marker",draggable:!0,editable:!0,loaded_callback:function(b){a.controller().map().setCenter(b.object().getPosition())}})}),this.element().on("click",".js-reset",function(b){b.preventDefault(),a.controller().reset()}),a.controller().on("focus",function(b){var c=b.data("type");switch(a.element().find(".js-add-polygon").removeClass("-active"),a.element().find(".js-display-marker-toolbox").removeClass("-active"),a.element().find(".js-add-line").removeClass("-active"),c){case"marker":a.element().find(".js-display-marker-toolbox").addClass("-active");break;case"polygon":a.element().find(".js-add-polygon").addClass("-active");break;case"line":a.element().find(".js-add-line").addClass("-active")}})},Charcoal.Admin.Property_Input_Map_Widget.prototype.display_marker_toolbar=function(){$(".c-map-maker").addClass("maker_header-open")},Charcoal.Admin.Property_Input_Map_Widget.prototype.hide_marker_toolbar=function(){$(".c-map-maker").removeClass("maker_header-open")},Charcoal.Admin.Property_Input_Map_Widget.prototype.save=function(){var a=this.controller().export(),b="object"==typeof a.places?a.places:{};return this.element().find("input[type=hidden]").val(JSON.stringify(b)),this},Charcoal.Admin.Property_Input_SelectPicker=function(a){this.input_type="charcoal/admin/property/input/select",this.input_id=null,this.select_selector=null,this.select_options=null,this.set_properties(a).create_select()},Charcoal.Admin.Property_Input_SelectPicker.prototype=Object.create(Charcoal.Admin.Property.prototype),Charcoal.Admin.Property_Input_SelectPicker.prototype.constructor=Charcoal.Admin.Property_Input_SelectPicker,Charcoal.Admin.Property_Input_SelectPicker.prototype.parent=Charcoal.Admin.Property.prototype,Charcoal.Admin.Property_Input_SelectPicker.prototype.set_properties=function(a){this.input_id=a.id||this.input_id,this.select_selector=a.data.select_selector||this.select_selector,this.select_options=a.data.select_options||this.select_options;var b={};return this.select_options=$.extend({},b,this.select_options),this},Charcoal.Admin.Property_Input_SelectPicker.prototype.create_select=function(){return $(this.select_selector).selectpicker(this.select_options),this},function(){var a=function(a){this.input_type="charcoal/admin/property/input/selectize",this.input_id=null,this.obj_type=null,this.copy_items=!1,this.title=null,this.translations=null,this.pattern=null,this.multiple=!1,this.separator=",",this.selectize=null,this.selectize_selector=null,this.form_ident=null,this.selectize_options={},this.choice_obj_map={},this.selectize_property_ident=null,this.selectize_obj_type=null,this.selectize_templates={},this.clipboard=null,this.allow_update=null,this.set_properties(a).init()};a.prototype=Object.create(Charcoal.Admin.Property.prototype),a.constructor=Charcoal.Admin.Property_Input_Selectize,a.parent=Charcoal.Admin.Property.prototype,a.prototype.init=function(){this.init_selectize(),this.init_clipboard(),this.init_allow_update(),this.init_allow_create();var a=this;this.selectize.on("update_item",function(b){a.create_item(null,b.callback,{id:b.value,step:0})})},a.prototype.set_properties=function(a){this.input_id=a.id||this.input_id,this.obj_type=a.data.obj_type||this.obj_type,this.copy_items=a.data.copy_items||this.copy_items,this.allow_update=a.data.allow_update||this.allow_update,this.allow_create=a.data.allow_create||this.allow_create,this.title=a.data.title||this.title,this.translations=a.data.translations||this.translations,this.pattern=a.data.pattern||this.pattern,this.multiple=a.data.multiple||this.multiple,this.separator=a.data.multiple_separator||this.multiple_separator||",",this.form_ident=a.data.form_ident||this.form_ident,this.selectize_selector=a.data.selectize_selector||this.selectize_selector,this.selectize_options=a.data.selectize_options||this.selectize_options,this.choice_obj_map=a.data.choice_obj_map||this.choice_obj_map,this.selectize_property_ident=a.data.selectize_property_ident||this.selectize_property_ident,this.selectize_obj_type=a.data.selectize_obj_type||this.selectize_obj_type,this.selectize_templates=a.data.selectize_templates||this.selectize_templates,this.$input=$(this.selectize_selector||"#"+this.input_id);var b;b=this.multiple?{drag_drop:{},charcoal_item:{}}:{charcoal_item:{}};var c=this.obj_type,d={plugins:b,formData:{},delimiter:this.separator,persist:!0,preload:"focus",openOnFocus:!0,labelField:"label",searchField:["value","label"],dropdownParent:this.$input.closest(".form-field"),render:{},createFilter:function(a){for(var b in this.options)if(b=this.options[b],b.label===a)return!1;return!0},onInitialize:function(){var a=this;a.sifter.iterator(this.items,function(b){var c=a.options[b],d=a.getItem(b);c.color&&d.css("background-color",c.color)})}};if(this.selectize_templates.item&&(d.render.item=function(a,b){return a.item_render?'
'+a.item_render+"
":'
'+b(a[d.labelField])+"
"}),this.selectize_templates.option&&(d.render.option=function(a,b){return a.option_render?'
'+a.option_render+"
":'
'+b(a[d.labelField])+"
"}),c?(d.create=this.create_item.bind(this),d.load=this.load_items.bind(this)):(d.plugins.create_on_enter={},d.create=function(a){return{value:a,label:a}}),this.selectize_options.splitOn){var e=this.selectize_options.splitOn;if("array"===$.type(e)){for(var f=e.length-1;f>=0;f--)switch(e[f]){case"comma":e[f]="\\s*,\\s*";break;case"tab":e[f]="\\t+";break;default:e[f]=e[f].replace(/[-\/\\^$*+?.()|[\]{}]/g,"\\$&")}e=e.join("|")}this.selectize_options.splitOn=new RegExp(e)}return this.selectize_options=$.extend(!0,{},d,this.selectize_options),this},a.prototype.create_item=function(a,b,c){var d={};c=c||{};var e=this.pattern,f=this,g=this.obj_type,h=this.title,i=this.translations,j=this.selectize_options,k=c.step||0,l=this.form_ident,m=null,n=c.id||null,o=this.selectize_property_ident,p=this.selectize_obj_type;l&&"object"==typeof l&&(!n&&l.create?(l=l.create,h+=" - "+i.statusTemplate.replaceMap({"[[ current ]]":1,"[[ total ]]":2}),k=1,m="Next"):n&&l.update?(l=l.update,2===k&&(h+=" - "+i.statusTemplate.replaceMap({"[[ current ]]":2,"[[ total ]]":2}),m="Finish")):l=null),$.isEmptyObject(j.formData)?(e?a&&(d[e]=a):a&&(d[this.choice_obj_map.label]=a),d.form_ident=l,d.submit_label=m):a&&(d=$.extend({},j.formData),$.each(d,function(b,c){":input"===c&&(d[b]=a)}));var q={title:h,size:BootstrapDialog.SIZE_WIDE,cssClass:"-quick-form",dialog_options:{onhide:function(){b({return:!1})}},widget_type:"charcoal/admin/widget/quickForm",widget_options:{obj_type:g,obj_id:n,form_data:d}};k>0&&(q.type=BootstrapDialog.TYPE_PRIMARY);var r=this.dialog(q,function(c){if(c.success){if(!c.widget_id)return!1;Charcoal.Admin.manager().add_widget({id:c.widget_id,type:"charcoal/admin/widget/quick-form",data:{obj_type:g},obj_id:n,extra_form_data:{selectize_obj_type:p,selectize_prop_ident:o},save_action:"selectize/save",update_action:"selectize/update",suppress_feedback:1===k,save_callback:function(c){var d={class:"new"},e=c.selectize[0];e&&$.extend(!0,d,e),b(d),r.close(),1===k&&f.create_item(a,b,{id:e.value,step:2})}}),Charcoal.Admin.manager().render()}})},a.prototype.load_items=function(a,b){var c=this.obj_type,d=this.selectize_property_ident,e=this.selectize_obj_type,f={obj_type:c,selectize_obj_type:e,selectize_prop_ident:d};$.ajax({url:Charcoal.Admin.admin_url()+"selectize/load",data:f,type:"GET",error:function(){b()},success:function(a){var c=[],d=a.selectize;for(var e in d)d.hasOwnProperty(e)&&(e=d[e],c.push(e));b(c)}})},a.prototype.dialog=Charcoal.Admin.Widget.prototype.dialog,a.prototype.init_selectize=function(){var a=this.$input.selectize(this.selectize_options);this.selectize=a[0].selectize},a.prototype.init_allow_create=function(){if(this.allow_create){var a=this.selectize,b=this;$(this.selectize_selector+"_create").on("click",function(){b.create_item(null,function(b){b&&b.value&&(a.addOption(b),a.addItem(b.value))})})}},a.prototype.init_allow_update=function(){switch(this.selectize.settings.mode){case"single":this.allow_update_single();break;case"multiple":this.allow_update_multiple()}},a.prototype.allow_update_single=function(){if(this.allow_update){var a=this.selectize,b=this;$(this.selectize_selector+"_update").on("click",function(){var c=a.items;c&&b.create_item(null,function(b){b&&b.value&&a.updateOption(c[0],b)},{id:c[0],step:0})})}},a.prototype.allow_update_multiple=function(){if(this.allow_update){var a=this.selectize,b=$(this.selectize_selector+"_update"),c=null,d=this;b[0].disabled=!0,b.on("click",function(){c&&d.create_item(null,function(b){b&&b.value&&a.updateOption(c,b)},{id:c,step:0})}),a.on("blur",function(){setTimeout(function(){b[0].disabled=!0},500)}),a.$control.on("mousedown","*:not(input)",function(d){c=$(d.target).eq(0).data("value"),a.$control.find(".active:not(input)")&&(b[0].disabled=!1)})}},a.prototype.init_clipboard=function(){if(this.copy_items){var a=this.selectize;this.clipboard=new Clipboard(this.selectize_selector+"_copy",{text:function(){return a.$input.val()}})}},Charcoal.Admin.Property_Input_Selectize=a}(jQuery,document),Selectize.define("btn_remove",function(a){a=$.extend({label:'',title:"Remove",className:"btn-remove",append:!0},a),this.require("buttons");"single"!==this.settings.mode&&function(a,b){var c=a;c.addButton(a,b,function(a){if(a.preventDefault(),!c.isLocked){var b=$(a.currentTarget).parent();c.setActiveItem(b),c.deleteSelection()&&c.setCaret(c.items.length)}})}(this,a)}),Selectize.define("btn_update",function(a){a=$.extend({label:'',title:"Update",className:"btn-update",append:!0},a),this.require("buttons");"single"!==this.settings.mode&&function(a,b){var c=a;c.addButton(a,b,function(a){if(a.preventDefault(),!c.isLocked){var b=$(a.currentTarget).parent();c.setActiveItem(b),c.trigger("update_item",{item:b,value:b.eq(0).data("value"),callback:function(a){a&&a.value&&c.updateOption(a.value,a)}})}})}(this,a)}),Selectize.define("buttons",function(){var a=function(a){return(a+"").replace(/&/g,"&").replace(//g,">").replace(/"/g,""")};this.buttonOffset=40,this.currentButtonOffset=0,this.addButton=function(b,c,d){var e=b,f=''+c.label+"";e.currentButtonOffset+=e.buttonOffset;var g=function(a,b){var c=a.search(/(<\/[^>]+>\s*)$/);return a.substring(0,c)+b+a.substring(c)},h=function(a,b){var c=a.match(/(padding-right:.*;)/);if(c&&c[0]){var d=c[0].length+c.index;return a.substring(0,c.index)+"padding-right:"+(b+8)+"px;"+a.substring(d)}return(c=a.match(/(style=")/))&&c[0]?(c=c[0].length+c.index,a.substring(0,c)+"padding-right:"+(b+8)+"px;"+a.substring(c)):(c=a.match(/(<[^>]+)/),c&&c[0]?(c=c[0].length+c.index,a.substring(0,c)+'style="padding-right:'+(b+8)+'px;"'+a.substring(c)):void 0)};b.setup=function(){var a=e.setup;return function(){if(c.append){var i=e.settings.render.item;e.settings.render.item=function(){return g(h(i.apply(b,arguments),e.currentButtonOffset),f)}}a.apply(b,arguments),b.$control.on("mousedown","."+c.className,function(a){a.preventDefault(),e.$control.data("ui-sortable")&&(e.$control.sortable("disable"),$(document).on("mouseup.sortable",function(){$(document).off("mouseup.sortable"),e.$control.sortable("enable")}))}),b.$control.on("click","."+c.className,function(a){"function"==typeof d&&d(a)})}}()}}),Selectize.define("create_on_blur",function(){if("multi"===this.settings.mode){var a=this;this.onBlur=function(){var b=a.onBlur;return function(){return""!==this.$control_input.val().trim()&&a.createItem(this.$control_input.val()),b.apply(this,arguments)}}()}}),Selectize.define("create_on_enter",function(){if("multi"===this.settings.mode){var a=this;this.onKeyUp=function(){var b=a.onKeyUp;return function(c){return 13===c.keyCode&&""!==this.$control_input.val().trim()&&a.createItem(this.$control_input.val()),b.apply(this,arguments)}}()}}),function(){var a=function(a){this.input_type="charcoal/admin/property/input/selectize",this.input_id=null,this.obj_type=null,this.copy_items=!1,this.title=null,this.translations=null,this.pattern=null,this.multiple=!1,this.separator=",",this.selectize=null,this.selectize_selector=null,this.form_ident=null,this.selectize_options={},this.choice_obj_map={},this.clipboard=null,this.allow_update=!1,this.set_properties(a).init()};a.prototype=Object.create(Charcoal.Admin.Property_Input_Selectize.prototype),a.constructor=Charcoal.Admin.Property_Input_Selectize,a.parent=Object.create(Charcoal.Admin.Property_Input_Selectize.prototype),a.prototype.set_properties=function(a){this.input_id=a.id||this.input_id,this.obj_type=a.data.obj_type||this.obj_type,this.copy_items=a.data.copy_items||this.copy_items,this.allow_update=a.data.allow_update||this.allow_update,this.title=a.data.title||this.title,this.translations=a.data.translations||this.translations,this.pattern=a.data.pattern||this.pattern,this.multiple=a.data.multiple||this.multiple,this.separator=a.data.multiple_separator||this.multiple_separator||",",this.form_ident=a.data.form_ident||this.form_ident,this.selectize_selector=a.data.selectize_selector||this.selectize_selector,this.selectize_options=a.data.selectize_options||this.selectize_options,this.choice_obj_map=a.data.choice_obj_map||this.choice_obj_map,this.$input=$(this.selectize_selector||"#"+this.input_id);var b;b=this.multiple?{drag_drop:{},charcoal_item:{}}:{charcoal_item:{}};var c=this.obj_type,d={plugins:b,formData:{},delimiter:this.separator,persist:!0,preload:"focus",openOnFocus:!0,searchField:["value","label","email"],dropdownParent:this.$input.closest(".form-field"),createFilter:function(a){for(var b in this.options)if(b=this.options[b],b.label===a)return!1;return!0},onInitialize:function(){var a=this;a.sifter.iterator(this.items,function(b){var c=a.options[b],d=a.getItem(b);c.color&&d.css("background-color",c.color)})},render:{item:function(a,b){return'
'+(a.label?''+b(a.label)+"":"")+(a.email?'":"")+"
"},option:function(a,b){return'
'+(a.label?''+b(a.label)+"":"")+(a.email?''+b(a.email)+"":"")+"
"}}};if(c?(d.create=this.create_item.bind(this),d.load=this.load_items.bind(this)):(d.plugins.create_on_enter={},d.create=function(a){return{value:a,label:a}}),this.selectize_options.splitOn){var e=this.selectize_options.splitOn;if("array"===$.type(e)){for(var f=e.length-1;f>=0;f--)switch(e[f]){case"comma":e[f]="\\s*,\\s*";break;case"tab":e[f]="\\t+";break;default:e[f]=e[f].replace(/[-\/\\^$*+?.()|[\]{}]/g,"\\$&")}e=e.join("|")}this.selectize_options.splitOn=new RegExp(e)}return this.selectize_options=$.extend(!0,{},d,this.selectize_options),this},Charcoal.Admin.Property_Input_Selectize_Email=a}(jQuery,document),Selectize.define("charcoal_item",function(a){a=$.extend({classField:"class",colorField:"color"},a);var b=this;this.settings.onItemAdd=function(){var c=null;return b.settings.hasOwnProperty("onItemAdd")&&(c=b.settings.onItemAdd),function(d,e){var f=b.options[d];if(f.hasOwnProperty(a.colorField)&&e.css("background-color",f[a.colorField]),f.hasOwnProperty(a.classField)&&e.addClass(f[a.classField]),c)return c.apply(this,arguments)}}()}),function(){var a=function(a){this.input_type="charcoal/admin/property/input/selectize/list",this.input_id=null,this.obj_type=null,this.copy_items=!1,this.title=null,this.translations=null,this.pattern=null,this.multiple=!1,this.separator=",",this.selectize=null,this.selectize_selector=null,this.form_ident=null,this.selectize_options={},this.clipboard=null,this.allow_update=!1,this.set_properties(a).init()};a.prototype=Object.create(Charcoal.Admin.Property_Input_Selectize.prototype),a.constructor=Charcoal.Admin.Property_Input_Selectize,a.parent=Charcoal.Admin.Property_Input_Selectize.prototype,a.prototype.set_properties=function(a){this.input_id=a.id||this.input_id,this.obj_type=a.data.obj_type||this.obj_type,this.copy_items=a.data.copy_items||this.copy_items,this.allow_update=a.data.allow_update||this.allow_update,this.title=a.data.title||this.title,this.translations=a.data.translations||this.translations,this.pattern=a.data.pattern||this.pattern,this.multiple=a.data.multiple||this.multiple,this.separator=a.data.multiple_separator||this.multiple_separator||",",this.form_ident=a.data.form_ident||this.form_ident,this.selectize_selector=a.data.selectize_selector||this.selectize_selector,this.selectize_options=a.data.selectize_options||this.selectize_options,this.$input=$(this.selectize_selector||"#"+this.input_id);var b;b=this.multiple?{drag_drop:{},charcoal_item:{}}:{charcoal_item:{}};var c=this.obj_type,d={plugins:b,formData:{},delimiter:this.separator,persist:!0,preload:"focus",openOnFocus:!0,searchField:["value","label"],dropdownParent:this.$input.closest(".form-field"),createFilter:function(a){for(var b in this.options)if(b=this.options[b],b.label===a)return!1;return!0},onInitialize:function(){var a=this;a.sifter.iterator(this.items,function(b){var c=a.options[b],d=a.getItem(b);c.color&&d.css("background-color",c.color)})}};if(c?(d.create=this.create_item.bind(this),d.load=this.load_items.bind(this)):(d.plugins.create_on_enter={},d.create=function(a){return{value:a,label:a}}),this.selectize_options.splitOn){var e=this.selectize_options.splitOn;if("array"===$.type(e)){for(var f=e.length-1;f>=0;f--)switch(e[f]){case"comma":e[f]="\\s*,\\s*";break;case"tab":e[f]="\\t+";break;default:e[f]=e[f].replace(/[-\/\\^$*+?.()|[\]{}]/g,"\\$&")}e=e.join("|")}this.selectize_options.splitOn=new RegExp(e)}return this.selectize_options=$.extend(!0,{},d,this.selectize_options),this},Charcoal.Admin.Property_Input_Selectize_List=a}(jQuery,document),Charcoal.Admin.Property_Input_Selectize_Search=function(a){this.input_type="charcoal/admin/property/input/selectize/search",this.input_id=null,this.obj_type=null,this.copy_items=!1,this.title=null,this.multiple=!1,this.separator=",",this._tags=null,this.selectize=null,this.selectize_selector=null,this.selectize_options={},this.clipboard=null,this.set_properties(a).init()},Charcoal.Admin.Property_Input_Selectize_Search.prototype=Object.create(Charcoal.Admin.Property.prototype),Charcoal.Admin.Property_Input_Selectize_Search.prototype.constructor=Charcoal.Admin.Property_Input_Selectize_Search,Charcoal.Admin.Property_Input_Selectize_Search.prototype.parent=Charcoal.Admin.Property.prototype,Charcoal.Admin.Property_Input_Selectize_Search.prototype.init=function(){if("function"!=typeof $.fn.sortable){return Charcoal.Admin.loadScript("https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js",this.init.bind(this)),this}this.init_selectize()},Charcoal.Admin.Property_Input_Selectize_Search.prototype.set_properties=function(a){this.input_id=a.id||this.input_id,this.obj_type=a.data.obj_type||this.obj_type,this.copy_items=a.data.copy_items||this.copy_items,this.title=a.data.title||this.title,this.multiple=a.data.multiple||this.multiple,this.separator=a.data.multiple_separator||this.multiple_separator||",",this.selectize_selector=a.data.selectize_selector||this.selectize_selector,this.selectize_options=a.data.selectize_options||this.selectize_options,this.$input=$(this.selectize_selector||"#"+this.input_id);var b;this.multiple&&(b=["remove_button","drag_drop"]);var c={plugins:b,formData:{},delimiter:this.separator,persist:!1,preload:!0,openOnFocus:!0};return this.selectize_options=$.extend({},c,this.selectize_options),this},Charcoal.Admin.Property_Input_Selectize_Search.prototype.init_selectize=function(){var a=this.$input.selectize(this.selectize_options);this.selectize=a[0].selectize},Charcoal.Admin.Property_Input_Selectize_Tags=function(a){this.input_type="charcoal/admin/property/input/selectize/tags",this.input_id=null,this.obj_type=null,this.copy_items=!1,this.title=null,this.multiple=!1,this.separator=",",this._tags=null,this.selectize=null,this.selectize_selector=null,this.selectize_options={},this.clipboard=null,this.set_properties(a).init()},Charcoal.Admin.Property_Input_Selectize_Tags.prototype=Object.create(Charcoal.Admin.Property.prototype),Charcoal.Admin.Property_Input_Selectize_Tags.prototype.constructor=Charcoal.Admin.Property_Input_Selectize_Tags,Charcoal.Admin.Property_Input_Selectize_Tags.prototype.parent=Charcoal.Admin.Property.prototype,Charcoal.Admin.Property_Input_Selectize_Tags.prototype.init=function(){if("function"!=typeof $.fn.sortable){return Charcoal.Admin.loadScript("https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js",this.init.bind(this)),this}this.init_selectize(),this.init_clipboard()},Charcoal.Admin.Property_Input_Selectize_Tags.prototype.set_properties=function(a){this.input_id=a.id||this.input_id,this.obj_type=a.data.obj_type||this.obj_type,this.copy_items=a.data.copy_items||this.copy_items,this.title=a.data.title||this.title,this.multiple=a.data.multiple||this.multiple,this.separator=a.data.multiple_separator||this.multiple_separator||",",this.selectize_selector=a.data.selectize_selector||this.selectize_selector,this.selectize_options=a.data.selectize_options||this.selectize_options,this.$input=$(this.selectize_selector||"#"+this.input_id);var b;b=this.multiple?["remove_button","drag_drop","charcoal_item"]:["charcoal_item"];var c=this.obj_type,d={plugins:b,formData:{},delimiter:this.separator,persist:!1,preload:!0,openOnFocus:!0,dropdownParent:this.$input.closest(".form-field"),createFilter:function(a){for(var b in this.options)if(b=this.options[b],b.text===a)return!1;return!0},onInitialize:function(){var a=this;a.sifter.iterator(this.items,function(b){var c=a.options[b],d=a.getItem(b);c.color&&d.css("background-color",c.color)})}};if(c?(d.create=this.create_tag.bind(this),d.load=this.load_tags.bind(this)):(d.plugins.push("create_on_enter"),d.create=function(a){return{value:a,text:a}}),this.selectize_options=$.extend({},d,this.selectize_options),this.selectize_options.splitOn){var e=this.selectize_options.splitOn +;if("array"===$.type(e)){for(var f=e.length-1;f>=0;f--)switch(e[f]){case"comma":e[f]="\\s*,\\s*";break;case"tab":e[f]="\\t+";break;default:e[f]=e[f].replace(/[-\/\\^$*+?.()|[\]{}]/g,"\\$&")}e=e.join("|")}this.selectize_options.splitOn=new RegExp(e)}return this},Charcoal.Admin.Property_Input_Selectize_Tags.prototype.create_tag=function(a,b){var c=this.obj_type,d=this.id,e=this.title,f=this.selectize_options,g={};$.isEmptyObject(f.formData)?g={name:a}:(g=$.extend({},f.formData),$.each(g,function(b,c){":input"===c&&(g[b]=a)}));var h={title:e,size:BootstrapDialog.SIZE_WIDE,cssClass:"-quick-form",dialog_options:{onhide:function(){b({return:!1})}},widget_type:"charcoal/admin/widget/quickForm",widget_options:{obj_type:c,obj_id:d,form_data:g}};this.dialog(h,function(a){if(a.success){if(!a.widget_id)return!1;Charcoal.Admin.manager().add_widget({id:a.widget_id,type:"charcoal/admin/widget/quick-form",data:{obj_type:c},obj_id:d,save_callback:function(a){var c=a.obj.id;"name"in a.obj&&a.obj.name&&(c=a.obj.name[Charcoal.Admin.lang()]||a.obj.name),b({value:a.obj.id,text:c,color:a.obj.color,class:"new"}),BootstrapDialog.closeAll()}})}})},Charcoal.Admin.Property_Input_Selectize_Tags.prototype.load_tags=function(a,b){var c=this.obj_type;if(!a.length)return b();$.ajax({url:Charcoal.Admin.admin_url()+"object/load",data:{obj_type:c},type:"GET",error:function(){b()},success:function(a){var c=[];for(var d in a.collection){d=a.collection[d];var e=d.id;"name"in d&&d.name&&(e=d.name[Charcoal.Admin.lang()]||d.name),c.push({value:d.id,text:e,color:d.color})}b(c)}})},Charcoal.Admin.Property_Input_Selectize_Tags.prototype.dialog=Charcoal.Admin.Widget.prototype.dialog,Charcoal.Admin.Property_Input_Selectize_Tags.prototype.onKeyDown=function(a){var b=this,c=!1,d=/Mac/.test(navigator.userAgent);if(b.isLocked&&9!==a.keyCode&&a.preventDefault(),"undefined"===$.type(b.isCmdDown)&&(c=!0,b.isCmdDown=a[d?"metaKey":"ctrlKey"]),b.isCmdDown&&67===a.keyCode){if(c&&(b.isCmdDown=void 0),b.$activeItems.length)for(var e=[],f=0,g=b.$activeItems.length;f0;a--)this.add_item();return this},Charcoal.Admin.Property_Input_Text.prototype.split_val=function(a){var b=this.split_on||this.multiple_separator;a=a||this.$input;var c=a.val(),d=c.split(b),e=0,f=d.length;if(1===f)return!1;for(;e-1&&(!b.multiple_max||b.currentValAmount-1&&(!b.multiple_min||b.currentValAmount>b.multiple_min)&&""===$(this).val()&&(a.preventDefault(),b.remove_item($(this))),f.indexOf(g)>-1&&(a.preventDefault(),$(this).prev("input").focus()),e.indexOf(g)>-1&&(a.preventDefault(),$(this).next("input").focus())}),a.on("keyup",function(){b.split_val($(this))})},Charcoal.Admin.Property_Input_Text.prototype.insert_item=function(a,b){var c=this.input_clone(b);return c.insertAfter(a),this.bind_keyboard_events(c),c.focus(),this.currentValAmount++,c},Charcoal.Admin.Property_Input_Text.prototype.add_item=function(a){var b=this.input_clone(a);return this.$container.append(b),this.bind_keyboard_events(b),b.focus(),this.currentValAmount++,b},Charcoal.Admin.Property_Input_Text.prototype.remove_item=function(a){var b=a.prev("input"),c=a.next("input");return!(!b.length&&!c.length)&&(b.length?b.focus():c.length&&c.focus(),this.remove_item_listeners(a),a.remove(),this.currentValAmount--,this)},Charcoal.Admin.Property_Input_Text.prototype.remove_item_listeners=function(a){return a.off("keydown"),a.off("keyup"),this},Charcoal.Admin.Property_Input_Text.prototype.input_clone=function(a){var b=this.$input,c=b.attr("class"),d=b.attr("type"),e=this.min_length,f=this.max_length,g=this.required,h=this.readonly,i=this.input_name,j=$("");return d&&j.attr("type",d),c&&j.attr("class",c),e&&j.attr("minlength",e),f&&j.attr("maxlength",f),g&&j.attr("required","required"),h&&j.attr("readonly","readonly"),a&&j.val(a),j.attr("name",i),j},Charcoal.Admin.Property_Input_Text.prototype.set_input_id=function(a){return this.input_id=a,this},Charcoal.Admin.Property_Input_Text.prototype.set_input_name=function(a){return this.input_name=a,this},Charcoal.Admin.Property_Input_Text.prototype.set_input_val=function(a){return this.input_val=a,this},Charcoal.Admin.Property_Input_Text.prototype.set_readonly=function(a){return a||(a=!1),this.readonly=a,this},Charcoal.Admin.Property_Input_Text.prototype.set_required=function(a){return a||(a=!1),this.required=a,this},Charcoal.Admin.Property_Input_Text.prototype.set_min_length=function(a){return a||(a=0),this.min_length=a,this},Charcoal.Admin.Property_Input_Text.prototype.set_max_length=function(a){return a||(a=0),this.max_length=a,this},Charcoal.Admin.Property_Input_Text.prototype.set_size=function(a){return a||(a=0),this.size=a,this},Charcoal.Admin.Property_Input_Text.prototype.set_multiple=function(a){return a||(a=!1),this.multiple=a,this},Charcoal.Admin.Property_Input_Text.prototype.set_multiple_min=function(a){return a||(a=!1),this.multiple_min=a,this},Charcoal.Admin.Property_Input_Text.prototype.set_multiple_max=function(a){return a||(a=!1),this.multiple_max=a,this},Charcoal.Admin.Property_Input_Text.prototype.set_multiple_separator=function(a){return a||(a=","),this.multiple_separator=a,this},Charcoal.Admin.Property_Input_Text.prototype.set_split_on=function(a){if(a){if("array"===$.type(a)){for(var b=a.length-1;b>=0;b--)switch(a[b]){case"comma":a[b]="\\s*,\\s*";break;case"tab":a[b]="\\t+";break;case"newline":a[b]="[\\n\\r]+";break;default:a[b]=a[b].replace(/[-\/\\^$*+?.()|[\]{}]/g,"\\$&")}a=a.join("|")}a=new RegExp(a)}else a=this.multiple_separator;return this.split_on=a,this},Charcoal.Admin.Property_Input_Tinymce=function(a){this.input_type="charcoal/admin/property/input/tinymce",this.input_id=null,this.data=a.data,this.editor_options=null,this._editor=null,window.elFinderCallback||(window.elFinderCallback={}),this.set_properties(a),this.init()},Charcoal.Admin.Property_Input_Tinymce.prototype=Object.create(Charcoal.Admin.Property.prototype),Charcoal.Admin.Property_Input_Tinymce.prototype.constructor=Charcoal.Admin.Property_Input_Tinymce,Charcoal.Admin.Property_Input_Tinymce.prototype.parent=Charcoal.Admin.Property.prototype,Charcoal.Admin.Property_Input_Tinymce.prototype.init=function(){this.create_tinymce()},Charcoal.Admin.Property_Input_Tinymce.prototype.base_url=function(){return Charcoal.Admin.base_url()+"assets/admin/scripts/vendors/tinymce"},Charcoal.Admin.Property_Input_Tinymce.prototype.set_properties=function(a){this.input_id=a.input_id||this.input_id,this.editor_options=a.editor_options||a.data.editor_options||this.editor_options,window.elFinderCallback[this.input_id]=this.elfinder_callback.bind(this);var b=Charcoal.Admin.locale().match(/([a-zA-Z]{2})(_|-)([a-zA-Z]{2})/)[0]||"en";b=b.replace("-","_"),b.match(/en_/)&&(b="en");var c={language:b,plugins:["advlist","anchor","autolink","autoresize","charcoal","charmap","code","colorpicker","contextmenu","fullscreen","hr","image","link","lists","media","nonbreaking","noneditable","paste","placeholder","searchreplace","tabfocus","table","visualblocks","visualchars","wordcount"],toolbar:"undo redo | styleselect | bold italic | forecolor backcolor | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image anchor",browser_spellcheck:!0,end_container_on_empty_block:!0,entity_encoding:"raw",allow_conditional_comments:!0,convert_fonts_to_spans:!0,forced_root_block:"p",allow_script_urls:!1,document_base_url:Charcoal.Admin.base_url(),relative_urls:!0,remove_script_host:!1,autoresize_min_height:"150px",autoresize_max_height:"400px",contextmenu:"link image inserttable | cell row column deletetable",file_picker_callback:$.proxy(this.elfinder_browser,null,this),image_advtab:!0,importcss_append:!0,media_alt_source:!1,nonbreaking_force_tab:!1,paste_data_images:!0,paste_as_text:!0,paste_merge_formats:!0,root_lang_attr:$("#"+this.input_id).closest("[data-lang]").data("lang"),table_grid:!0,table_tab_navigation:!0,visualblocks_default_state:!1};return"plugins"in c&&"plugins"in this.editor_options&&($.each(this.editor_options.plugins,function(a,b){var d,e=0===b.indexOf("!");if(e&&(b=b.slice(1)),e)for(;(d=c.plugins.indexOf(b))>-1;)delete c.plugins[d];else-1===c.plugins.indexOf(b)&&c.plugins.push(b)}),delete this.editor_options.plugins),this.editor_options=$.extend({},c,this.editor_options),this.editor_options.selector="#"+this.input_id,this.editor_options.setup=function(a){a.on("change",function(){window.tinymce.triggerSave()})},this},Charcoal.Admin.Property_Input_Tinymce.prototype.create_tinymce=function(){var a=this;if("object"!=typeof window.tinyMCE){var b=this.base_url()+"/tinymce.min.js";return Charcoal.Admin.loadScript(b,this.create_tinymce.bind(this)),this}window.tinyMCE.dom.Event.domLoaded=!0,window.tinyMCE.baseURI=new window.tinyMCE.util.URI(this.base_url()),window.tinyMCE.baseURL=this.base_url(),window.tinyMCE.suffix=".min",window.tinyMCE.PluginManager.get(this.input_id)||(window.tinyMCE.PluginManager.add(this.input_id,function(b){a.set_editor(b)}),"array"!==$.type(this.editor_options.plugins)&&(this.editor_options.plugins=[]),this.editor_options.plugins.push(this.input_id)),window.tinyMCE.init(this.editor_options)},Charcoal.Admin.Property_Input_Tinymce.prototype.elfinder_callback=function(a,b){parent.tinyMCE.activeEditor.windowManager.getParams().oninsert(a,b),parent.tinyMCE.activeEditor.windowManager.close()},Charcoal.Admin.Property_Input_Tinymce.prototype.elfinder_browser=function(a,b,c,d){var e=this;return window.tinyMCE.activeEditor.windowManager.open({file:a.data.elfinder_url+"&"+$.param(d),title:a.data.dialog_title||"",width:900,height:450,resizable:"yes"},{oninsert:function(a,c){var f,g,h,i;for(f=a.url,g=/\/[^\/]+?\/\.\.\//;f.match(g);)f=f.replace(g,"/");i=e.selection.getContent(),0===i.length&&"A"===e.selection.getNode().nodeName&&(i=e.selection.getNode().textContent),h=a.name+" ("+c.formatSize(a.size)+")","file"===d.filetype&&b(f,{text:i||h,title:h}),"image"===d.filetype&&b(f,{alt:h}),"media"===d.filetype&&b(f)}}),!1},Charcoal.Admin.Property_Input_Tinymce.prototype.set_editor=function(a){return this._editor=a,this},Charcoal.Admin.Property_Input_Tinymce.prototype.editor=function(){return this._editor},Charcoal.Admin.Property_Input_Tinymce.prototype.destroy=function(){var a=this.editor();a&&a.remove()},Charcoal.Admin.Template=function(a){window.alert("Template "+a)},Charcoal.Admin.Template_Login=function(a){this.template_type="charcoal/admin/template/login",this.init(a)},Charcoal.Admin.Template_Login.prototype=Object.create(Charcoal.Admin.Template.prototype),Charcoal.Admin.Template_Login.prototype.constructor=Charcoal.Admin.Template_Login,Charcoal.Admin.Template_Login.prototype.parent=Charcoal.Admin.Template.prototype,Charcoal.Admin.Template_Login.prototype.init=function(a){window.console.debug(a),this.bind_events()},Charcoal.Admin.Template_Login.prototype.bind_events=function(){$("#login-form").on("submit.charcoal.login",function(a){a.preventDefault();var b=$(this),c=b.prop("action")||window.location.href,d=b.serialize();$.post(c,d,function(a){window.console.debug(a),a.success?window.location.href=a.next_url:BootstrapDialog.show({title:authL10n.login,message:commonL10n.authFailed,type:BootstrapDialog.TYPE_DANGER})},"json").fail(function(){BootstrapDialog.show({title:authL10n.login,message:commonL10n.authFailed,type:BootstrapDialog.TYPE_DANGER})})})},Charcoal.Admin.Template_MenuHeader=function(){$(".js-toggle-class").click(function(a){a.preventDefault();var b=$(this),c=b.data("class"),d=b.data("target");$(d).toggleClass(c)}),$(document).on("click",".js-accordion-header",function(a){a.preventDefault(),$(this).toggleClass("is-open").siblings(".js-accordion-content").stop().slideToggle()})},Charcoal.Admin.Template_Account_LostPassword=function(a){this.template_type="charcoal/admin/template/account/lost-password",this.init(a)},Charcoal.Admin.Template_Account_LostPassword.prototype=Object.create(Charcoal.Admin.Template.prototype),Charcoal.Admin.Template_Account_LostPassword.prototype.constructor=Charcoal.Admin.Template_Account_LostPassword,Charcoal.Admin.Template_Account_LostPassword.prototype.parent=Charcoal.Admin.Template.prototype,Charcoal.Admin.Template_Account_LostPassword.prototype.init=function(a){window.console.debug(a),this.bind_events()},Charcoal.Admin.Template_Account_LostPassword.prototype.bind_events=function(){$("#lost-password-form").on("submit.charcoal.password",function(a){a.preventDefault();var b=$(this),c=b.prop("action")||window.location.href,d=b.serialize();$.post(c,d,function(a){window.console.debug(a),BootstrapDialog.show({title:authL10n.lostPassword,message:authL10n.lostPassSuccess,type:BootstrapDialog.TYPE_SUCCESS,onhidden:function(){window.location.reload()}})},"json").fail(function(){BootstrapDialog.show({title:authL10n.lostPassword,message:authL10n.lostPassFailed,type:BootstrapDialog.TYPE_DANGER,onhidden:function(){window.grecaptcha.reset()}})})})},Charcoal.Admin.Template_Account_ResetPassword=function(a){this.template_type="charcoal/admin/template/account/reset-password",this.init(a)},Charcoal.Admin.Template_Account_ResetPassword.prototype=Object.create(Charcoal.Admin.Template.prototype),Charcoal.Admin.Template_Account_ResetPassword.prototype.constructor=Charcoal.Admin.Template_Account_ResetPassword,Charcoal.Admin.Template_Account_ResetPassword.prototype.parent=Charcoal.Admin.Template.prototype,Charcoal.Admin.Template_Account_ResetPassword.prototype.init=function(a){window.console.debug(a),this.bind_events()},Charcoal.Admin.Template_Account_ResetPassword.prototype.bind_events=function(){$("#reset-password-form").on("submit.charcoal.password",function(a){a.preventDefault();var b=$(this),c=b.prop("action")||window.location.href,d=b.serialize();$.post(c,d,function(a){window.console.debug(a),BootstrapDialog.show({title:authL10n.passwordReset,message:authL10n.resetPassSuccess,type:BootstrapDialog.TYPE_SUCCESS,onhidden:function(){window.location.href=Charcoal.Admin.admin_url()+"login"}})},"json").fail(function(){BootstrapDialog.show({title:authL10n.passwordReset,message:authL10n.resetPassFailed,type:BootstrapDialog.TYPE_DANGER,onhidden:function(){window.grecaptcha.reset()}})})})}; \ No newline at end of file diff --git a/assets/src/scripts/charcoal/admin/widget.js b/assets/src/scripts/charcoal/admin/widget.js index ce337d2701..e444b44fa8 100644 --- a/assets/src/scripts/charcoal/admin/widget.js +++ b/assets/src/scripts/charcoal/admin/widget.js @@ -37,6 +37,7 @@ Charcoal.Admin.Widget = function (opts) { if (typeof opts.id === 'string') { this.set_element($('#' + opts.id)); this.set_id(opts.id); + this.widget_id = opts.widget_id || opts.id; } if (typeof opts.type === 'string') { @@ -60,13 +61,27 @@ Charcoal.Admin.Widget.prototype.set_opts = function (opts) { return this; }; +/** + * Add option + * @param {String} ident + * @param {Mixed} val + * @return this (chainable) + */ +Charcoal.Admin.Widget.prototype.add_opts = function (ident, val) { + if (typeof ident === 'string') { + this._opts[ident] = val; + } + + return this; +}; + /** * If a ident is specified, the method tries to return * the options pointed out. * If no ident is specified, the method returns * the whole opts object * - * @param {String} ident | falcultative + * @param {String} [ident] * @return {Object|Mixed|false} */ Charcoal.Admin.Widget.prototype.opts = function (ident) { @@ -194,7 +209,11 @@ Charcoal.Admin.Widget.prototype.reload = function (callback) { contentType: 'application/json', success: function (response) { if (typeof response.widget_id === 'string') { - that.set_id(response.widget_id); + var wid = response.widget_id; + that.set_id(wid); + that.add_opts('id', wid); + that.add_opts('widget_id', wid); + that.widget_id = wid; that.anim_out(function () { that.element().replaceWith(response.widget_html); that.set_element($('#' + that.id())); diff --git a/assets/src/scripts/charcoal/admin/widget/table.js b/assets/src/scripts/charcoal/admin/widget/table.js index 6b58ff0551..59990baffc 100644 --- a/assets/src/scripts/charcoal/admin/widget/table.js +++ b/assets/src/scripts/charcoal/admin/widget/table.js @@ -194,8 +194,8 @@ Charcoal.Admin.Widget_Table.prototype.bind_events = function () } }).disableSelection(); - $('.js-page-switch').on('click', function (e) { - e.preventDefault(); + $('.js-page-switch', that.table_selector).on('click', function (event) { + event.preventDefault(); var $this = $(this); var page_num = $this.data('page-num');