From cfcda326e578e553cac76e56954f2e65baf496e1 Mon Sep 17 00:00:00 2001 From: Brian Federle Date: Mon, 21 Nov 2011 14:22:35 -0800 Subject: [PATCH] -Fix args.context for zone host details panel -Fix list view edit action -Support range input for create form --- ui/css/cloudstack3.css | 24 +++++++++++++++ ui/scripts-test/instances.js | 10 +++++-- ui/scripts-test/system.js | 9 ++---- ui/scripts/ui/dialog.js | 33 +++++++++++++++++---- ui/scripts/ui/widgets/listView.js | 49 +++++++++++++++++++------------ 5 files changed, 92 insertions(+), 33 deletions(-) diff --git a/ui/css/cloudstack3.css b/ui/css/cloudstack3.css index 874fad1d72c..a11837b3e11 100644 --- a/ui/css/cloudstack3.css +++ b/ui/css/cloudstack3.css @@ -2681,6 +2681,30 @@ Dialogs*/ float: left; } +.ui-dialog div.form-container div.value .range-edit { + width: 249px; + height: 33px; + margin: 2px 0 0; +} + +.ui-dialog div.form-container div.value .range-edit .range-item { + width: 124px; + height: 32px; + position: relative; + float: left; +} + +.ui-dialog div.form-container div.value .range-edit input { + width: 105px; + margin: 0 9px 0 0; +} + +.ui-dialog div.form-container div.value .range-edit label.error { + position: absolute; + left: 3px; + top: 25px; +} + .ui-dialog div.form-container div.value select { width: 100%; float: right; diff --git a/ui/scripts-test/instances.js b/ui/scripts-test/instances.js index b7805e58024..3025618a9ff 100644 --- a/ui/scripts-test/instances.js +++ b/ui/scripts-test/instances.js @@ -138,7 +138,11 @@ edit: { label: 'Edit instance name', action: function(args) { - args.response.success(args.data[0]); + if ((args.data.name) == '') { + args.response.error({ message: 'Instance name cannot be blank.' }); + } else { + args.response.success(); + } } }, @@ -369,7 +373,7 @@ } }, resetPassword: { - label: 'Reset password', + label: 'Reset password', action: function(args) { args.response.success({}); }, @@ -384,7 +388,7 @@ return 'VM password reset. New password is: ' + args.password; } }, - notification: { + notification: { poll: testData.notifications.customPoll({ password: '1284018jaj#' }) diff --git a/ui/scripts-test/system.js b/ui/scripts-test/system.js index 8e10f45a8fa..f30f33b5a2d 100644 --- a/ui/scripts-test/system.js +++ b/ui/scripts-test/system.js @@ -186,12 +186,9 @@ label: 'Netmask', validation: { required: true } }, - startip: { - label: 'Start IP', - validation: { required: true } - }, - endip: { - label: 'Start IP', + ipRange: { + label: 'IP Range', + range: ['startip', 'endip'], validation: { required: true } } } diff --git a/ui/scripts/ui/dialog.js b/ui/scripts/ui/dialog.js index 1981f9bbde8..9bf4b788227 100644 --- a/ui/scripts/ui/dialog.js +++ b/ui/scripts/ui/dialog.js @@ -193,13 +193,34 @@ } }); } else { - $input = $('').attr({ - name: key, - type: this.password || this.isPassword ? 'password' : 'text' - }).appendTo($value); + // Text field + if (this.range) { + $input = $.merge( + // Range start + $('').attr({ + type: 'text', + name: this.range[0] + }), - if (this.defaultValue) { - $input.val(this.defaultValue); + // Range end + $('').attr({ + type: 'text', + name: this.range[1] + }) + ).appendTo( + $('
').addClass('range-edit').appendTo($value) + ); + + $input.wrap($('
').addClass('range-item')); + } else { + $input = $('').attr({ + name: key, + type: this.password || this.isPassword ? 'password' : 'text' + }).appendTo($value); + + if (this.defaultValue) { + $input.val(this.defaultValue); + } } } diff --git a/ui/scripts/ui/widgets/listView.js b/ui/scripts/ui/widgets/listView.js index 83f06fa7aea..8fc2f31e6bd 100644 --- a/ui/scripts/ui/widgets/listView.js +++ b/ui/scripts/ui/widgets/listView.js @@ -312,9 +312,11 @@ }; // Hide edit field, validate and save changes - var showLabel = function(val) { + var showLabel = function(val, options) { + if (!options) options = {}; + var oldVal = $label.html(); - if (val) $label.html(val); + $label.html(val); var data = { id: $instanceRow.data('list-view-item-id'), @@ -336,6 +338,8 @@ $edit.hide(); $label.fadeIn(); $instanceRow.closest('div.data-table').dataTable('refresh'); + + if (options.success) options.success(args); }, error: function(args) { if (args.message) { @@ -343,6 +347,8 @@ $edit.hide(), $label.html(oldVal).fadeIn(); $instanceRow.closest('div.data-table').dataTable('refresh'); + + if (options.error) options.error(args); } } } @@ -354,24 +360,28 @@ return false; } - if ($label.is(':visible')) { + if (!$editInput.is(':visible')) { showEditField(); } else if ($editInput.val() != $label.html()) { $edit.animate({ opacity: 0.5 }); var originalName = $label.html(); var newName = $editInput.val(); - - addNotification( - { - section: $instanceRow.closest('div.view').data('view-args').id, - desc: 'Renamed ' + originalName + ' to ' + newName - }, - function(data) { - showLabel(newName); - }, - [{ name: newName }] - ); + showLabel(newName, { + success: function() { + addNotification( + { + section: $instanceRow.closest('div.view').data('view-args').id, + desc: newName ? 'Set value of ' + $instanceRow.find('td.name span').html() + ' to ' + newName : + 'Unset value for ' + $instanceRow.find('td.name span').html() + }, + function(args) { + + }, + [{ name: newName }] + ); + } + }); } else { showLabel(); } @@ -1017,10 +1027,8 @@ }; // Populate context object w/ instance data - detailViewArgs.context[ - $listView.data('view-args').activeSection - ] = [jsonObj]; - + var listViewActiveSection = $listView.data('view-args').activeSection; + // Create custom-generated detail view if (listViewData.detailView.pageGenerator) { detailViewArgs.pageGenerator = listViewData.detailView.pageGenerator; @@ -1032,6 +1040,11 @@ else detailViewArgs.section = listViewArgs.activeSection ? listViewArgs.activeSection : listViewArgs.id; + detailViewArgs.context[ + listViewActiveSection != '_zone' ? + listViewActiveSection : detailViewArgs.section + ] = [jsonObj]; + createDetailView(detailViewArgs, function($detailView) { $detailView.data('list-view', $listView); });