incubator-cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From olgasm...@apache.org
Subject git commit: CS-15292: Split long OS Type list when create Template, ISO.
Date Wed, 25 Jul 2012 09:09:54 GMT
Updated Branches:
  refs/heads/master 1075344f0 -> f090fdeea


CS-15292: Split long OS Type list when create Template,ISO.


Project: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/commit/f090fdee
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/tree/f090fdee
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/diff/f090fdee

Branch: refs/heads/master
Commit: f090fdeea748e72b92878d955764d5059055e69d
Parents: 1075344
Author: olgasmola <olya.smola@gmail.com>
Authored: Wed Jul 11 16:09:38 2012 +0300
Committer: olgasmola <olya.smola@gmail.com>
Committed: Wed Jul 25 12:05:05 2012 +0300

----------------------------------------------------------------------
 ui/scripts/templates.js |   70 ++++++++++++++++++++++++--
 ui/scripts/ui/dialog.js |  116 ++++++++++++++++++++++-------------------
 2 files changed, 128 insertions(+), 58 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/f090fdee/ui/scripts/templates.js
----------------------------------------------------------------------
diff --git a/ui/scripts/templates.js b/ui/scripts/templates.js
index 7a99d79..d926d05 100644
--- a/ui/scripts/templates.js
+++ b/ui/scripts/templates.js
@@ -204,11 +204,42 @@
                     }
                   },
 
