").appendTo($("dl#roles_tabs", dialog));
+
+ $("a", a).trigger("click");
+
+ role_tab.setup(role_section);
+ role_tab.onShow();
+ }
+
+});
diff --git a/src/sunstone/public/app/tabs/oneflow-templates-tab/form-panels/create/advanced.hbs b/src/sunstone/public/app/tabs/oneflow-templates-tab/form-panels/create/advanced.hbs
new file mode 100644
index 0000000000..7799ec90c1
--- /dev/null
+++ b/src/sunstone/public/app/tabs/oneflow-templates-tab/form-panels/create/advanced.hbs
@@ -0,0 +1,12 @@
+
\ No newline at end of file
diff --git a/src/sunstone/public/app/tabs/oneflow-templates-tab/form-panels/create/formPanelId.js b/src/sunstone/public/app/tabs/oneflow-templates-tab/form-panels/create/formPanelId.js
new file mode 100644
index 0000000000..470c675aca
--- /dev/null
+++ b/src/sunstone/public/app/tabs/oneflow-templates-tab/form-panels/create/formPanelId.js
@@ -0,0 +1,3 @@
+define(function(require){
+ return 'createServiceTemplateForm';
+});
\ No newline at end of file
diff --git a/src/sunstone/public/app/tabs/oneflow-templates-tab/form-panels/create/wizard.hbs b/src/sunstone/public/app/tabs/oneflow-templates-tab/form-panels/create/wizard.hbs
new file mode 100644
index 0000000000..a68412f1b0
--- /dev/null
+++ b/src/sunstone/public/app/tabs/oneflow-templates-tab/form-panels/create/wizard.hbs
@@ -0,0 +1,100 @@
+
\ No newline at end of file
diff --git a/src/sunstone/public/app/tabs/oneflow-templates-tab/utils/role-tab.js b/src/sunstone/public/app/tabs/oneflow-templates-tab/utils/role-tab.js
new file mode 100644
index 0000000000..8da638f02a
--- /dev/null
+++ b/src/sunstone/public/app/tabs/oneflow-templates-tab/utils/role-tab.js
@@ -0,0 +1,211 @@
+define(function(require) {
+ // Dependencies
+ var Locale = require('utils/locale');
+ var Tips = require('utils/tips');
+ var TemplatesTable = require('tabs/templates-tab/datatable');
+
+ var TemplateHTML = require('hbs!./role-tab/html');
+ var TemplateElasticityRowHTML = require('hbs!./role-tab/elasticity-row');
+ var TemplateScheRowHTML = require('hbs!./role-tab/sche-row');
+
+ function RoleTab(html_role_id) {
+ this.html_role_id = html_role_id;
+
+ return this;
+ }
+
+ RoleTab.prototype = {
+ 'html': _role_tab_content,
+ 'setup': _setup_role_tab_content,
+ 'onShow': _onShow,
+ 'retrieve': _retrieve,
+ //'fill': _fill
+
+ };
+ RoleTab.prototype.constructor = RoleTab;
+
+ return RoleTab;
+
+ function _role_tab_content(){
+ var opts = {
+ info: false,
+ select: true
+ };
+
+ this.templatesTable = new TemplatesTable("roleTabTemplates"+this.html_role_id, opts);
+
+ return TemplateHTML({
+ 'templatesTableHTML': this.templatesTable.dataTableHTML
+ });
+ }
+
+ function _setup_role_tab_content(role_section) {
+ var that = this;
+
+ Tips.setup(role_section);
+
+ this.templatesTable.initialize();
+ this.templatesTable.idInput().attr("required", "");
+
+ role_section.on("change", "#role_name", function(){
+ $("#" + that.html_role_id +" #role_name_text").html($(this).val());
+ });
+
+ role_section.on("change", "select#type", function(){
+ var new_tr = $(this).closest('tr');
+ if ($(this).val() == "PERCENTAGE_CHANGE") {
+ $("#min_adjust_step_td", new_tr).html('');
+ } else {
+ $("#min_adjust_step_td", new_tr).empty();
+ }
+ });
+
+ $("#tf_btn_elas_policies", role_section).bind("click", function(){
+ $( TemplateElasticityRowHTML({}) ).appendTo($("#elasticity_policies_tbody", role_section));
+ });
+
+ role_section.on("click", "#elasticity_policies_table i.remove-tab", function() {
+ var tr = $(this).closest('tr');
+ tr.remove();
+ });
+
+ $("#tf_btn_sche_policies", role_section).bind("click", function(){
+ $( TemplateScheRowHTML({}) ).appendTo($("#scheduled_policies_tbody", role_section));
+ });
+
+ role_section.on("click", "#scheduled_policies_table i.remove-tab", function() {
+ var tr = $(this).closest('tr');
+ tr.remove();
+ });
+
+ $("#tf_btn_elas_policies", role_section).trigger("click");
+ $("#tf_btn_sche_policies", role_section).trigger("click");
+
+ role_section.on("change", ".service_network_checkbox", function(){
+ var vm_template_contents = "";
+ $(".service_network_checkbox:checked", role_section).each(function(){
+ vm_template_contents += "NIC=[NETWORK_ID=\"$"+$(this).val()+"\"]\n";
+ });
+
+ $(".vm_template_contents", role_section).val(vm_template_contents);
+ });
+ }
+
+ function _onShow(){
+ this.templatesTable.refreshResourceTableSelect();
+ }
+
+ function _retrieve(context){
+ var role = {};
+ role['name'] = $('input[name="name"]', context).val();
+ role['cardinality'] = $('input[name="cardinality"]', context).val();
+ role['vm_template'] = this.templatesTable.retrieveResourceTableSelect();
+ role['shutdown_action'] = $('select[name="shutdown_action_role"]', context).val();
+ role['parents'] = [];
+ role['vm_template_contents'] = $(".vm_template_contents", context).val();
+
+ $('.parent_roles_body input.check_item:checked', context).each(function(){
+ role['parents'].push($(this).val());
+ });
+
+ var shutdown_action = $('select[name="shutdown_action_role"]', context).val();
+ if (shutdown_action) {
+ role['shutdown_action'] = shutdown_action;
+ }
+
+ var min_vms = $('input[name="min_vms"]', context).val();
+ if (min_vms) {
+ role['min_vms'] = min_vms;
+ }
+
+ var max_vms = $('input[name="max_vms"]', context).val();
+ if (max_vms) {
+ role['max_vms'] = max_vms;
+ }
+
+ var cooldown = $('input[name="cooldown"]', context).val();
+ if (cooldown) {
+ role['cooldown'] = cooldown;
+ }
+
+ role = _removeEmptyObjects(role);
+ role['elasticity_policies'] = [];
+ $("#elasticity_policies_tbody tr", context).each(function(){
+ if ($("#type" ,this).val()) {
+ var policy = {};
+ policy['type'] = $("#type" ,this).val();
+ policy['adjust'] = $("#adjust" ,this).val();
+ policy['min_adjust_step'] = $("#min_adjust_step" ,this).val();
+ policy['expression'] = $("#expression" ,this).val();
+ policy['period_number'] = $("#period_number" ,this).val();
+ policy['period'] = $("#period" ,this).val();
+ policy['cooldown'] = $("#cooldown" ,this).val();
+
+ // TODO remove empty policies
+ role['elasticity_policies'].push(_removeEmptyObjects(policy));
+ }
+ });
+
+ role['scheduled_policies'] = [];
+ $("#scheduled_policies_tbody tr", context).each(function(){
+ if ($("#type" ,this).val()) {
+ var policy = {};
+ policy['type'] = $("#type" ,this).val();
+ policy['adjust'] = $("#adjust" ,this).val();
+ policy['min_adjust_step'] = $("#min_adjust_step" ,this).val();
+
+ var time_format = $("#time_format" ,this).val();
+ policy[time_format] = $("#time" ,this).val();
+
+ // TODO remove empty policies
+ role['scheduled_policies'].push(_removeEmptyObjects(policy));
+ }
+ });
+
+ return role;
+ }
+
+ //----------------------------------------------------------------------------
+
+ function _removeEmptyObjects(obj){
+ for (var elem in obj){
+ var remove = false;
+ var value = obj[elem];
+ if (value instanceof Array){
+ if (value.length == 0)
+ remove = true;
+ else if (value.length > 0){
+ value = jQuery.grep(value, function (n) {
+ var obj_length = 0;
+ for (e in n)
+ obj_length += 1;
+
+ if (obj_length == 0)
+ return false;
+
+ return true;
+ });
+
+ if (value.length == 0)
+ remove = true;
+ }
+ }
+ else if (value instanceof Object){
+ var obj_length = 0;
+ for (e in value)
+ obj_length += 1;
+ if (obj_length == 0)
+ remove = true;
+ }else{
+ value = String(value);
+ if (value.length == 0)
+ remove = true;
+ }
+
+ if (remove)
+ delete obj[elem];
+ }
+
+ return obj;
+ }
+});
\ No newline at end of file
diff --git a/src/sunstone/public/app/tabs/oneflow-templates-tab/utils/role-tab/elasticity-row.hbs b/src/sunstone/public/app/tabs/oneflow-templates-tab/utils/role-tab/elasticity-row.hbs
new file mode 100644
index 0000000000..0437992620
--- /dev/null
+++ b/src/sunstone/public/app/tabs/oneflow-templates-tab/utils/role-tab/elasticity-row.hbs
@@ -0,0 +1,30 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/sunstone/public/app/tabs/oneflow-templates-tab/utils/role-tab/html.hbs b/src/sunstone/public/app/tabs/oneflow-templates-tab/utils/role-tab/html.hbs
new file mode 100644
index 0000000000..2433df5afe
--- /dev/null
+++ b/src/sunstone/public/app/tabs/oneflow-templates-tab/utils/role-tab/html.hbs
@@ -0,0 +1,205 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+ {{{templatesTableHTML}}}
+
+
+
+
+
+
+
+
+
+
+ {{tr "Network Interfaces"}}
+
+
+
+
+
+
+
+
+
+
+
+
+ {{tr "Parent roles"}}
+
+
+
+
+
+
+
+
+
+
+
+ {{#advancedSection (tr "Role Elasticity") }}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ {{tr "Elasticity policies"}}
+
+
+
+
+
+
+ {{tr "CHANGE: Add/substract the given number of VMs."}}
+ {{tr "CARDINALITY: Set the cardinality to the given number."}}
+ {{tr "PERCENTAGE_CHANGE: Add/substract the given percentage to the current cardinality."}}
+ " style="width:14%">{{tr "Type"}}
+
+
+ {{tr "CHANGE: -2, will substract 2 VMs from the role"}}
+ {{tr "CARDINALITY: 8, will set carditanilty to 8"}}
+ {{tr "PERCENTAGE_CHANGE: 20, will increment cardinality by 20%"}}" style="width:12%">{{tr "Adjust"}}
+
+
+ {{tr " If present, the policy will change the cardinality by at least the number of VMs set in this attribute."}}" style="width:9%">{{tr "Min"}}
+
+
+ {{tr "Example: ATT < 20"}}" style="width:30%">{{tr "Expression"}}
+
+ {{tr "CHANGE: Add/substract the given number of VMs."}}
+ {{tr "CARDINALITY: Set the cardinality to the given number."}}
+ {{tr "PERCENTAGE_CHANGE: Add/substract the given percentage to the current cardinality."}}" style="width:14%">{{tr "Type"}}
+
+
+ {{tr "CHANGE: -2, will substract 2 VMs from the role"}}
+ {{tr "CARDINALITY: 8, will set carditanilty to 8"}}
+ {{tr "PERCENTAGE_CHANGE: 20, will increment cardinality by 20%"}}" style="width:12%">{{tr "Adjust"}}
+
+
{{tr "Min"}}
+
+
+ {{tr "Start time: Exact time for the adjustement"}}" style="width:28%">{{tr "Time format"}}
+
+
+ {{tr "Recurrence: Time for recurring adjustements. Time is specified with the Unix cron syntax"}}
+ {{tr "Start time: Exact time for the adjustement"}}" style="width:33%">{{tr "Time expression"}}
+
+ {{#advancedSection (tr "Advanced Role Parameters") }}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ {{/advancedSection}}
+
+
\ No newline at end of file
diff --git a/src/sunstone/public/app/tabs/oneflow-templates-tab/utils/role-tab/sche-row.hbs b/src/sunstone/public/app/tabs/oneflow-templates-tab/utils/role-tab/sche-row.hbs
new file mode 100644
index 0000000000..3f2d566dca
--- /dev/null
+++ b/src/sunstone/public/app/tabs/oneflow-templates-tab/utils/role-tab/sche-row.hbs
@@ -0,0 +1,27 @@
+