Revision 5c2d9ab5

View differences:

src/sunstone/public/app/tabs/templates-tab/form-panels/create/wizard-tabs/general/capacity-inputs.js
6 6
  require('foundation.slider');
7 7
  var Locale = require('utils/locale');
8 8
  var Tips = require('utils/tips');
9
  var WizardFields = require('utils/wizard-fields');
9 10

  
10 11
  /*
11 12
    TEMPLATES
......
19 20

  
20 21
  return {
21 22
    'html': _html,
22
    'setup': _setup
23
    'setup': _setup,
24
    'fill': _fill,
25
    'retrieve': _retrieve,
26
    'retrieveResize': _retrieveResize
23 27
  };
24 28

  
25 29
  /*
......
165 169

  
166 170
    vcpu_slider.foundation('slider', 'set_value', 0);
167 171
  }
172

  
173
  /**
174
   * Fills the capacity inputs
175
   * @param  {Object} context  JQuery selector
176
   * @param  {Object} template VM or VMTemplate object
177
   */
178
  function _fill(context, element) {
179
    var fields = $('[wizard_field]', context);
180

  
181
    fields.each(function() {
182
      var field_name = $(this).attr('wizard_field');
183
      $(this).data("original_value", element.TEMPLATE[field_name]);
184
    });
185

  
186
    WizardFields.fill(context, element.TEMPLATE);
187
  }
188

  
189
  /**
190
   * Retrieves the input values
191
   * @param  {Object} context  JQuery selector
192
   * @return {Object}         If the input is not empty, returns:
193
   *                                  - CPU
194
   *                                  - MEMORY
195
   *                                  - VCPU
196
   */
197
  function _retrieve(context) {
198
    return WizardFields.retrieve(context);
199
  }
200

  
201
  /**
202
   * Retrieves the input values, but only if the value has changed from the
203
   * original set in fill()
204
   * @param  {Object} context  JQuery selector
205
   * @return {Object}         If the input has changed, returns:
206
   *                                  - CPU
207
   *                                  - MEMORY
208
   *                                  - VCPU
209
   */
210
  function _retrieveResize(context) {
211
    var templateJSON = WizardFields.retrieve(context);
212

  
213
    var fields = $('[wizard_field]', context);
214

  
215
    fields.each(function() {
216
      var field_name = $(this).attr('wizard_field');
217
      if (templateJSON[field_name] == $(this).data("original_value")){
218
        delete templateJSON[field_name];
219
      }
220
    });
221

  
222
    return templateJSON;
223
  }
168 224
});
src/sunstone/public/app/tabs/vms-tab/dialogs/resize.js
56 56
    Tips.setup(context);
57 57

  
58 58
    $('#' + DIALOG_ID + 'Form', context).submit(function() {
59
      var templateJSON = WizardFields.retrieve(context);
60

  
61
      if (templateJSON["CPU"] == that.element.TEMPLATE.CPU) {
62
        delete templateJSON["CPU"];
63
      };
64

  
65
      if (templateJSON["MEMORY"] == that.element.TEMPLATE.MEMORY) {
66
        delete templateJSON["MEMORY"];
67
      };
68

  
69
      if (templateJSON["VCPU"] == that.element.TEMPLATE.VCPU) {
70
        delete templateJSON["VCPU"];
71
      };
59
      var templateJSON = CapacityInputs.retrieveResize(context);
72 60

  
73 61
      var enforce = $("#enforce", this).is(":checked");
74 62

  
......
90 78
  function _onShow(context) {
91 79
    var that = this;
92 80
    $('#vm_id', context).text(that.element.ID);
93
    $('#CPU', context).val(that.element.TEMPLATE.CPU);
94
    $('#MEMORY_TMP', context).val(that.element.TEMPLATE.MEMORY);
95
    if (that.element.VCPU) {
96
      $('#VCPU', context).val(that.element.TEMPLATE.VCPU);
97
    }
81
    CapacityInputs.fill(context, that.element);
98 82

  
99 83
    context.foundation('slider', 'reflow');
100 84
    

Also available in: Unified diff