+                  osCategory: {
+                    label: 'OS Category',
+                    select: function(args) {
+                      $.ajax({
+                        url: createURL("listOsCategories"),
+                        dataType: "json",
+                        async: true,
+                        success: function(json) {
+                          var osCats = json.listoscategoriesresponse.oscategory;
+                          var items = [];
+                          if (isAdmin())
+                            items.push({id: -1, description: "All OS"});
+                          $(osCats).each(function() {
+                            items.push({id: this.id, description: this.name});
+                          });
+                          args.response.success({data: items});
+                        }
+                      });
+                    }
+                  },
+
                   osTypeId: {
                     label: 'label.os.type',
+                    dependsOn: 'osCategory',
                     select: function(args) {
+                      if(args.osCategory == null)
+                        return;
+
+                      var apiCmd;
+                      if(args.osCategory == -1)
+                        apiCmd = "listOsTypes";
+                      else
+                        apiCmd = "listOsTypes&oscategoryid=" + args.osCategory;
+
                       $.ajax({
-                        url: createURL("listOsTypes"),
+                        url: createURL(apiCmd),
                         dataType: "json",
                         async: true,
                         success: function(json) {
@@ -783,15 +814,46 @@
                     isBoolean: true,
                     isChecked: true
                   },
-
+                  
+                  osCategory: {
+                    label: 'OS Category',
+                    dependsOn: 'isBootable',
+                    select: function(args) {
+                      $.ajax({
+                        url: createURL("listOsCategories"),
+                        dataType: "json",
+                        async: true,
+                        success: function(json) {
+                          var osCats = json.listoscategoriesresponse.oscategory;
+                          var items = [];
+                          if (isAdmin())
+                            items.push({id: -1, description: "All OS"});
+                          $(osCats).each(function() {
+                            items.push({id: this.id, description: this.name});
+                          });
+                          args.response.success({data: items});
+                        }
+                      });
+                    }
+                  },
+                  
                   osTypeId: {
                     label: 'label.os.type',
-                    dependsOn: 'isBootable',
+                    dependsOn: ['isBootable','osCategory'],
                     isHidden: false,
                     validation: { required: true },
                     select: function(args) {
+                      if(args.osCategory == null)
+                        return;
+
+                      var apiCmd;
+                      if(args.osCategory == -1)
+                        apiCmd = "listOsTypes";
+                      else
+                        apiCmd = "listOsTypes&oscategoryid=" + args.osCategory;
+
                       $.ajax({
-                        url: createURL("listOsTypes"),
+                        url: createURL(apiCmd),
                         dataType: "json",
                         async: true,
                         success: function(json) {

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/f090fdee/ui/scripts/ui/dialog.js
----------------------------------------------------------------------
diff --git a/ui/scripts/ui/dialog.js b/ui/scripts/ui/dialog.js
index de44eb0..86db690 100644
--- a/ui/scripts/ui/dialog.js
+++ b/ui/scripts/ui/dialog.js
@@ -117,52 +117,56 @@
         var $value = $('<div>').addClass('value')
               .appendTo($formItem);
         var $input, $dependsOn, selectFn, selectArgs;
-        var dependsOn = field.dependsOn;
+        var dependsOn = $.isArray(field.dependsOn) ? field.dependsOn : [field.dependsOn]
; //now an array
 
         // Depends on fields
-        if (field.dependsOn) {
-          $formItem.attr('depends-on', dependsOn);
-          $dependsOn = $form.find('input, select').filter(function() {
-            return $(this).attr('name') === dependsOn;
-          });
+        if (dependsOn.length) {
+          $.each(dependsOn, function(key, value){
+            var dependsOn = value;
+
+            $formItem.attr('depends-on-'+value, dependsOn);
+            $dependsOn = $form.find('input, select').filter(function() {
+              return $(this).attr('name') === dependsOn;
+            });
 
-          if ($dependsOn.is('[type=checkbox]')) {
-            var isReverse = args.form.fields[dependsOn].isReverse;
+            if ($dependsOn.is('[type=checkbox]')) {
+              var isReverse = args.form.fields[dependsOn].isReverse;
 
-            // Checkbox
-            $dependsOn.bind('click', function(event) {
-              var $target = $(this);
-              var $dependent = $target.closest('form').find('[depends-on=\'' + dependsOn
+ '\']');
+              // Checkbox
+              $dependsOn.bind('click', function(event) {
+                var $target = $(this);
+                var $dependent = $target.closest('form').find('[depends-on-' + value + '=\''
+ dependsOn + '\']');
 
-              if (($target.is(':checked') && !isReverse) ||
+                if (($target.is(':checked') && !isReverse) ||
                   ($target.is(':unchecked') && isReverse)) {
-                $dependent.css('display', 'inline-block');
-                $dependent.each(function() {
-                  if ($(this).data('dialog-select-fn')) {
-                    $(this).data('dialog-select-fn')();
-                  }
-                });
-              } else if (($target.is(':unchecked') && !isReverse) ||
-                         ($target.is(':checked') && isReverse)) {
-                $dependent.hide();
-              }
+                  $dependent.css('display', 'inline-block');
+                  $dependent.each(function() {
+                    if ($(this).find('select').data('dialog-select-fn')) {
+                      $(this).find('select').data('dialog-select-fn')();
+                    }
+                  });
+                } else if (($target.is(':unchecked') && !isReverse) ||
+                           ($target.is(':checked') && isReverse)) {
+                  $dependent.hide();
+                }
 
-              $dependent.find('input[type=checkbox]').click();
+                $dependent.find('input[type=checkbox]').click();
 
-              if (!isReverse) {
-                $dependent.find('input[type=checkbox]').attr('checked', false);
-              } else {
-                $dependent.find('input[type=checkbox]').attr('checked', true);
-              }
+                if (!isReverse) {
+                  $dependent.find('input[type=checkbox]').attr('checked', false);
+                } else {
+                  $dependent.find('input[type=checkbox]').attr('checked', true);
+                }
 
-              return true;
-            });
+                return true;
+              });
 
-            // Show fields by default if it is reverse checkbox
-            if (isReverse) {
-              $dependsOn.click();
-            }
-          }
+              // Show fields by default if it is reverse checkbox
+              if (isReverse) {
+                $dependsOn.click();
+              }
+            };
+          });
         }
 
         // Determine field type of input
@@ -207,31 +211,35 @@
           // Pass form item to provider for additional manipulation
           $.extend(selectArgs, { $select: $input });
 
-          if (dependsOn) {
-            $dependsOn = $input.closest('form').find('input, select').filter(function() {
-              return $(this).attr('name') === dependsOn;
-            });
+          if (dependsOn.length) {
+            $.each(dependsOn, function(key, value){
+              var dependsOn = value;
 
-            $dependsOn.bind('change', function(event) {
-              var $target = $(this);
+              $dependsOn = $input.closest('form').find('input, select').filter(function()
{
+                return $(this).attr('name') === dependsOn;
+              });
 
-              if (!$dependsOn.is('select')) return true;
+              $dependsOn.bind('change', function(event) {
+                var $target = $(this);
 
-              var dependsOnArgs = {};
+                if (!$dependsOn.is('select')) return true;
 
-              $input.find('option').remove();
-             
-              if (!$target.children().size()) return true;
+                var dependsOnArgs = {};
 
-              dependsOnArgs[dependsOn] = $target.val();
-              selectFn($.extend(selectArgs, dependsOnArgs));
+                $input.find('option').remove();
 
-              return true;
-            });
+                if (!$target.children().size()) return true;
 
-            if (!$dependsOn.is('select')) {
-              selectFn(selectArgs);
-            }
+                dependsOnArgs[dependsOn] = $target.val();
+                selectFn($.extend(selectArgs, dependsOnArgs));
+
+                return true;
+              });
+
+              if (!$dependsOn.is('select')) {
+                selectFn(selectArgs);
+              }
+            });
           } else {
             selectFn(selectArgs);
           }


Mime
View raw message