[Kimchi-devel] [PATCH] UI: refactor guest edit code.
Aline Manera
alinefm at linux.vnet.ibm.com
Wed Aug 13 01:28:22 UTC 2014
I will apply just this patch as it is already reviewed and tested and
does not depends on the other one
On 08/11/2014 11:22 AM, shaohef at linux.vnet.ibm.com wrote:
> From: ShaoHe Feng <shaohef at linux.vnet.ibm.com>
>
> We don not need a special "save" button for permission form.
>
> All form in guest edit tab can share the same "save" button.
>
> also, we will add a password form, it will also share this button.
>
> Signed-off-by: ShaoHe Feng <shaohef at linux.vnet.ibm.com>
> Signed-off-by: Simon Jin <simonjin at linux.vnet.ibm.com>
> ---
> ui/css/theme-default/guest-edit.css | 5 -----
> ui/js/src/kimchi.guest_edit_main.js | 40 +++++++++++++++++++++----------------
> ui/pages/guest-edit.html.tmpl | 3 ---
> 3 files changed, 23 insertions(+), 25 deletions(-)
>
> diff --git a/ui/css/theme-default/guest-edit.css b/ui/css/theme-default/guest-edit.css
> index 1092cc9..74c2237 100644
> --- a/ui/css/theme-default/guest-edit.css
> +++ b/ui/css/theme-default/guest-edit.css
> @@ -261,8 +261,3 @@
> width: 46%;
> float: right;
> }
> -
> -#form-guest-edit-permission-save {
> - float: right;
> - margin-right: 10px;
> -}
> diff --git a/ui/js/src/kimchi.guest_edit_main.js b/ui/js/src/kimchi.guest_edit_main.js
> index 38a2bc0..7d24b44 100644
> --- a/ui/js/src/kimchi.guest_edit_main.js
> +++ b/ui/js/src/kimchi.guest_edit_main.js
> @@ -19,13 +19,11 @@ kimchi.guest_edit_main = function() {
> var buttonContainer = $('#action-button-container');
> $('#guest-edit-tabs').tabs({
> beforeActivate: function(event, ui) {
> + var display_list = ['form-guest-edit-general', 'form-guest-edit-permission']
> $(buttonContainer).addClass('hidden');
> - $("#form-guest-edit-permission-save").addClass('hidden');
> var deactivated = ui['newPanel'];
> - if($(deactivated).attr('id') === 'form-guest-edit-general') {
> + if(display_list.indexOf($(deactivated).attr('id')) >= 0) {
> $(buttonContainer).removeClass('hidden');
> - }else if($(deactivated).attr('id') === 'form-guest-edit-permission'){
> - $("#form-guest-edit-permission-save").removeClass('hidden');
> }
> }
> });
> @@ -335,18 +333,6 @@ kimchi.guest_edit_main = function() {
> filterNodes("", $("#permission-avail-users"));
> filterNodes("", $("#permission-avail-groups"));
> });
> - $("#form-guest-edit-permission-save").on("click", function(){
> - var content = { users: [], groups: [] };
> - $("#permission-sel-users").children().each(function(){
> - content.users.push($("label", this).text());
> - });
> - $("#permission-sel-groups").children().each(function(){
> - content.groups.push($("label", this).text());
> - });
> - kimchi.updateVM(kimchi.selectedGuest, content, function(){
> - kimchi.window.close();
> - });
> - });
> };
>
> var initContent = function(guest) {
> @@ -393,7 +379,7 @@ kimchi.guest_edit_main = function() {
>
> kimchi.retrieveVM(kimchi.selectedGuest, initContent);
>
> - var submitForm = function(event) {
> + var generalSubmit = function(event) {
> $(saveButton).prop('disabled', true);
> var data=$('#form-guest-edit-general').serializeObject();
> if(data['memory']!=undefined) {
> @@ -410,7 +396,27 @@ kimchi.guest_edit_main = function() {
> kimchi.message.error(err.responseJSON.reason);
> $(saveButton).prop('disabled', false);
> });
> + }
>
> + var permissionSubmit = function(event) {
> + var content = { users: [], groups: [] };
> + $("#permission-sel-users").children().each(function(){
> + content.users.push($("label", this).text());
> + });
> + $("#permission-sel-groups").children().each(function(){
> + content.groups.push($("label", this).text());
> + });
> + kimchi.updateVM(kimchi.selectedGuest, content, function(){
> + kimchi.window.close();
> + });
> + }
> +
> + // tap map, "general": 0, "storage": 1, "interface": 2, "permission": 3, "password": 4
> + var submit_map = {0: generalSubmit, 3:permissionSubmit};
> + var submitForm = function(event) {
> + var current = $('#guest-edit-tabs').tabs( "option", "active" );
> + var submitFun = submit_map[current];
> + submitFun && submitFun(event);
> event.preventDefault();
> };
>
> diff --git a/ui/pages/guest-edit.html.tmpl b/ui/pages/guest-edit.html.tmpl
> index 1c1d7d4..f24f7de 100644
> --- a/ui/pages/guest-edit.html.tmpl
> +++ b/ui/pages/guest-edit.html.tmpl
> @@ -150,9 +150,6 @@
> <span class="text">$_("Save")</span>
> </button>
> </div>
> - <button id="form-guest-edit-permission-save" class="btn-normal hidden">
> - <span class="text">$_("Save")</span>
> - </button>
> </footer>
> </div>
> <script id="cdrom-row-tmpl" type="text/html">
More information about the Kimchi-devel
mailing list