%PDF- %PDF-
| Direktori : /data/old/home/stash/atlassian/stash/3.7.1/atlassian-stash/static/util/ |
| Current File : //data/old/home/stash/atlassian/stash/3.7.1/atlassian-stash/static/util/config-form-min.js |
define("util/config-form",["aui","jquery","lodash","util/ajax"],function(G,D,H,F){function C(L,K){return H.isFunction(L)?L(H.extend({},K)):L}var I={};function A(O,N){var M={};N=H.extend({},N,O.params);if(O["context-provider"]){N=C(O["context-provider"],N)}var L;try{H.each(O,function(T,R){if(!(/params|context-provider|view/.test(R))){M[R]=C(O[R],N)}else{if(R==="view"){var Q=T(N);if(Q){var S={};if(typeof Q==="object"){S=H.extend(S,Q)}if(Q.loadTransformer){N.config=C(Q.loadTransformer,N.config)}var P=H.isFunction(Q.formContents)?Q.formContents:Q;S.formContents=C(P,N);M.view=S}}}})}catch(K){L=K}if(!M.view){M.view={formContents:aui.message.error({content:G.escapeHtml(G.I18n.getText("stash.web.config.form.load.error",M.pluginKey+":"+M.key,L?L:"Unknown error"))})}}M.moduleKey=M.key;M.completeModuleKey=M.pluginKey+":"+M.key;I[M.completeModuleKey]=M;return M}function B(K){return I[K.pluginKey+":"+K.key]}function E(L){var K=WebFragments.getWebFragmentDescriptors(L,"panel");if(K&&K.length){return K[0]}else{return null}}function J(L,K){this.$container=D(L);this.configContextName=K}J.prototype.loadAndRender=function(K){return D.when(K(),this._loadWebResources().fail(H.bind(function(L){this.$container.html(aui.message.error({content:L.message}))},this))).done(H.bind(function(L){this._render(L[0])},this))};J.prototype._loadWebResources=function(){return WRM.require("wrc!"+this.configContextName)};J.prototype._render=function(N,K,O){var M={config:N||{},errors:K};var P=E(this.configContextName);var L=A(P,M);this.$container.empty();if(L&&L.view&&L.view.formContents){this.$container.append(stash.widget.form({content:L.view.formContents,action:"",errors:O}));this.$container.find(":input:visible:enabled:first").first().focus()}if(L&&L.view&&L.view.initForm){L.view.initForm(N)}};J.prototype.save=function(M){var L=F.formToJSON(this.$container.find("form.aui"));var N=E(this.configContextName);var K=B(N);if(K&&K.view&&K.view.saveTransformer){L=K.view.saveTransformer(L)}return D.when(M(L)).fail(H.bind(this._validationErrors,this,L))};J.prototype._validationErrors=function(L,N,P,M,K){var O=H.reduce(K.errors,function(Q,R){Q[R.context]=(Q[R.context]||[]).concat([R.message]);return Q},{});this._render(L,O,O[null])};return J});var ConfigForm=require("util/config-form");