This repository has been archived by the owner on Oct 31, 2023. It is now read-only.
forked from cozy/cozy-clearance
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient-build.min.js
1 lines (1 loc) · 15.2 KB
/
client-build.min.js
1
require.register("cozy-clearance/contact_autocomplete",function(t,e,n){n.exports=function(t,n,r){var o;return o=e("./contact_collection"),null==r&&(r=function(){return!0}),t.on("keyup",function(){return function(e){return 13!==e.which||t.data("typeahead").shown?void 0:(n(t.val()),t.val(""),e.preventDefault())}}(this)),t.typeahead({source:function(t){var e,n,a;return a=new RegExp(t),e=o.filter(function(t){return t.match(a)}),n=[],e.forEach(function(t){return t.get("emails").forEach(function(e){return n.push({id:t.id,hasPicture:t.get("hasPicture"),display:""+t.get("name")+" <"+e+">",toString:function(){return""+e+";"+t.id}})})}),n=n.filter(r)},matcher:function(t){var e;return e=$.fn.typeahead.Constructor.prototype.matcher,e.call(this,t.display)},sorter:function(t){var e,n,r,o,a;for(e=[],r=[],n=[];o=t.shift();)a=o.display,a.toLowerCase().indexOf(this.query.toLowerCase())?~a.indexOf(this.query)?r.push(o):n.push(o):e.push(o);return e.concat(r,n)},highlighter:function(t){var e,n;return n=$.fn.typeahead.Constructor.prototype.highlighter,e=t.hasPicture?'<img width="40" src="clearance/contacts/'+t.id+'.jpg"> ':'<img width="40" src="images/defaultpicture.png"> ',e+n.call(this,t.display)},updater:function(){return function(t){return n(t),""}}(this)})}}),require.register("cozy-clearance/contact_collection",function(t,e,n){var r,o,a={}.hasOwnProperty,i=function(t,e){function n(){this.constructor=t}for(var r in e)a.call(e,r)&&(t[r]=e[r]);return n.prototype=e.prototype,t.prototype=new n,t.__super__=e.prototype,t};o=new Backbone.Collection,o.url="clearance/contacts",o.model=r=function(t){function e(){return e.__super__.constructor.apply(this,arguments)}return i(e,t),e.prototype.match=function(t){return t.test(this.get("name"))||this.get("emails").some(function(e){return t.test(e)})},e}(Backbone.Model),o.fetch(),n.exports=o}),require.register("cozy-clearance/modal",function(e,n,r){var o,a=function(t,e){return function(){return t.apply(e,arguments)}},i={}.hasOwnProperty,s=function(t,e){function n(){this.constructor=t}for(var r in e)i.call(e,r)&&(t[r]=e[r]);return n.prototype=e.prototype,t.prototype=new n,t.__super__=e.prototype,t};o=function(t){function e(){return this.closeOnEscape=a(this.closeOnEscape,this),e.__super__.constructor.apply(this,arguments)}return s(e,t),e.prototype.id="modal-dialog",e.prototype.className="modal fade",e.prototype.attributes={"data-backdrop":"static","data-keyboard":"false"},e.prototype.initialize=function(t){return null==this.title&&(this.title=t.title),null==this.content&&(this.content=t.content),null==this.yes&&(this.yes=t.yes||"ok"),null==this.no&&(this.no=t.no||"cancel"),null==this.cb&&(this.cb=t.cb||function(){}),this.render(),this.saving=!1,this.$el.modal("show"),this.$("button.close").click(function(t){return function(e){return e.stopPropagation(),t.onNo()}}(this)),$(document).on("keyup",this.closeOnEscape)},e.prototype.events=function(){return{"click #modal-dialog-no":"onNo","click #modal-dialog-yes":"onYes",click:"onClickAnywhere"}},e.prototype.onNo=function(){return this.closing?void 0:(this.closing=!0,this.$el.modal("hide"),setTimeout(function(t){return function(){return t.remove()}}(this),500),this.cb(!1))},e.prototype.onYes=function(){return this.closing?void 0:(this.closing=!0,this.$el.modal("hide"),setTimeout(function(t){return function(){return t.remove()}}(this),500),this.cb(!0))},e.prototype.closeOnEscape=function(t){return 27===t.which?this.onNo():void 0},e.prototype.remove=function(){return $(document).off("keyup",this.closeOnEscape),e.__super__.remove.apply(this,arguments)},e.prototype.render=function(){var t,e,n,r,o,a,i;return e=$('<button class="close" type="button" data-dismiss="modal" aria-hidden="true">×</button>'),a=$('<h4 class="model-title">').text(this.title),o=$('<div class="modal-header">').append(e,a),t=$('<div class="modal-body">').append(this.renderContent()),i=$('<button id="modal-dialog-yes" class="btn btn-cozy">').text(this.yes),r=$('<div class="modal-footer">').append(i),this.no&&r.prepend($('<button id="modal-dialog-no" class="btn btn-link">').text(this.no)),n=$('<div class="modal-content">').append(o,t,r),n=$('<div class="modal-dialog">').append(n),$("body").append(this.$el.append(n))},e.prototype.renderContent=function(){return this.content},e.prototype.onClickAnywhere=function(t){return t.target.id===this.id?this.onNo():void 0},e}(Backbone.View),o.alert=function(t,e,n){return new o({title:t,content:e,yes:"ok",no:null,cb:n})},o.confirm=function(t,e,n,r,a){return new o({title:t,content:e,yes:n,no:r,cb:a})},o.error=function(e,n){return new ModalView(t("modal error"),e,t("modal ok"),!1,n)},r.exports=o}),require.register("cozy-clearance/modal_share_template",function(e,n,r){function o(e){var n,r=[],o=e||{};return function(t,e,o,a,i,s,c){r.push("<p>"+jade.escape(null==(n=t("modal question "+e+" shareable",{name:o.get("name")}))?"":n)+'</p><p><button id="share-public" class="button btn-cozy">'+jade.escape(null==(n=t("public"))?"":n)+'</button> <button id="share-private" class="button btn-cozy">'+jade.escape(null==(n=t("private"))?"":n)+"</button></p>"),"public"==a?r.push("<p>"+jade.escape(null==(n=t("modal shared "+e+" link msg"))?"":n)+'</p><input id="public-url"'+jade.attr("value",i(),!0,!1)+' class="form-control"/>'):(r.push("<p>"+jade.escape(null==(n=t("only you can see"))?"":n)+'</p><form role="form" class="input-group"><input id="share-input" type="text"'+jade.attr("placeholder",t("modal shared "+e+" custom msg"),!0,!1)+' class="form-control"/><a id="add-contact" class="btn btn-cozy">Add</a></form><ul id="share-list">'),function(){var e=a;if("number"==typeof e.length)for(var o=0,l=e.length;l>o;o++){var u=e[o],p=u.key;r.push('<li class="clearance-line">'),u.contact?(r.push(u.contact.get("hasPicture")?'<img width="40"'+jade.attr("src","clearance/contacts/"+u.contact.id+".jpg",!0,!1)+"/> ":'<img width="40" src="images/defaultpicture.png"/> '),r.push('<span class="clearance-name">'+jade.escape(null==(n=u.contact.get("name"))?"":n)+"</span>")):r.push('<span class="clearance-name">'+jade.escape(null==(n=u.email)?"":n)+"</span>");var h=s.keys(c);h.length>1?(r.push("<select"+jade.attr("data-key",p,!0,!1)+' class="changeperm">'),function(){var e=c;if("number"==typeof e.length)for(var o=0,a=e.length;a>o;o++){var i=e[o];r.push("<option"+jade.attr("value",o,!0,!1)+jade.attr("selected",u.perm==o,!0,!1)+">"+jade.escape(null==(n=" "+t("perm")+t(i))?"":n)+"</option>")}else{var a=0;for(var o in e){a++;var i=e[o];r.push("<option"+jade.attr("value",o,!0,!1)+jade.attr("selected",u.perm==o,!0,!1)+">"+jade.escape(null==(n=" "+t("perm")+t(i))?"":n)+"</option>")}}}.call(this),r.push("</select>")):r.push(jade.escape(null==(n=" "+t("perm")+c[h[0]])?"":n)),r.push("<a"+jade.attr("data-key",p,!0,!1)+jade.attr("title",t("revoke"),!0,!1)+' class="clearance-btn pull-right revoke"><i class="icon-remove"></i></a><a'+jade.attr("data-key",p,!0,!1)+jade.attr("title",t("see link"),!0,!1)+jade.attr("href",i(p),!0,!1)+' class="clearance-btn pull-right show-link"><i class="glyphicon glyphicon-link"></i></a></li>')}else{var l=0;for(var o in e){l++;var u=e[o],p=u.key;r.push('<li class="clearance-line">'),u.contact?(r.push(u.contact.get("hasPicture")?'<img width="40"'+jade.attr("src","clearance/contacts/"+u.contact.id+".jpg",!0,!1)+"/> ":'<img width="40" src="images/defaultpicture.png"/> '),r.push('<span class="clearance-name">'+jade.escape(null==(n=u.contact.get("name"))?"":n)+"</span>")):r.push('<span class="clearance-name">'+jade.escape(null==(n=u.email)?"":n)+"</span>");var h=s.keys(c);h.length>1?(r.push("<select"+jade.attr("data-key",p,!0,!1)+' class="changeperm">'),function(){var e=c;if("number"==typeof e.length)for(var o=0,a=e.length;a>o;o++){var i=e[o];r.push("<option"+jade.attr("value",o,!0,!1)+jade.attr("selected",u.perm==o,!0,!1)+">"+jade.escape(null==(n=" "+t("perm")+t(i))?"":n)+"</option>")}else{var a=0;for(var o in e){a++;var i=e[o];r.push("<option"+jade.attr("value",o,!0,!1)+jade.attr("selected",u.perm==o,!0,!1)+">"+jade.escape(null==(n=" "+t("perm")+t(i))?"":n)+"</option>")}}}.call(this),r.push("</select>")):r.push(jade.escape(null==(n=" "+t("perm")+c[h[0]])?"":n)),r.push("<a"+jade.attr("data-key",p,!0,!1)+jade.attr("title",t("revoke"),!0,!1)+' class="clearance-btn pull-right revoke"><i class="icon-remove"></i></a><a'+jade.attr("data-key",p,!0,!1)+jade.attr("title",t("see link"),!0,!1)+jade.attr("href",i(p),!0,!1)+' class="clearance-btn pull-right show-link"><i class="glyphicon glyphicon-link"></i></a></li>')}}}.call(this),r.push("</ul>"))}("t"in o?o.t:"undefined"!=typeof t?t:void 0,"type"in o?o.type:"undefined"!=typeof type?type:void 0,"model"in o?o.model:"undefined"!=typeof model?model:void 0,"clearance"in o?o.clearance:"undefined"!=typeof clearance?clearance:void 0,"makeURL"in o?o.makeURL:"undefined"!=typeof makeURL?makeURL:void 0,"Object"in o?o.Object:"undefined"!=typeof Object?Object:void 0,"possible_permissions"in o?o.possible_permissions:"undefined"!=typeof possible_permissions?possible_permissions:void 0),r.join("")}r.exports=o}),require.register("cozy-clearance/modal_share_view",function(e,n,r){var o,a,i,s,c,l,u,p=function(t,e){return function(){return t.apply(e,arguments)}},h={}.hasOwnProperty,d=function(t,e){function n(){this.constructor=t}for(var r in e)h.call(e,r)&&(t[r]=e[r]);return n.prototype=e.prototype,t.prototype=new n,t.__super__=e.prototype,t};a=n("./modal"),c=n("./contact_autocomplete"),s=n("./contact_collection"),l=function(t){var e;for(null==t&&(t=32),e="";e.length<t;)e+=Math.random().toString(36).substr(2);return e.substr(0,t)},i=function(t,e){return"public"===t?[]:"public"===e?t:t.filter(function(t){return!_.findWhere(e,{key:t.key})})},u=function(t,e,n,r){var o;return o={method:t,url:e,dataType:"json",data:JSON.stringify(n),contentType:"application/json; charset=utf-8"},$.ajax(_.extend(o,r))},r.exports=o=function(e){function r(){return this.showLink=p(this.showLink,this),this.onClose=p(this.onClose,this),this.onYes=p(this.onYes,this),this.onNo=p(this.onNo,this),this.revoke=p(this.revoke,this),this.onGuestAdded=p(this.onGuestAdded,this),this.getClearanceWithContacts=p(this.getClearanceWithContacts,this),this.getRenderData=p(this.getRenderData,this),this.typeaheadFilter=p(this.typeaheadFilter,this),this.makeURL=p(this.makeURL,this),r.__super__.constructor.apply(this,arguments)}return d(r,e),r.prototype.id="cozy-clearance-modal",r.prototype.template_content=n("./modal_share_template"),r.prototype.events=function(){return _.extend(r.__super__.events.apply(this,arguments),{"click #share-public":"makePublic","click #share-private":"makePrivate","click #modal-dialog-share-save":"onSave","click .revoke":"revoke","click .show-link":"showLink","click #add-contact":"onAddClicked","change select.changeperm":"changePerm"})},r.prototype.permissions=function(){return{r:t("r")}},r.prototype.initialize=function(e){return this.cb=this.onClose,this.model=e.model,this.model.set("clearance",this.model.get("clearance")||[]),this.initState=JSON.parse(JSON.stringify(this.model.get("clearance"))),this.title=t("sharing"),this.yes=t("save"),this.no=t("cancel"),r.__super__.initialize.apply(this,arguments)},r.prototype.makeURL=function(t){var e;return e=this.model.getPublicURL(),t&&(e+="?key="+t),e},r.prototype.makePublic=function(){return"public"!==this.model.get("clearance")?(this.lastPrivate=this.model.get("clearance"),this.model.set({clearance:"public"}),this.refresh()):void 0},r.prototype.makePrivate=function(){return Array.isArray(this.model.get("clearance"))?void 0:(this.model.set({clearance:this.lastPrivate||[]}),this.refresh())},r.prototype.render=function(){var e;return r.__super__.render.call(this),e=$(".modal-footer"),e.prepend($("<span class='pull-left'>"+t("send email hint")+"</span>"))},r.prototype.afterRender=function(){var t;return t=this.model.get("clearance")||[],"public"===t?this.$("#share-public").addClass("toggled"):(this.$("#share-private").addClass("toggled"),c(this.$("#share-input"),this.onGuestAdded,this.typeaheadFilter)),setTimeout(function(e){return function(){return"public"===t?e.$("#public-url").focus().select():e.$("input#share-input").select()}}(this),100)},r.prototype.renderContent=function(){return $("<p>Please wait</p>")},r.prototype.typeaheadFilter=function(t){return!this.existsEmail(t.toString().split(";")[0])},r.prototype.existsEmail=function(t){return this.model.get("clearance").some(function(e){return e.email===t})},r.prototype.getRenderData=function(){return{type:this.model.get("type"),model:this.model,clearance:this.getClearanceWithContacts(),makeURL:this.makeURL,possible_permissions:this.permissions(),t:t}},r.prototype.getClearanceWithContacts=function(){var t;return t=this.model.get("clearance")||[],"public"===t?"public":t.map(function(t){var e;return e=_.clone(t),e.contactid&&(e.contact=s.get(t.contactid)),e})},r.prototype.refresh=function(){return this.$(".modal-body").html(this.template_content(this.getRenderData())),this.afterRender()},r.prototype.onAddClicked=function(){return this.onGuestAdded(this.$("#share-input").val())},r.prototype.onGuestAdded=function(t){var e,n,r,o,a;return a=t.split(";"),n=a[0],e=a[1],this.existsEmail(n)?null:(r=l(),o="r",this.model.get("clearance").push({email:n,contactid:e,key:r,perm:o}),this.refresh())},r.prototype.revoke=function(t){var e;return e=this.model.get("clearance").filter(function(e){return e.key!==t.currentTarget.dataset.key}),this.model.set({clearance:e}),this.refresh()},r.prototype.changePerm=function(t){var e;return e=t.currentTarget,this.model.get("clearance").filter(function(t){return t.key===e.dataset.key})[0].perm=e.options[e.selectedIndex].value,this.refresh()},r.prototype.onNo=function(){var e,n,o,s;return e=this.model.get("clearance"),o=0!==i(e,this.initState).length,n=e.length!==this.initState.length,s=o||n,s?a.confirm(t("confirm"),t("share confirm save"),t("yes"),t("no"),function(t){return function(e){return e?r.__super__.onNo.apply(t,arguments):void 0}}(this)):r.__super__.onNo.apply(this,arguments)},r.prototype.onYes=function(){var e,n;return e=this.model.get("clearance"),n=0!==i(e,this.initState).length,this.$("#share-input").val()&&!n?a.confirm(t("confirm"),t("share forgot add"),t("no forgot"),t("yes forgot"),function(t){return function(e){return e?r.__super__.onYes.apply(t,arguments):void 0}}(this)):r.__super__.onYes.apply(this,arguments)},r.prototype.onClose=function(e){var n,r;return e?(n=i(this.model.get("clearance"),this.initState),n.length?(r=t("send mails question")+n.map(function(t){return t.email}).join(", "),a.confirm(t("modal send mails"),r,t("yes"),t("no"),function(t){return function(e){return t.doSave(e,n)}}(this))):this.doSave(!1)):this.model.set({clearance:this.initState})},r.prototype.doSave=function(t,e){return u("PUT","clearance/"+this.model.id,this.saveData(),{error:function(){return a.error("server error occured")},success:function(n){return function(){return n.model.trigger("change"),t?u("POST","clearance/"+n.model.id+"/send",e,{error:function(){return a.error("mail not send")},success:function(){return n.$el.modal("hide")}}):n.$el.modal("hide")}}(this)})},r.prototype.saveData=function(){return{clearance:this.model.get("clearance")}},r.prototype.showLink=function(e){var n,r,o,a,i;return r=$(e.target).parents("li"),0===r.find(".linkshow").length?(o=$(e.currentTarget),a=o.prop("href"),r=$('<div class="linkshow">'),n=$("<label>").text(t("copy paste link")),i=$('<input type="text">').val(a),o.parents("li").append(r.append(n,i)),i.focus().select(),e.preventDefault()):r.find(".linkshow").remove(),!1},r}(a)});