Revision a97b6350

View differences:

src/sunstone/public/app/tabs/templates-tab/form-panels/instantiate.js
66 66
  }
67 67

  
68 68
  function _submitWizard(context) {
69
    if (!this.selected_nodes || this.selected_nodes.length == 0) {
70
      Notifier.notifyError(Locale.tr("No template selected"));
71
      Sunstone.hideFormPanelLoading(this.tabId);
72
      return false;
73
    }
74

  
69 75
    var vm_name = $('#vm_name', context).val();
70 76
    var n_times = $('#vm_n_times', context).val();
71 77
    var n_times_int = 1;
src/sunstone/public/app/tabs/templates-tab/form-panels/instantiate/html.hbs
1 1
<form data-abide="ajax" id="{{formPanelId}}Wizard" class="custom creation">
2 2
  <div class="row">
3
    <div class="large-12 large-centered columns selectTemplateTable">
4
    </div>
5
  </div>
6
  <div class="row nameContainer">
3 7
    <div class="large-4 columns">
4 8
      <label for="vm_name">
5 9
        {{tr "VM Name"}}
......
29 33
    </div>
30 34
  </div>
31 35
  <div class="row">
32
    <div class="large-11 large-centered columns list_of_templates">
36
    <div class="large-12 large-centered columns list_of_templates">
33 37
    </div>
34 38
  </div>
35 39
</form>
src/sunstone/public/app/tabs/vms-tab/form-panels/create.js
4 4
   */
5 5

  
6 6
  require('foundation.tab');
7
  var BaseFormPanel = require('utils/form-panels/form-panel');
7
  var InstantiateTemplateFormPanel = require('tabs/templates-tab/form-panels/instantiate');
8 8
  var Sunstone = require('sunstone');
9 9
  var Locale = require('utils/locale');
10 10
  var Tips = require('utils/tips');
......
13 13
  var UserInputs = require('utils/user-inputs');
14 14
  var OpenNebulaTemplate = require('opennebula/template');
15 15
  var TemplatesTable = require('tabs/templates-tab/datatable');
16

  
17
  /*
18
    TEMPLATES
19
   */
20

  
21
  var TemplateWizardHTML = require('hbs!./create/wizard');
22

  
23 16
  /*
24 17
    CONSTANTS
25 18
   */
......
32 25
   */
33 26

  
34 27
  function FormPanel() {
28
    InstantiateTemplateFormPanel.call(this);
29

  
35 30
    this.formPanelId = FORM_PANEL_ID;
36 31
    this.tabId = TAB_ID;
37 32
    this.actions = {
......
43 38
    };
44 39

  
45 40
    this.templatesTable = new TemplatesTable('vm_create', {'select': true});
46

  
47
    BaseFormPanel.call(this);
48 41
  }
49 42

  
50 43
  FormPanel.FORM_PANEL_ID = FORM_PANEL_ID;
51
  FormPanel.prototype = Object.create(BaseFormPanel.prototype);
44
  FormPanel.prototype = Object.create(InstantiateTemplateFormPanel.prototype);
52 45
  FormPanel.prototype.constructor = FormPanel;
53
  FormPanel.prototype.htmlWizard = _htmlWizard;
54
  FormPanel.prototype.setup = _setup;
55 46
  FormPanel.prototype.onShow = _onShow;
56
  FormPanel.prototype.submitWizard = _submitWizard;
47
  FormPanel.prototype.setup = _setup;
57 48

  
58 49
  return FormPanel;
59 50

  
60 51
  /*
61 52
    FUNCTION DEFINITIONS
62 53
   */
63

  
64
  function _htmlWizard() {
65

  
66
    return TemplateWizardHTML({
67
      'formPanelId': this.formPanelId,
68
      'templatesTableHTML': this.templatesTable.dataTableHTML
69
    });
70
  }
71

  
72 54
  function _setup(context) {
73
    $("#create_vm_template_proceed", context).attr("disabled", "disabled");
74
    $("#create_vm_inputs_step", context).hide();
55
    var that = this;
56
    InstantiateTemplateFormPanel.prototype.setup.call(this, context);
57

  
58
    $(".selectTemplateTable", context).html(
59
      '<fieldset>' +
60
        '<legend>' + Locale.tr("Select a template") + '</legend>' +
61
        this.templatesTable.dataTableHTML +
62
      '</fieldset>');
75 63

  
76 64
    this.templatesTable.initialize();
77 65

  
78 66
    $("#selected_resource_id_vm_create", context).on("change", function(){
79
        var template_id = $(this).val();
67
        $(".nameContainer", context).show();
80 68

  
81
        $("#create_vm_inputs_step", context).hide();
82
        $("#create_vm_user_inputs", context).empty();
83

  
84
        OpenNebulaTemplate.show({
85
            data : {
86
                id: template_id
87
            },
88
            timeout: true,
89
            success: function (request, template_json){
90
                $("#create_vm_inputs_step", context).hide();
91
                $("#create_vm_user_inputs", context).empty();
92

  
93
                var has_inputs = UserInputs.vmTemplateInsert(
94
                    $("#create_vm_user_inputs", context),
95
                    template_json,
96
                    {text_header: ""});
97

  
98
                if(has_inputs){
99
                    $("#create_vm_inputs_step", context).show();
100
                }
101

  
102
                $("#create_vm_template_proceed", context).removeAttr("disabled");
103
            },
104
            error: function(request,error_json, container){
105
                Notifier.onError(request,error_json, container);
106
            }
107
        });
69
         var templatesContext = $(".list_of_templates", context);
70
        templatesContext.html("");
71
        templatesContext.show();
72

  
73
        var template_id = $(this).val();
74
        that.setTemplateIds(context, [template_id]);
108 75
    });
109 76

  
110 77
    Tips.setup(context);
111 78
  }
112 79

  
113 80
  function _onShow(context) {
114
    $("input#vm_name", context).focus();
115 81
    this.templatesTable.resetResourceTableSelect();
116
  }
117

  
118
  function _submitWizard(context) {
119
    var vm_name = $('#create_vm_name', context).val();
120
    var template_id = $("#selected_resource_id_vm_create", context).val();
121
    var n_times = $('#create_vm_n_times', context).val();
122
    var n_times_int = 1;
123
    var hold = $('#create_vm_hold', context).prop("checked");
124

  
125
    if (!template_id.length) {
126
      Notifier.notifyError(tr("You have not selected a template"));
127
      return false;
128
    }
129

  
130
    if (n_times.length) {
131
      n_times_int = parseInt(n_times, 10);
132
    }
133

  
134
    var extra_msg = "";
135
    if (n_times_int > 1) {
136
      extra_msg = n_times_int + " times";
137
    }
138

  
139
    Notifier.notifySubmit("Template.instantiate", template_id, extra_msg);
140

  
141
    var extra_info = {
142
      'hold': hold
143
    };
144

  
145
    var tmp_json = WizardFields.retrieve(context);
146

  
147
    extra_info['template'] = tmp_json;
148

  
149
    if (!vm_name.length) { //empty name use OpenNebula core default
150
      for (var i = 0; i < n_times_int; i++) {
151
        extra_info['vm_name'] = "";
152
        Sunstone.runAction("Template.instantiate_quiet", template_id, extra_info);
153
      }
154
    } else {
155
      if (vm_name.indexOf("%i") == -1) {//no wildcard, all with the same name
156
        for (var i = 0; i < n_times_int; i++) {
157
          extra_info['vm_name'] = vm_name;
158
          Sunstone.runAction("Template.instantiate_quiet", template_id, extra_info);
159
        }
160
      } else { //wildcard present: replace wildcard
161
        for (var i = 0; i < n_times_int; i++) {
162
          extra_info['vm_name'] = vm_name.replace(/%i/gi, i);
163
          Sunstone.runAction("Template.instantiate_quiet", template_id, extra_info);
164
        }
165
      }
166
    }
167

  
168
    setTimeout(function() {
169
      Sunstone.resetFormPanel(TAB_ID, FORM_PANEL_ID);
170
      Sunstone.hideFormPanel(TAB_ID);
171
      Sunstone.runAction("VM.list");
172
    }, 1500);
82
    InstantiateTemplateFormPanel.prototype.onShow.call(this, context);
173 83

  
174
    return false;
84
    $(".nameContainer", context).hide();
175 85
  }
176 86
});

Also available in: Unified diff