diff --git a/src/main/webapp/scripts/xnat/app/codeEditor.js b/src/main/webapp/scripts/xnat/app/codeEditor.js index 87c0968bc51d20579fd5a229922f58cb2417d527..e821ab4cd27f79c1a2cb8b28c4b0dc2a267e86ce 100644 --- a/src/main/webapp/scripts/xnat/app/codeEditor.js +++ b/src/main/webapp/scripts/xnat/app/codeEditor.js @@ -39,7 +39,9 @@ var XNAT = getObject(XNAT || {}); this.isInput = (function(){ return _this.$source.is(':input') })(); - this.isUrl = !this.source && this.opts.url; + this.isUrl = !this.source && (this.opts.loadUrl || this.opts.load || this.opts.url); + + this.loadUrl = this.isUrl ? (this.opts.loadUrl || this.opts.load || this.opts.url) : null; // set default language for editor // add [data-code-language="javascript"] to source code element @@ -51,13 +53,18 @@ var XNAT = getObject(XNAT || {}); // set source to null or empty string // and opts.url = '/url/to/data' to // pull code from a REST call - this.code = ''; + return XNAT.xhr.get(this.loadUrl); } else { // extract code from the source this.code = this.isInput ? this.$source.val() : this.$source.html(); } - return this.code + return this.code; + // return { + // done: function(callback){ + // callback.call(_this, _this.code); + // } + // } }; // @@ -83,8 +90,8 @@ var XNAT = getObject(XNAT || {}); if (this.isUrl){ // save via ajax return xhr.request(extend(true, { - method: method, - url: url, + method: method || _this.opts.submitMethod || _this.opts.method, + url: url || _this.opts.submitUrl || _this.opts.url, success: function(){ _this.dialog.close() } @@ -158,16 +165,18 @@ var XNAT = getObject(XNAT || {}); opts = cloneObject(opts); // insert additional content above editor - if (opts.before || opts.contentTop) { - modal.content += opts.before || opts.contentTop; + if (opts.before) { + modal.content += '<div class="before-editor">' + opts.before + '</div>'; + delete opts.before; // don't pass this to xmodal.open() } // div container for code editor modal.content += '<div class="code-editor" style="width:840px;height:440px;position:relative;"></div>'; // insert additional content BELOW editor - if (opts.after || opts.contentBottom) { - modal.content += opts.after || opts.contentBottom; + if (opts.after) { + modal.content += '<div class="after-editor">' + opts.after + '</div>'; + delete opts.after; // don't pass this to xmodal.open() } modal.title = 'XNAT Code Editor'; diff --git a/src/main/webapp/scripts/xnat/ui/input.js b/src/main/webapp/scripts/xnat/ui/input.js index 5d5137f501af7908924c642584f97e938926394f..0f829de3d4a177c726c3ad6c6e8a3562768575e1 100644 --- a/src/main/webapp/scripts/xnat/ui/input.js +++ b/src/main/webapp/scripts/xnat/ui/input.js @@ -112,7 +112,7 @@ var XNAT = getObject(XNAT); otherTypes = [ 'password', 'date', 'file', - 'radio', 'button', 'hidden' + 'button', 'hidden' ]; otherTypes.forEach(function(type){ input[type] = function(config){ @@ -129,19 +129,32 @@ var XNAT = getObject(XNAT); // }; return setupType('checkbox', '', config); }; - - // create an input with display: block style - input.text.block = function(config){ - config = extend(true, {}, config, config.element, { - $: { addClass: 'text block' }, - style: { display: 'block' } - }); - return input.text(config); + + // radio buttons are special too + input.radio = function(config){ + otherTypes.push('radio'); + config = extend(true, {}, config, config.element); }; // save a list of all available input types input.types = [].concat(textTypes, numberTypes, otherTypes); + // create display: block versions of ALL input types + input.types.forEach(function(type, i){ + input[type]['block'] = function(config){ + config = extend(true, {}, config, config.element, { + $: { addClass: 'display-block' }, + style: { display: 'block' } + }); + return input[type](config); + } + }); + + // // not *technically* an <input> element, but a form input nonetheless + // input.textarea = function(config){ + // + // }; + // after the page is finished loading, set empty // input values from [data-lookup] attribute $(window).on('load', function(){ diff --git a/src/main/webapp/scripts/xnat/ui/panel.js b/src/main/webapp/scripts/xnat/ui/panel.js index 682c4dbdc9795d3b22fdb46de2997962ddb58d19..1e9969d87073a77a800586ce8deac03e165426a8 100644 --- a/src/main/webapp/scripts/xnat/ui/panel.js +++ b/src/main/webapp/scripts/xnat/ui/panel.js @@ -228,7 +228,7 @@ var XNAT = getObject(XNAT || {}); $this.not(':radio').changeVal(val); if (/checkbox/i.test(this.type)) { - this.checked = !!this.value; + this.checked = (this.value === val || !!this.value); } if (/radio/i.test(this.type)) { @@ -875,14 +875,13 @@ var XNAT = getObject(XNAT || {}); addDataObjects(opts.element, { codeLanguage: opts.code }); + // open code editor on double-click + opts.element.ondblclick = function(){ + var panelTextarea = XNAT.app.codeEditor.init(this, { language: opts.code || 'html' }); + panelTextarea.openEditor(); + }; } - // open code editor on double-click - opts.element.ondblclick = function(){ - var panelTextarea = XNAT.app.codeEditor.init(this, { language: opts.code || 'html' }); - panelTextarea.openEditor(); - }; - opts.element.rows = opts.rows || opts.element.rows || 10; var textarea = spawn('textarea', opts.element);