(function(){Djblets.Avatars={};"use strict";Djblets.Avatars.Settings=Backbone.Model.extend({defaults:function defaults(){return{configuration:{},serviceID:null,services:{}}}});"use strict";Djblets.Avatars.ServiceSettingsFormView=Backbone.View.extend({validate:function validate(){return true}});"use strict";var _slicedToArray=function(){function sliceIterator(arr,i){var _arr=[];var _n=true;var _d=false;var _e=undefined;try{for(var _i=arr[Symbol.iterator](),_s;!(_n=(_s=_i.next()).done);_n=true){_arr.push(_s.value);if(i&&_arr.length===i)break}}catch(err){_d=true;_e=err}finally{try{if(!_n&&_i["return"])_i["return"]()}finally{if(_d)throw _e}}return _arr}return function(arr,i){if(Array.isArray(arr)){return arr}else if(Symbol.iterator in Object(arr)){return sliceIterator(arr,i)}else{throw new TypeError("Invalid attempt to destructure non-iterable instance")}}}();(function(){var _Promise$withResolver=Promise.withResolver(),_Promise$withResolver2=_slicedToArray(_Promise$withResolver,2),readyPromise=_Promise$withResolver2[0],resolve=_Promise$withResolver2[1];Djblets.Avatars.SettingsFormView=Backbone.View.extend({events:{"change #id_avatar_service_id":"_onServiceChanged",submit:"_onSubmit"},initialize:function initialize(){var _this=this;console.assert(Djblets.Avatars.SettingsFormView.instance===null);Djblets.Avatars.SettingsFormView.instance=this;this._configForms=new Map;this._$config=this.$(".avatar-service-configuration");var services=this.model.get("services");this.listenTo(this.model,"change:serviceID",function(){return _this._showHideForms()});resolve()},_onSubmit:function _onSubmit(e){var serviceID=this.model.get("serviceID");var currentForm=this._configForms.get(serviceID);if(currentForm&&!currentForm.validate()){e.preventDefault()}},renderForms:function renderForms(){var _iteratorNormalCompletion=true;var _didIteratorError=false;var _iteratorError=undefined;try{for(var _iterator=this._configForms.values()[Symbol.iterator](),_step;!(_iteratorNormalCompletion=(_step=_iterator.next()).done);_iteratorNormalCompletion=true){var form=_step.value;form.render()}}catch(err){_didIteratorError=true;_iteratorError=err}finally{try{if(!_iteratorNormalCompletion&&_iterator.return){_iterator.return()}}finally{if(_didIteratorError){throw _iteratorError}}}this.$("#id_avatar_service_id").change();this._showHideForms(true);return this},_showHideForms:function _showHideForms(){var services=this.model.get("services");var serviceID=this.model.get("serviceID");var currentForm=this._configForms.get(serviceID);var previousID=this.model.previous("serviceID");var previousForm=previousID?this._configForms.get(previousID):undefined;if(previousForm&&currentForm){previousForm.$el.hide();currentForm.$el.show()}else if(previousForm){previousForm.$el.hide();this._$config.hide()}else if(currentForm){currentForm.$el.show();this._$config.show()}},_onServiceChanged:function _onServiceChanged(e){var $target=$(e.target);this.model.set("serviceID",$target.val())}},{instance:null,addConfigForm:function addConfigForm(serviceID,formClass){Djblets.Avatars.SettingsFormView.instance._configForms.set(serviceID,new formClass({el:$('[data-avatar-service-id="'+serviceID+'"]'),model:Djblets.Avatars.SettingsFormView.instance.model}))},ready:readyPromise})})();"use strict";(function(){var allowedMimeTypes=["image/png","image/jpeg","image/gif"];Djblets.Avatars.FileUploadSettingsFormView=Djblets.Avatars.ServiceSettingsFormView.extend({events:{"change #id_file-upload-avatar_upload":"_onFileChanged"},validate:function validate(){var file=this.$("#id_file-upload-avatar_upload")[0].files[0];if(!file){alert(gettext("You must choose a file."));return false}if(!allowedMimeTypes.some(function(el){return el===file.type})){alert(gettext("Invalid file format"));return false}return true},render:function render(){this._$preview=this.$(".avatar-preview");return this},_onFileChanged:function _onFileChanged(e){var _this=this;var file=e.target.files[0];if(file){var reader=new FileReader;reader.addEventListener("load",function(){_this._$preview.children().eq(0).replaceWith($("<img />").attr("src",reader.result))});reader.readAsDataURL(file)}}})})()}).call(this);