Revision f7f7a0a7

View differences:

src/sunstone/public/app/opennebula/vm.js
334 334
    "suspend": function(params) {
335 335
      OpenNebulaAction.simple_action(params, RESOURCE, "suspend");
336 336
    },
337
    "save_as_template": function(params) {
338
      OpenNebulaAction.simple_action(params, RESOURCE, "save_as_template");
339
    },
337 340
    "resume": function(params) {
338 341
      OpenNebulaAction.simple_action(params, RESOURCE, "resume");
339 342
    },
src/sunstone/public/app/tabs/provision-tab/vms/list.js
485 485
          },
486 486
          success: function(request, response){
487 487
            OpenNebula.Action.clear_cache("VMTEMPLATE");
488
            Notifier.notifyMessage(Locale.tr("Image") + ' ' + request.request.data[0][1].name + ' ' + Locale.tr("saved successfully"))
488
            Notifier.notifyMessage(Locale.tr("VM Template") + ' ' + request.request.data[0][1].name + ' ' + Locale.tr("saved successfully"))
489 489
            update_provision_vm_info(vm_id, context);
490 490
            button.removeAttr("disabled");
491 491
          },
src/sunstone/public/app/tabs/vms-tab.js
17 17
    require('./vms-tab/dialogs/attach-nic'),
18 18
    require('./vms-tab/dialogs/snapshot'),
19 19
    require('./vms-tab/dialogs/vnc'),
20
    require('./vms-tab/dialogs/spice')
20
    require('./vms-tab/dialogs/spice'),
21
    require('./vms-tab/dialogs/saveas-template')
21 22
  ];
22 23

  
23 24
  var _panels = [
src/sunstone/public/app/tabs/vms-tab/actions.js
8 8
  var Spice = require('utils/spice');
9 9

  
10 10
  var TAB_ID = require('./tabId');
11
  var CREATE_DIALOG_ID = require('./form-panels/create/formPanelId');
12
  var DEPLOY_DIALOG_ID = require('./dialogs/deploy/dialogId');
13
  var MIGRATE_DIALOG_ID = require('./dialogs/migrate/dialogId');
14
  var VNC_DIALOG_ID = require('./dialogs/vnc/dialogId');
15
  var SPICE_DIALOG_ID = require('./dialogs/spice/dialogId');
11
  var CREATE_DIALOG_ID           = require('./form-panels/create/formPanelId');
12
  var DEPLOY_DIALOG_ID           = require('./dialogs/deploy/dialogId');
13
  var MIGRATE_DIALOG_ID          = require('./dialogs/migrate/dialogId');
14
  var VNC_DIALOG_ID              = require('./dialogs/vnc/dialogId');
15
  var SPICE_DIALOG_ID            = require('./dialogs/spice/dialogId');
16
  var SAVE_AS_TEMPLATE_DIALOG_ID = require('./dialogs/saveas-template/dialogId');
16 17

  
17 18
  var XML_ROOT = "VM";
18 19
  var RESOURCE = "VM";
......
163 164
        Spice.unlock();
164 165
      },
165 166
      notify: true
166
    }
167
    },
168
    "VM.saveas_template" : {
169
      type: "single",
170
      call: function() {
171
       var dialog = Sunstone.getDialog(SAVE_AS_TEMPLATE_DIALOG_ID);
172
       dialog.show();
173
       },
174
      error: function(req, resp) {
175
        Notifier.onError(req, resp);
176
      },
177
      notify: false
178
    },
167 179
  };
168 180

  
169 181
  return _actions;
src/sunstone/public/app/tabs/vms-tab/buttons.js
39 39
      tip: Locale.tr("This will migrate the selected VMs to the chosen host"),
40 40
      layout: "vmsplanification_buttons",
41 41
      custom_classes : "state-dependent"
42

  
43 42
    },
44 43
    "VM.migrate_live" : {
45 44
      type: "action",
......
194 193
      text: '<i class="fa fa-desktop" style="color: rgb(111, 111, 111)"/> ' + Locale.tr("SPICE"),
195 194
      custom_classes: "only-right-info spice-right-info",
196 195
      tip: Locale.tr("SPICE")
197
    }
196
    },
197
    "VM.saveas_template" : {
198
      type: "action",
199
      text: '<i class="fa fa-save"/>',
200
      tip: Locale.tr("This Virtual Machine will be saved in a new Template. You can then create a new Virtual Machine using this Template"),
201
      custom_classes : "state-dependent"
202
    },
198 203
  }
199 204

  
200 205
  return Buttons;
