From 8fb5c531428be12adde8ab34d139a69b0a330e61 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Wed, 20 May 2015 11:21:19 -0700 Subject: [PATCH 1/2] handle initial values for hash tables --- domain-server/resources/web/js/settings.js | 39 +++++++++++++--------- 1 file changed, 23 insertions(+), 16 deletions(-) diff --git a/domain-server/resources/web/js/settings.js b/domain-server/resources/web/js/settings.js index 40c40eb4f7..94c270f520 100644 --- a/domain-server/resources/web/js/settings.js +++ b/domain-server/resources/web/js/settings.js @@ -767,7 +767,8 @@ $('body').on('click', '.save-button', function(e){ }); function makeTable(setting, keypath, setting_value, isLocked) { - var isArray = !_.has(setting, 'key') + var isArray = !_.has(setting, 'key'); + var isHash = !isArray; if (!isArray && setting.can_order) { setting.can_order = false; @@ -780,7 +781,8 @@ function makeTable(setting, keypath, setting_value, isLocked) { } html += ""; + + "' name='" + keypath + "' id='" + (typeof setting.html_id !== 'undefined' ? setting.html_id : keypath) + + "' data-setting-type='" + (isArray ? 'array' : 'hash') + "'>"; // Column names html += "" @@ -809,33 +811,38 @@ function makeTable(setting, keypath, setting_value, isLocked) { var row_num = 1; if (keypath.length > 0 && _.size(setting_value) > 0) { - _.each(setting_value, function(row, indexOrName) { - html += "" + _.each(setting_value, function(row, rowIndexOrName) { + html += "" if (setting.numbered === true) { html += "" } if (setting.key) { - html += "" + html += "" } _.each(setting.columns, function(col) { - html += "" + // setup the td for this column + html += ""; }) if (!isLocked && !setting.read_only) { From 227bdff07a96f7407154f82cfa782cc5b26c64c3 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Wed, 20 May 2015 11:31:32 -0700 Subject: [PATCH 2/2] fix width of re-order column --- domain-server/resources/web/css/style.css | 4 ++++ domain-server/resources/web/js/settings.js | 22 +++++++++++++++------- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/domain-server/resources/web/css/style.css b/domain-server/resources/web/css/style.css index 51275da509..952a504b13 100644 --- a/domain-server/resources/web/css/style.css +++ b/domain-server/resources/web/css/style.css @@ -65,6 +65,10 @@ td.buttons { width: 30px; } +td.buttons.reorder-buttons { + width: 40px; +} + td .glyphicon { text-align: center; font-size: 12px; diff --git a/domain-server/resources/web/js/settings.js b/domain-server/resources/web/js/settings.js index 94c270f520..044f846293 100644 --- a/domain-server/resources/web/js/settings.js +++ b/domain-server/resources/web/js/settings.js @@ -168,12 +168,20 @@ $(document).ready(function(){ if (sibling.hasClass(Settings.DATA_COL_CLASS)) { // set focus to next input - sibling.find('input').focus() - } else if (sibling.hasClass(Settings.ADD_DEL_BUTTONS_CLASS)) { - sibling.find('.' + Settings.ADD_ROW_BUTTON_CLASS).click() + sibling.find('input').focus(); + } else { - // set focus to the first input in the new row - $target.closest('table').find('tr.inputs input:first').focus() + // jump over the re-order row, if that's what we're on + if (sibling.hasClass(Settings.REORDER_BUTTONS_CLASS)) { + sibling = sibling.next(); + } + + if (sibling.hasClass(Settings.ADD_DEL_BUTTONS_CLASS)) { + sibling.find('.' + Settings.ADD_ROW_BUTTON_CLASS).click() + + // set focus to the first input in the new row + $target.closest('table').find('tr.inputs input:first').focus() + } } } else if ($target.is('input')) { @@ -801,8 +809,8 @@ function makeTable(setting, keypath, setting_value, isLocked) { if (!isLocked && !setting.read_only) { if (setting.can_order) { - html += ""; + html += ""; } html += "" }
" + row_num + "" + indexOrName + "" + rowIndexOrName + "" if (isArray) { - rowIsObject = setting.columns.length > 1 - colValue = rowIsObject ? row[col.name] : row - html += colValue - - // for arrays we add a hidden input to this td so that values can be posted appropriately - html += "" - } else if (row.hasOwnProperty(col.name)) { - html += row[col.name] + rowIsObject = setting.columns.length > 1; + colValue = rowIsObject ? row[col.name] : row; + colName = keypath + "[" + rowIndexOrName + "]" + (rowIsObject ? "." + col.name : ""); + } else { + colValue = row[col.name]; + colName = keypath + "." + rowIndexOrName + "." + col.name; } - html += ""; + + // add the actual value to the td so it is displayed + html += colValue; + + // for values to be posted properly we add a hidden input to this td + html += ""; + + html += "