diff --git a/package.json b/package.json index 7b11020..22539c2 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "gdapi-ui", - "version": "1.2.3", + "version": "1.2.4", "dependencies": { "gd-assets": "1.0.x" } diff --git a/public/css/main.css b/public/css/main.css index 27cdab1..94c6d23 100644 --- a/public/css/main.css +++ b/public/css/main.css @@ -214,25 +214,26 @@ LI { font-family: "Monaco", "Andale Mono", "Courier New", "Courier", monospace; } -#json { +.json { font-family: "Monaco", "Andale Mono", "Courier New", "Courier", monospace; white-space: pre-wrap; line-height: normal; } -#json LI { +.json LI { line-height: normal; } -#json UL { +.json UL { list-style: none; - margin: 0 0 0 2em; + margin: 0 0 0 20px; padding: 0; } -#json LI .icon { +.json LI .icon { position: relative; left: -15px; + margin-right: -15px; } H1 { diff --git a/public/js/HTMLApi.js b/public/js/HTMLApi.js index b7e1883..7d31ac7 100644 --- a/public/js/HTMLApi.js +++ b/public/js/HTMLApi.js @@ -10,10 +10,12 @@ function HTMLApi(data, docs, user, cb) this._reqModal = null; this._editSchema = null; + this._editData = null; this._lastMethod = null; - this._lastBody = null; + this._lastMode = null; this._lastType = null; this._lastOpt = null; + this._lastRequestBody = null; this._referenceDropdownLimit = 100; this._magicNull = "__-*NULL*-__"; @@ -381,7 +383,7 @@ HTMLApi.prototype.actionLoad = function(name, obj, body) { var self = this; - this._lastBody = body||this._lastBody||{}; + this._lastRequestBody = body||this._lastRequestBody||{}; if ( !obj ) obj = this._data; @@ -416,7 +418,7 @@ HTMLApi.prototype.actionLoad = function(name, obj, body) var tpl = {}; var mode = 'action'; - tpl.fields = self._flattenFields(mode, actionInput, self._lastBody); + tpl.fields = self._flattenFields(mode, actionInput, self._lastRequestBody); tpl.hasFields = tpl.fields.length > 0; tpl.mode = mode; tpl.createTypes = false; @@ -428,7 +430,7 @@ HTMLApi.prototype.actionLoad = function(name, obj, body) var html = Handlebars.templates['edit'](tpl); var popinActions = [ - {id: 'ok', text: 'Show Request', /*on_enter: true, */ onClick: function() { self.showRequest('POST',actionInput,retry,url); }.bind(self) }, + {id: 'ok', text: 'Show Request', /*on_enter: true, */ onClick: function() { self.showRequest(mode,'POST',actionInput,retry,url); }.bind(self) }, {id: 'cancel', text: 'Cancel', cancel: true } ]; @@ -507,27 +509,38 @@ HTMLApi.prototype.filterAdd = function(name, modifier, value, before) if ( !name ) { // Get the first filter name - name = schemaFilters[ Object.keys(schemaFilters)[0] ]; + name = Object.keys(schemaFilters)[0]; } + if ( !modifier && schemaFilters[name] && schemaFilters[name]['modifiers'] ) + { + modifier = schemaFilters[name]['modifiers'][0]; + } + + if ( !modifier ) + modifier = 'eq'; + var cur = { name: name, - modifier: modifier || 'eq', + modifier: modifier, value: value || '' }; - html = Handlebars.templates['filter']({ + var html = Handlebars.templates['filter']({ allFilterSchema: schemaFilters, thisFilterSchema: schemaFilters[name], cur: cur }); + var $elem = $(html); if( before ) - $(before).before(html); + $elem = $(before).before($elem); else - $('#filter-body').append(html); + $lem = $('#filter-body').append($elem); $('#no-filters').hide(); + this.modifierChange($elem); + return $elem; } HTMLApi.prototype.filterRemove = function(elem) @@ -552,24 +565,36 @@ HTMLApi.prototype.filterChange = function(elem) var value = $('#'+prefix+'_value').val(); this.filterRemove(elem); - this.filterAdd(name, modifier, value, next); + $elem = this.filterAdd(name, modifier, value, next); } -HTMLApi.prototype.modifierChange = function(elem) +HTMLApi.prototype.modifierChange = function(inElem) { - var $elem = $(elem); - var modifier = $elem.val(); - var $row = $elem.parents('.filter'); - var prefix = $row.data('prefix'); - var $input = $(prefix+'_value'); + var $elem, $row, prefix; + if ( inElem.tagName == 'select' ) + { + $elem = $(inElem); + $row = $elem.parents('.filter'); + prefix = $row.data('prefix'); + } + else + { + $row = $(inElem); + prefix = $row.data('prefix'); + $elem = $('#'+prefix+'_modifier'); + } - $input.toggle( (modifier != 'null' && modifier != 'notnull') ); + var modifier = $elem.val(); + var $input = $('#'+prefix+'_value'); + var on = (modifier != 'null' && modifier != 'notnull'); + + $input.toggle(on); } HTMLApi.prototype.filterApply = function(clear) { var $rows = $('#filters DIV.filter'); - var $row,name,modifier,value; + var $row,prefix,name,modifier,value; var query = ''; @@ -722,7 +747,7 @@ HTMLApi.prototype.request = function(method,body,opt,really) opt = opt || {}; this._lastOpt = opt; - this._lastBody = body; + this._lastRequestBody = body; this._lastMethod = method; var url = opt.url || this._data.links.self || window.location.href; @@ -872,7 +897,7 @@ HTMLApi.prototype.requestDone = function(err, body, res) if ( body.links && body.links.self ) selfUrl = body.links.self; - out = this._formatter.valueToHTML(body) + out = '