src/sunstone/public/app/tabs/vms-tab/dialogs/saveas-template.js
1
define(function(require) {
2
  /*
3
    DEPENDENCIES
4
   */
5

  
6
  var BaseDialog = require('utils/dialogs/dialog');
7
  var TemplateHTML = require('hbs!./saveas-template/html');
8
  var Sunstone = require('sunstone');
9
  var OpenNebula = require('opennebula');
10
  var Notifier = require('utils/notifier');
11
  var Tips = require('utils/tips');
12

  
13
  /*
14
    CONSTANTS
15
   */
16

  
17
  var DIALOG_ID = require('./saveas-template/dialogId');
18
  var TAB_ID = require('../tabId');
19

  
20
  /*
21
    CONSTRUCTOR
22
   */
23

  
24
  function Dialog() {
25
    this.dialogId = DIALOG_ID;
26

  
27
    BaseDialog.call(this);
28
  }
29

  
30
  Dialog.DIALOG_ID = DIALOG_ID;
31
  Dialog.prototype = Object.create(BaseDialog.prototype);
32
  Dialog.prototype.constructor = Dialog;
33
  Dialog.prototype.html = _html;
34
  Dialog.prototype.onShow = _onShow;
35
  Dialog.prototype.setup = _setup;
36

  
37
  return Dialog;
38

  
39
  /*
40
    FUNCTION DEFINITIONS
41
   */
42

  
43
  function _html() {
44
    return TemplateHTML({
45
      'dialogId': this.dialogId
46
    });
47
  }
48

  
49
  function _setup(context) {
50
    var that = this;
51

  
52
    Tips.setup(context);
53

  
54

  
55
    $('#' + DIALOG_ID + 'Form', context).submit(function() {
56
      var template_name = $('#template_name', this).val();
57
      var vm_id = $("#vm_id", context).val();
58

  
59
      OpenNebula.VM.save_as_template({
60
        data : {
61
          id: vm_id,
62
          extra_param: {
63
            name : template_name
64
          }
65
        },
66
        success: function(request, response){
67
          OpenNebula.Action.clear_cache("VMTEMPLATE");
68
          Notifier.notifyMessage(Locale.tr("VM Template") + ' ' + template_name + ' ' + Locale.tr("saved successfully"))
69
        },
70
        error: function(request, response){
71
          Notifier.onError(request, response);
72
        }
73
      })
74

  
75
      Sunstone.getDialog(DIALOG_ID).hide();
76
      Sunstone.getDialog(DIALOG_ID).reset();
77
      return false;
78
    });
79

  
80
    return false;
81
  }
82

  
83
  function _onShow(context) {
84
    $("#vm_id", context).val(Sunstone.getDataTable(TAB_ID).elements());
85
    $("#template_name", context).focus();
86
    return false;
87
  }
88
});
src/sunstone/public/app/tabs/vms-tab/dialogs/saveas-template/dialogId.js
1
define(function(require) {
2
  return 'saveAsTemplate';
3
})
src/sunstone/public/app/tabs/vms-tab/dialogs/saveas-template/html.hbs
1
<div id="{{dialogId}}" class="reveal-modal small" role="dialog" data-reveal >
2
  <div class="row">
3
    <div class="large-12 columns">
4
      <h3 class="subheader" id="">{{tr "Save as Template"}}</h3>
5
    </div>
6
  </div>
7
  <div class="reveal-body">
8
    <form id="{{dialogId}}Form" action="">
9
      <div class="row">
10
        <div class="large-6 columns">
11
          <label for="vm_id">{{tr "Virtual Machine ID"}}:</label>
12
          <input style="border-style: inset; background-color: lightgrey" type="text" name="vm_id" id="vm_id" disabled/>
13
        </div>
14
      </div>
15
      <div class="row">
16
        <div class="large-12 columns">
17
          <label for="template_name">{{tr "Template name"}}:</label>
18
          <input type="text" name="template_name" id="template_name" />
19
        </div>
20
      </div>
21
      <div class="form_buttons">
22
        <button class="button radius right success" type="submit">{{tr "Save As Template"}}</button>
23
      </div>
24
      <a class="close-reveal-modal">&#215;</a>
25
    </form>
26
  </div>
27
</div>
src/sunstone/public/app/tabs/vms-tab/utils/state-actions.js
28 28
    ["VM.delete", "VM.delete_recreate", "VM.resize"];
29 29

  
30 30
  STATE_ACTIONS[OpenNebulaVM.STATES.POWEROFF] =
31
    ["VM.delete", "VM.resume", "VM.resize", "VM.attachdisk", "VM.detachdisk", "VM.attachnic", "VM.detachnic", "VM.disk_saveas", "VM.disk_snapshot_create", "VM.disk_snapshot_revert", "VM.disk_snapshot_delete", "VM.migrate", "VM.undeploy", "VM.undeploy_hard", "VM.shutdown_hard"];
31
    ["VM.delete", "VM.resume", "VM.resize", "VM.attachdisk", "VM.detachdisk", "VM.attachnic", "VM.detachnic", "VM.disk_saveas", "VM.disk_snapshot_create", "VM.disk_snapshot_revert", "VM.disk_snapshot_delete", "VM.migrate", "VM.undeploy", "VM.undeploy_hard", "VM.shutdown_hard", "VM.saveas_template"];
32 32

  
33 33
  STATE_ACTIONS[OpenNebulaVM.STATES.UNDEPLOYED] =
34 34
    ["VM.delete", "VM.delete_recreate", "VM.resume", "VM.resize", "VM.deploy"];

Also available in: Unified diff