-
Notifications
You must be signed in to change notification settings - Fork 0
/
atoms.app.appnima.user.js
1 lines (1 loc) · 5.5 KB
/
atoms.app.appnima.user.js
1
(function(){"use strict";var __bind=function(fn,me){return function(){return fn.apply(me,arguments)}},__hasProp={}.hasOwnProperty,__extends=function(child,parent){function ctor(){this.constructor=child}for(var key in parent)__hasProp.call(parent,key)&&(child[key]=parent[key]);return ctor.prototype=parent.prototype,child.prototype=new ctor,child.__super__=parent.prototype,child};Atoms.Organism.AppnimaProfile=function(_super){function AppnimaProfile(){return this.onFormChange=__bind(this.onFormChange,this),AppnimaProfile.__super__.constructor.apply(this,arguments)}return __extends(AppnimaProfile,_super),AppnimaProfile["extends"]=!0,AppnimaProfile.events=["error","change","logout"],AppnimaProfile["default"]={children:[{"Atom.Figure":{id:"avatar",style:"big",events:["touch"]}},{"Atom.Heading":{id:"mail"}},{"Molecule.Form":{id:"form",style:"margin-all",events:["change","error","submit"],children:[{"Atom.Input":{id:"username",type:"text",name:"username",placeholder:"Username..."}},{"Atom.Label":{text:"Other Information"}},{"Atom.Input":{id:"name",type:"text",name:"name",placeholder:"Name..."}},{"Atom.Input":{id:"phone",type:"tel",name:"phone",placeholder:"Phone..."}},{"Atom.Input":{id:"site",type:"text",name:"site",placeholder:"Site..."}},{"Atom.Button":{text:"Update profile",style:"margin-top fluid theme"}},{"Atom.Button":{text:"Logout",style:"fluid",callbacks:["onLogout"]}},{"Atom.Input":{id:"file",type:"file",events:["change"],callbacks:["onAvatarChange"]}}]}}]},AppnimaProfile.prototype.file=void 0,AppnimaProfile.prototype.render=function(){return AppnimaProfile.__super__.render.apply(this,arguments),null==window.Appnima?alert("ERROR: App/nima library not exists."):void 0},AppnimaProfile.prototype.show=function(){var field,session,value,_ref;if(AppnimaProfile.__super__.show.apply(this,arguments),session=Appnima.User.session()){this.avatar.refresh({url:session.avatar}),this.mail.refresh({text:session.mail});for(field in session)value=session[field],value&&null!=(_ref=this.form[field])&&_ref.value(value);return this.onFormChange()}},AppnimaProfile.prototype.onFigureTouch=function(){return this.form.file.el.trigger("click"),!1},AppnimaProfile.prototype.onAvatarChange=function(){var file_url,reader,_ref;return event.stopPropagation(),event.preventDefault(),file_url=event.target.files[0],(null!=file_url&&null!=(_ref=file_url.type)?_ref.match(/image.*/):void 0)&&(reader=new FileReader,reader.onerror=function(event){return alert("Error code: "+event.target.error)},reader.onload=function(_this){return function(event){return _this.file=event.target.result,_this.avatar.refresh({url:_this.file}),_this.onFormSubmit()}}(this),reader.readAsDataURL(file_url)),!1},AppnimaProfile.prototype.onFormChange=function(){var child,form,method,_i,_len,_ref;for(form=this.form.value(),method=""===form.mail?"attr":"removeAttr",_ref=this.form.children,_i=0,_len=_ref.length;_len>_i;_i++)child=_ref[_i],child.value||child.el[method]("disabled",!0);return!1},AppnimaProfile.prototype.onFormError=function(){return this.bubble("error",form),!1},AppnimaProfile.prototype.onFormSubmit=function(event,form){var parameters,_ref;return null!=(null!=(_ref=window.Appnima)?_ref.key:void 0)&&(parameters=(null!=form?form.value():void 0)||{},null!=this.file&&(parameters.avatar=this.file),__.Dialog.Loading.show(),window.Appnima.User.update(parameters).then(function(_this){return function(error,result){return error?_this.bubble("error",error):_this.bubble("change",result),__.Dialog.Loading.hide()}}(this))),!1},AppnimaProfile.prototype.onLogout=function(){return Appnima.User.logout().then(function(_this){return function(error,result){return _this.bubble("logout",result)}}(this))},AppnimaProfile}(Atoms.Organism.Section),Atoms.Organism.AppnimaSession=function(_super){function AppnimaSession(){return this.onFormChange=__bind(this.onFormChange,this),AppnimaSession.__super__.constructor.apply(this,arguments)}return __extends(AppnimaSession,_super),AppnimaSession["extends"]=!0,AppnimaSession.events=["login","signup","error"],AppnimaSession["default"]={style:"centered",children:[{"Atom.Image":{}},{"Molecule.Form":{id:"form",events:["change"],children:[{"Atom.Input":{id:"mail",type:"email",name:"mail",placeholder:"Email...",events:["keyup"],required:!0}},{"Atom.Input":{id:"password",type:"password",name:"password",placeholder:"Password...",events:["keyup"],required:!0}},{"Atom.Button":{text:"Login",action:"login",style:"fluid theme",callbacks:["onSubmit"]}},{"Atom.Button":{text:"Signup",action:"signup",style:"fluid",callbacks:["onSubmit"]}}]}},{"Atom.Text":{value:"© All Rights Reserved"}}]},AppnimaSession.prototype.render=function(){return AppnimaSession.__super__.render.apply(this,arguments),null!=window.Appnima?this.onFormChange():alert("ERROR: App/nima library not exists.")},AppnimaSession.prototype.onFormChange=function(){var child,form,method,_i,_len,_ref;for(form=this.form.value(),method=""===form.mail||""===form.password?"attr":"removeAttr",_ref=this.form.children,_i=0,_len=_ref.length;_len>_i;_i++)child=_ref[_i],child.value||child.el[method]("disabled",!0);return!1},AppnimaSession.prototype.onSubmit=function(event,button){var action,values,_ref;return null!=(null!=(_ref=window.Appnima)?_ref.key:void 0)?(action=button.attributes.action,values=this.form.value(),__.Dialog.Loading.show(),window.Appnima.User[action](values.mail,values.password).then(function(_this){return function(error,appnima){return error?_this.bubble("error",error):_this.bubble(action,appnima),__.Dialog.Loading.hide()}}(this))):alert("ERROR: Unknown App/nima key")},AppnimaSession}(Atoms.Organism.Section)}).call(this);