Revision ccee68a1

View differences:

src/sunstone/etc/sunstone-views/admin.yaml
226 226
            features: true
227 227
            input_output: true
228 228
            context: true
229
            actions: true
229 230
            scheduling: true
230 231
            hybrid: true
231 232
            vmgroup: true
src/sunstone/public/app/tabs/templates-tab/form-panels/create-common.js
43 43
    require('./create/wizard-tabs/network'),
44 44
    require('./create/wizard-tabs/os'),
45 45
    require('./create/wizard-tabs/io'),
46
    require('./create/wizard-tabs/actions'),
46 47
    require('./create/wizard-tabs/context'),
47 48
    require('./create/wizard-tabs/scheduling'),
48 49
    require('./create/wizard-tabs/hybrid'),
src/sunstone/public/app/tabs/templates-tab/form-panels/create/wizard-tabs/actions.js
1
/* -------------------------------------------------------------------------- */
2
/* Copyright 2002-2017, OpenNebula Project, OpenNebula Systems                */
3
/*                                                                            */
4
/* Licensed under the Apache License, Version 2.0 (the "License"); you may    */
5
/* not use this file except in compliance with the License. You may obtain    */
6
/* a copy of the License at                                                   */
7
/*                                                                            */
8
/* http://www.apache.org/licenses/LICENSE-2.0                                 */
9
/*                                                                            */
10
/* Unless required by applicable law or agreed to in writing, software        */
11
/* distributed under the License is distributed on an "AS IS" BASIS,          */
12
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   */
13
/* See the License for the specific language governing permissions and        */
14
/* limitations under the License.                                             */
15
/* -------------------------------------------------------------------------- */
16

  
17
define(function(require) {
18
  /*
19
    DEPENDENCIES
20
   */
21

  
22
  var Config = require('sunstone-config');
23
  var Locale = require('utils/locale');
24
  var Tips = require('utils/tips');
25
  var WizardFields = require('utils/wizard-fields');
26
  var UniqueId = require('utils/unique-id');
27
  var Humanize = require('utils/humanize');
28
  var TemplateUtils = require('utils/template-utils');
29

  
30
  var TemplateHTML = require('hbs!./actions/html');
31
  /*
32
    CONSTANTS
33
   */
34

  
35
  var WIZARD_TAB_ID = require('./actions/wizardTabId');
36

  
37
  /*
38
    CONSTRUCTOR
39
   */
40

  
41
  function WizardTab(opts) {
42
    if (!Config.isTemplateCreationTabEnabled(opts.tabId, 'actions')) {
43
      throw "Wizard Tab not enabled";
44
    }
45

  
46
    this.wizardTabId = WIZARD_TAB_ID + UniqueId.id();
47
    this.icon = "fa-calendar";
48
    this.title = Locale.tr("Actions");
49
  }
50

  
51
  WizardTab.prototype.constructor = WizardTab;
52
  WizardTab.prototype.html = _html;
53
  WizardTab.prototype.setup = _setup;
54
  WizardTab.prototype.onShow = _onShow;
55
  WizardTab.prototype.retrieve = _retrieve;
56
  WizardTab.prototype.fill = _fill;
57

  
58
  return WizardTab;
59

  
60
  function _html() {
61
    return TemplateHTML();
62
  }
63

  
64
  function _onShow(context, panelForm) {
65
  }
66

  
67
  function _setup(context) {
68
    var that = this;
69
		
70
    context.off('click', '#add_scheduling_temp_action');
71
    context.on('click', '#add_scheduling_temp_action', function() {
72
      $("#add_scheduling_temp_action", context).attr("disabled", "disabled");
73
      $("#scheduling_temp_actions_table").append('<tr>\
74
          <td>\
75
            <select id="select_new_action" class="select_new_action" name="select_action">\
76
              <option value="terminate">' + Locale.tr("terminate") + '</option>\
77
              <option value="terminate-hard">' + Locale.tr("terminate-hard") + '</option>\
78
              <option value="hold">' + Locale.tr("hold") + '</option>\
79
              <option value="release">' + Locale.tr("release") + '</option>\
80
              <option value="stop">' + Locale.tr("stop") + '</option>\
81
              <option value="suspend">' + Locale.tr("suspend") + '</option>\
82
              <option value="resume">' + Locale.tr("resume") + '</option>\
83
              <option value="reboot">' + Locale.tr("reboot") + '</option>\
84
              <option value="reboot-hard">' + Locale.tr("reboot-hard") + '</option>\
85
              <option value="poweroff">' + Locale.tr("poweroff") + '</option>\
86
              <option value="poweroff-hard">' + Locale.tr("poweroff-hard") + '</option>\
87
              <option value="undeploy">' + Locale.tr("undeploy") + '</option>\
88
              <option value="undeploy-hard">' + Locale.tr("undeploy-hard") + '</option>\
89
              <option value="snapshot-create">' + Locale.tr("snapshot-create") + '</option>\
90
            </select>\
91
          </td>\
92
         <td>\
93
            <input id="date_input" type="date" placeholder="2013/12/30"/>\
94
            <input id="time_input" type="time" placeholder="12:30"/>\
95
         </td>\
96
         <td>\
97
            <button id="add_temp_action_json" class="secondary small button radius" >' + Locale.tr("Add") + '</button>\
98
         </td>\
99
         <td colspan=2></td>\
100
       </tr>');
101

  
102
      return false;
103
    });
104

  
105
    context.off("click", "#add_temp_action_json");
106
    context.on("click" , "#add_temp_action_json", function(){
107
      var date_input_value = $("#date_input", context).val();
108
      var time_input_value = $("#time_input", context).val();
109

  
110
      if (date_input_value == "" || time_input_value == ""){
111
        return false;
112
      }
113

  
114
      var time_value = date_input_value + ' ' + time_input_value;
115
      var epoch_str = new Date(time_value);
116
      var time = parseInt(epoch_str.getTime()) / 1000;
117

  
118
      var new_action = $("#select_new_action", context).val();
119
      var sched_action = {};
120
      sched_action.ACTION = new_action;
121
      sched_action.TIME = time;
122

  
123
      $(this).parents('tr').remove();
124
      $("#add_scheduling_temp_action", context).removeAttr("disabled");
125

  
126
      $("#sched_temp_actions_body").append(fromJSONtoActionsTable(sched_action));
127
			
128
      return false;
129
    });
130

  
131
    context.on("focusout" , "#time_input", function(){
132
      $("#time_input").removeAttr("data-invalid");
133
      $("#time_input").removeAttr("class");
134
    });
135

  
136
    context.off("click", ".remove_action_x");
137
    context.on("click", ".remove_action_x", function(){
138
      $(this).parents('tr').remove();
139
    });
140
  }
141

  
142
  function _retrieve(context) {
143
    var templateJSON = {};
144
    var actionsJSON = [];
145

  
146
    $("#scheduling_temp_actions_table tbody tr").each(function(index){
147
      var first = $(this).children("td")[0];
148
      if(!$('select', first).html()){
149
        var actionJSON = {};
150
        actionJSON.ID = index;
151
        $(this).children("td").each(function(index2){
152
          if(index2 == 0)
153
            actionJSON.ACTION = $(this).text();
154
          else if (index2 == 1){
155
            var pretty_time = $(this).text();
156
            pretty_time = pretty_time.split(' ');
157
            var date = convertDate(pretty_time[1]);
158
            var time_value = date + ' ' + pretty_time[0];
159
            var epoch_str = new Date(time_value);
160
            var time = parseInt(epoch_str.getTime()) / 1000;
161
            actionJSON.TIME = time;
162
          }
163
        });
164
      }
165
      if (!$.isEmptyObject(actionJSON)) {actionsJSON.push(actionJSON)};
166
    });
167

  
168
    templateJSON['SCHED_ACTION'] = actionsJSON;
169
    return templateJSON;
170
  }
171

  
172
  function _fill(context, templateJSON) {
173
    var actions = fromJSONtoActionsTable(templateJSON.SCHED_ACTION);
174
    $("#sched_temp_actions_body").append(actions);
175
    delete templateJSON['SCHED_ACTION'];
176
  }
177

  
178
  function fromJSONtoActionsTable(actions_array) {
179
    var str = ""
180

  
181
    if (!actions_array) {
182
      return "";
183
    }
184

  
185
    if (!$.isArray(actions_array)) {
186
      var tmp_array = new Array();
187
      tmp_array[0]  = actions_array;
188
      actions_array = tmp_array;
189
    }
190

  
191
    if (!actions_array.length) {
192
      return "";
193
    }
194

  
195
    $.each(actions_array, function(index, scheduling_action) {
196
      str += fromJSONtoActionRow(scheduling_action);
197
    });
198

  
199
    return str;
200
  }
201

  
202
  function fromJSONtoActionRow(scheduling_action) {
203
    var time_str = Humanize.prettyTime(scheduling_action.TIME);
204

  
205
    var str = "";
206
    str += '<tr class="tr_action">\
207
       <td class="action_row">' + TemplateUtils.htmlEncode(scheduling_action.ACTION) + '</td>\
208
       <td nowrap class="time_row">' + time_str + '</td>\
209
       <td>\
210
         <div>\
211
           <a id="minus" class="remove_action_x" href="#"><i class="fa fa-trash-o"/></a>\
212
         </div>\
213
       </td>\
214
     </tr>';
215

  
216
    return str;
217
  }
218

  
219
  function convertDate(date_string){
220
    date_string = date_string.split('/');
221
    return date_string[2] + "-" + date_string[1] + "-" + date_string[0]; 
222
  }
223

  
224
});
src/sunstone/public/app/tabs/templates-tab/form-panels/create/wizard-tabs/actions/html.hbs
1
<div class="row">
2
  <div class="large-12 columns">
3
    <table id="scheduling_temp_actions_table" class="info_table dataTable">
4
      <thead>
5
        <tr>
6
          <th> {{tr "Action"}} </th>
7
          <th> {{tr "Time"}} </th>
8
          <th colspan=""> {{tr "Actions"}} </th>
9
          <th><button id="add_scheduling_temp_action" class="button small success right radius"> {{tr "Add action"}} </button></th>
10
        </tr>
11
      </thead>
12
      <tbody id="sched_temp_actions_body"></tbody>
13
    </table>
14
  </div>
15
</div>
src/sunstone/public/app/tabs/templates-tab/form-panels/create/wizard-tabs/actions/wizardTabId.js
1
/* -------------------------------------------------------------------------- */
2
/* Copyright 2002-2017, OpenNebula Project, OpenNebula Systems                */
3
/*                                                                            */
4
/* Licensed under the Apache License, Version 2.0 (the "License"); you may    */
5
/* not use this file except in compliance with the License. You may obtain    */
6
/* a copy of the License at                                                   */
7
/*                                                                            */
8
/* http://www.apache.org/licenses/LICENSE-2.0                                 */
9
/*                                                                            */
10
/* Unless required by applicable law or agreed to in writing, software        */
11
/* distributed under the License is distributed on an "AS IS" BASIS,          */
12
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   */
13
/* See the License for the specific language governing permissions and        */
14
/* limitations under the License.                                             */
15
/* -------------------------------------------------------------------------- */
16

  
17
define(function(require){
18
  return 'actionsTab';
19
});

Also available in: Unified diff