1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-04-02 10:50:07 +03:00

Fix dropdowns datatable master (#1162)

Co-authored-by: Jorge Lobo <jlobo@opennebula.systems>
This commit is contained in:
Jorge Miguel Lobo Escalona 2021-04-29 10:51:45 +02:00 committed by GitHub
parent 5b4c4e0c77
commit 20d3575fb8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 681 additions and 689 deletions

View File

@ -25,7 +25,7 @@ define(function(require) {
Navigation = require("utils/navigation");
var RESOURCE = "VM";
var VM_MONITORING_CACHE_NAME = 'VM.MONITORING';
var VM_MONITORING_CACHE_NAME = "VM.MONITORING";
var STATES_STR = [
"INIT",
@ -674,12 +674,12 @@ define(function(require) {
return Array.isArray(monitoringPool)
? monitoringPool.reduce(function(result, monitoringVM) {
return $.extend(result, { [monitoringVM.ID]: monitoringVM })
return $.extend(result, { [monitoringVM.ID]: monitoringVM });
}, {})
: {}
}
: {};
};
OpenNebulaAction.list(params, VM_MONITORING_CACHE_NAME, 'vm/monitor', process, undefined, false);
OpenNebulaAction.list(params, VM_MONITORING_CACHE_NAME, "vm/monitor", process, undefined, false);
},
"resize" : function(params) {
var action_obj = params.data.extra_param;
@ -848,10 +848,10 @@ define(function(require) {
function _promiseGetVm({ id, success, async = true } = {}) {
return $.ajax({
url: 'vm/' + id,
type: 'GET',
url: "vm/" + id,
type: "GET",
success: function(response) {
if (typeof success === 'function') {
if (typeof success === "function") {
var vm = response ? response[RESOURCE] : undefined;
success(vm);
}
@ -863,20 +863,20 @@ define(function(require) {
function _getMonitoringPool() {
var monitoring = undefined;
var cache = OpenNebulaAction.cache(VM_MONITORING_CACHE_NAME);
if (cache && cache.data) {
monitoring = cache.data
monitoring = cache.data;
}
if (!monitoring || $.isEmptyObject(monitoring)) {
VM.pool_monitor({
success: function(response) {
monitoring = response
monitoring = response;
}
})
});
}
return monitoring || {}
return monitoring || {};
}
function retrieveLastHistoryRecord(element) {
@ -976,52 +976,52 @@ define(function(require) {
}
function getNicsFromMonitoring(element = {}) {
let monitoringPool = _getMonitoringPool()
let monitoringVM = monitoringPool[element.ID]
let monitoringPool = _getMonitoringPool();
let monitoringVM = monitoringPool[element.ID];
if (!monitoringPool || $.isEmptyObject(monitoringPool) || !monitoringVM) return [];
return EXTERNAL_IP_ATTRS.reduce(function(externalNics, attr) {
let monitoringValues = monitoringVM[attr]
let monitoringValues = monitoringVM[attr];
if (monitoringValues) {
$.each(monitoringValues.split(','), function(_, ip) {
let exists = externalNics.some(function(nic) { return nic.IP === ip })
$.each(monitoringValues.split(","), function(_, ip) {
let exists = externalNics.some(function(nic) { return nic.IP === ip; });
if (!exists) {
externalNics.push({ NIC_ID: '_', IP: ip });
externalNics.push({ NIC_ID: "_", IP: ip });
}
});
}
return externalNics;
}, [])
}, []);
}
// Return the IP or several IPs of a VM
function ipsStr(element, options) {
options = $.extend({
defaultValue: '--',
divider: '<br>',
defaultValue: "--",
divider: "<br>",
groupStrFunction: groupByIpsStr,
forceGroup: false
}, options)
var nics = getNICs(element);
var nicsFromMonitoring = getNicsFromMonitoring(element)
}, options);
nics = nics.concat(nicsFromMonitoring)
var nics = getNICs(element);
var nicsFromMonitoring = getNicsFromMonitoring(element);
nics = nics.concat(nicsFromMonitoring);
// infoextended: alias will be group by nic
if (Config.isExtendedVmInfo || options.forceGroup) {
return options.groupStrFunction(element, nics)
return options.groupStrFunction(element, nics);
}
return $.map(nics, function(nic) {
return $.map(NIC_ALIAS_IP_ATTRS, function(attribute) {
return nic[attribute]
})
}).join(options.divider) || options.defaultValue
return nic[attribute];
});
}).join(options.divider) || options.defaultValue;
};
// Return a dropdown with all the IPs
@ -1037,20 +1037,22 @@ define(function(require) {
if (ips.length === 0)
return "<p style=\"margin-bottom:0;\">--</p>";
else if (ips.length === 1)
return "<p style=\"margin-bottom:0;\">"+ips[0]+"</p>"
var firstIP = ipsHtml.split("<end_first_ip>")[0]
ipsHtml = ipsHtml.split("<end_first_ip>")[1]
ipsHtml =
"<ul class=\"dropdown menu ips-dropdown\" style=\"white-space: nowrap;text-align:left;\" data-dropdown-menu>" +
"<li>" +
"<a style=\"padding-top:0em;padding-bottom:0em;padding-left:0em;color:gray\">"+
return "<p style=\"margin-bottom:0;\">"+ips[0]+"</p>";
var firstIP = ipsHtml.split("<end_first_ip>")[0];
ipsHtml = ipsHtml.split("<end_first_ip>")[1];
ipsHtml =
"<ul class='dropdown-menu-css'>" +
"<li>" +
"<div>"+
firstIP +
"</a>" +
"<ul class=\"menu\" style=\"max-height: 50em; overflow: scroll; width:250px;\">" +
"</div>" +
"</li>" +
"<li class='menu-hide upper'>" +
"<ul>" +
ipsHtml +
"</ul>" +
"</li>" +
"</li>" +
"</ul>";
return ipsHtml;
};
@ -1108,22 +1110,22 @@ define(function(require) {
}
nicSection.html(nic.NIC_ID + ": " + ip);
column.append($("<li/>").append(nicSection));
if (nic.ALIAS_IDS) {
nic.ALIAS_IDS.split(",").forEach(function(aliasId) {
var templateAlias = Array.isArray(element.TEMPLATE.NIC_ALIAS)
? element.TEMPLATE.NIC_ALIAS
: [element.TEMPLATE.NIC_ALIAS];
var alias = templateAlias.find(function(alias) {
return alias.NIC_ID === aliasId;
});
if (alias) {
var alias_ip = alias.IP || alias.IP6_ULA + "&#10;&#13;" + identation + "> " + alias.IP6_GLOBAL;
column.append($("<li/>").append($("<a/>").css({
"color": "gray",
"font-style": "italic",
@ -1157,13 +1159,13 @@ define(function(require) {
nicSection.css("font-weight","bold");
}
else {
ip = nic.IP || nic.IP6_ULA + "<br>" + identation + nic.IP6_GLOBAL
ip = nic.IP || nic.IP6_ULA + "<br>" + identation + nic.IP6_GLOBAL;
}
nicSection.html(nic.NIC_ID + ": " + ip);
column.append(nicSection);
if (nic.ALIAS_IDS) {
nic.ALIAS_IDS.split(",").forEach(function(aliasId) {
var templateAlias = Array.isArray(element.TEMPLATE.NIC_ALIAS)
@ -1191,36 +1193,36 @@ define(function(require) {
};
function isVNCSupported(element = {}) {
var actionEnabled = Config.isTabActionEnabled('vms-tab', 'VM.vnc')
var vncSupported = graphicSupported(element, 'vnc')
var actionEnabled = Config.isTabActionEnabled("vms-tab", "VM.vnc");
var vncSupported = graphicSupported(element, "vnc");
return actionEnabled && vncSupported
return actionEnabled && vncSupported;
}
function isVCenterVM(element = {}){
return Boolean(element.USER_TEMPLATE &&
String(element.USER_TEMPLATE.HYPERVISOR).toLowerCase() === 'vcenter');
String(element.USER_TEMPLATE.HYPERVISOR).toLowerCase() === "vcenter");
}
function isVMRCSupported(element = {}) {
var actionEnabled = Config.isTabActionEnabled('vms-tab', 'VM.startvmrc')
var vmrcSupported = graphicSupported(element, 'vnc')
var actionEnabled = Config.isTabActionEnabled("vms-tab", "VM.startvmrc");
var vmrcSupported = graphicSupported(element, "vnc");
return actionEnabled && vmrcSupported && isVCenterVM(element);
}
function isSPICESupported(element = {}) {
var actionEnabled = Config.isTabActionEnabled('vms-tab', 'VM.startspice')
var spiceSupported = graphicSupported(element, 'spice')
var actionEnabled = Config.isTabActionEnabled("vms-tab", "VM.startspice");
var spiceSupported = graphicSupported(element, "spice");
return actionEnabled && spiceSupported
return actionEnabled && spiceSupported;
}
function isWFileSupported(element = {}) {
var history = retrieveLastHistoryRecord(element);
var actionEnabled = Config.isTabActionEnabled("vms-tab", "VM.save_virt_viewer")
var vncSupported = graphicSupported(element, 'vnc')
var spiceSupported = graphicSupported(element, 'spice')
var actionEnabled = Config.isTabActionEnabled("vms-tab", "VM.save_virt_viewer");
var vncSupported = graphicSupported(element, "vnc");
var spiceSupported = graphicSupported(element, "spice");
return (actionEnabled && history && (vncSupported || spiceSupported))
? {
@ -1240,7 +1242,7 @@ define(function(require) {
var isEnabled = false;
if (
$.inArray(String(typeConnection).toLowerCase(), ['rdp', 'ssh']) > -1 &&
$.inArray(String(typeConnection).toLowerCase(), ["rdp", "ssh"]) > -1 &&
element && element.TEMPLATE && element.TEMPLATE.GRAPHICS && element.LCM_STATE
) {
var template = element.TEMPLATE;

View File

@ -26,7 +26,6 @@ define(function(require) {
var Menu = require("utils/menu");
var Tips = require("utils/tips");
var Navigo = require("Navigo");
var UtilsFoundation = require("utils/foundation/utils");
var router;
@ -629,8 +628,6 @@ define(function(require) {
$(document).on("click", ".paginate_button", function(event) {
event.preventDefault();
event.stopPropagation();
UtilsFoundation.update(null);
});
};
@ -691,7 +688,7 @@ define(function(require) {
$(".only-sunstone-info", tab).hide();
$(".only-sunstone-form", tab).hide();
$(".only-sunstone-list", tab).fadeIn();
if (tabName == "marketplaceapps-tab"){
$(".action_blocks", tab).removeClass("large-10").addClass("large-7");
$(".search_division", tab).removeClass("large-2").addClass("large-5");

View File

@ -29,22 +29,21 @@ define(function(require) {
var StateRolesVmButtons = require('./roles/state-roles-vm-buttons');
var Sunstone = require('sunstone');
var Tips = require('utils/tips');
var UtilsFoundation = require("utils/foundation/utils");
var VMRemoteActions = require('utils/remote-actions');
/*
TEMPLATES
*/
var TemplateHTML = require('hbs!./roles/html');
var TemplateRoleInfo = require('hbs!./roles/roleInfo');
var TemplateHTML = require("hbs!./roles/html");
var TemplateRoleInfo = require("hbs!./roles/roleInfo");
/*
CONSTANTS
*/
var TAB_ID = require('../tabId');
var PANEL_ID = require('./roles/panelId');
var TAB_ID = require("../tabId");
var PANEL_ID = require("./roles/panelId");
var XML_ROOT = "DOCUMENT";
var lastRoleIndexSelected = undefined;
@ -90,20 +89,20 @@ define(function(require) {
$.each(roles, function(){
roleList.push(
{
'name': this.name,
'state': OpenNebulaRole.state(this.state),
'cardinality': this.cardinality,
'vm_template': this.vm_template,
'parents': this.parents ? this.parents.join(', ') : '-'
"name": this.name,
"state": OpenNebulaRole.state(this.state),
"cardinality": this.cardinality,
"vm_template": this.vm_template,
"parents": this.parents ? this.parents.join(", ") : "-"
});
});
}
return TemplateHTML({
'element': this.element,
'panelId': this.panelId,
'servicePanel': this.servicePanel,
'roleList': roleList
"element": this.element,
"panelId": this.panelId,
"servicePanel": this.servicePanel,
"roleList": roleList
});
}
@ -137,12 +136,12 @@ define(function(require) {
var that = this;
if (that.servicerolesDataTable && state["selectedRole"]){
$('.check_item[id="'+state["selectedRole"]+'"]', that.servicerolesDataTable.dataTable).closest('tr').click();
$(".check_item[id=\""+state["selectedRole"]+"\"]", that.servicerolesDataTable.dataTable).closest("tr").click();
}
if (that.serviceroleVMsDataTable && state["selectedVMs"]){
$.each(state["selectedVMs"], function(){
$('.check_item[id="'+this+'"]', that.serviceroleVMsDataTable.dataTable).closest('tr').click();
$(".check_item[id=\""+this+"\"]", that.serviceroleVMsDataTable.dataTable).closest("tr").click();
});
}
}
@ -155,12 +154,12 @@ define(function(require) {
if (roles && roles.length) {
that.servicerolesDataTable = new DomDataTable(
'datatable_roles_'+this.panelId,
"datatable_roles_"+this.panelId,
{
actions: true,
info: false,
oneSelection: true,
customTabContext: $('#role_actions', context),
customTabContext: $("#role_actions", context),
customTrListener: function(tableObj, tr){
var rowData = tableObj.dataTable.fnGetData(tr);
var roleName = $(rowData[0]).data().name
@ -175,29 +174,29 @@ define(function(require) {
StateRolesButtons.enableStateActions(roleSelected.state);
if (!isEqualLastIndex) {
lastRoleIndexSelected = roleIndexSelected
lastRoleIndexSelected = roleIndexSelected;
}
$('#roles_extended_info, context')
.fadeOut(isEqualLastIndex ? 0 : 'slow', function() {
$("#roles_extended_info, context")
.fadeOut(isEqualLastIndex ? 0 : "slow", function() {
$(this).html(that.roleHTML(context, roleSelected));
that.roleSetup($(this), roleSelected);
})
.fadeIn(isEqualLastIndex ? 0 : 'slow');
.fadeIn(isEqualLastIndex ? 0 : "slow");
// The info listener is triggered instead of
// the row selection. So we click the check input to select
// the row also
var check = $('.check_item', tr);
var check = $(".check_item", tr);
if (!check.is(":checked")) {
check.trigger('click');
check.trigger("click");
}
}
});
this.servicerolesDataTable.initialize();
Sunstone.insertButtonsInTab(TAB_ID, "service_roles_tab", RolesButtons, $('#role_actions', context));
Sunstone.insertButtonsInTab(TAB_ID, "service_roles_tab", RolesButtons, $("#role_actions", context));
}
}
@ -220,13 +219,13 @@ define(function(require) {
function successCallback (data) {
if (data && data.ID === id) {
var ready = ""
var ready = "";
if (ready_status_gate) {
ready = (data.USER_TEMPLATE && data.USER_TEMPLATE.READY == "YES")
? '<span class="has-tip" title="'+
Locale.tr("The VM is ready")+'"><i class="fas fa-check"/></span>'
: '<span class="has-tip" title="'+
Locale.tr("Waiting for the VM to be ready")+'"><i class="fas fa-clock"/></span>'
? "<span class=\"has-tip\" title=\""+
Locale.tr("The VM is ready")+"\"><i class=\"fas fa-check\"/></span>"
: "<span class=\"has-tip\" title=\""+
Locale.tr("Waiting for the VM to be ready")+"\"><i class=\"fas fa-clock\"/></span>";
}
ips = OpenNebulaVM.ipsStr(data, { forceGroup: true });
@ -236,18 +235,17 @@ define(function(require) {
roleVms[index] = rowInfoRoleVm(ready, id, name, uname, gname, ips, actions, data.STATE, data.LCM_STATE);
}
promises.push(OpenNebulaVM.promiseGetVm({ id, success: successCallback }))
})
promises.push(OpenNebulaVM.promiseGetVm({ id, success: successCallback }));
});
}
$.when.apply($, promises).then(function() {
if (that.serviceroleVMsDataTable) {
that.serviceroleVMsDataTable.updateView(null, roleVms, true);
UtilsFoundation.update(context);
VMRemoteActions.bindActionsToContext(context)
VMRemoteActions.bindActionsToContext(context);
}
if (callback && typeof callback === 'function') {
if (callback && typeof callback === "function") {
callback();
}
@ -256,10 +254,10 @@ define(function(require) {
return TemplateRoleInfo({
'role': role,
'servicePanel': that.servicePanel,
'panelId': that.panelId,
'vmsTableColumns': [
"role": role,
"servicePanel": that.servicePanel,
"panelId": that.panelId,
"vmsTableColumns": [
Locale.tr("ID"),
Locale.tr("Name"),
Locale.tr("Owner"),
@ -267,22 +265,22 @@ define(function(require) {
Locale.tr("IPs"),
"" // Remote actions
],
'vms': roleVms
"vms": roleVms
});
}
function rowInfoRoleVm(ready, id, name = "", uname = "", gname = "", ips = "", actions = "", state, lcm_state) {
return [
ready,
'<input class="check_item" ' +
'style="vertical-align: inherit;" ' +
'type="checkbox" ' +
'id="vm_' + id + '" ' +
'name="selected_items" ' +
'value="' + id + '" ' +
'state="' + state + '" ' +
'lcm_state="' + lcm_state + '" />',
'<a href="/#vms-tab/' + id + '">'+ id +'</a>',
"<input class=\"check_item\" " +
"style=\"vertical-align: inherit;\" " +
"type=\"checkbox\" " +
"id=\"vm_" + id + "\" " +
"name=\"selected_items\" " +
"value=\"" + id + "\" " +
"state=\"" + state + "\" " +
"lcm_state=\"" + lcm_state + "\" />",
"<a href=\"/#vms-tab/" + id + "\">"+ id +"</a>",
name,
uname,
gname,
@ -296,11 +294,11 @@ define(function(require) {
if(that.servicePanel) {
that.serviceroleVMsDataTable = new DomDataTable(
'datatable_vms_' + that.panelId + '_' + role.name,
"datatable_vms_" + that.panelId + "_" + role.name,
{
actions: true,
info: false,
customTabContext: $('#role_vms_actions', context),
customTabContext: $("#role_vms_actions", context),
dataTableOptions: {
"bAutoWidth": false,
"bSortClasses" : false,
@ -318,15 +316,15 @@ define(function(require) {
TAB_ID,
"service_roles_tab",
RolesVmButtons,
$('div#role_vms_actions', context)
$("div#role_vms_actions", context)
);
$("#role_vms_actionsrefresh_buttons", context).on('click', function(event) {
$("#role_vms_actionsrefresh_buttons", context).on("click", function(event) {
event.preventDefault();
var prevRowsSelected = $(".check_item:checked", that.serviceroleVMsDataTable.dataTable);
var prevIdsSelected = $.map(prevRowsSelected, function(row) {
return $(row).attr('id');
return $(row).attr("id");
});
var roleSelected = that.roles[lastRoleIndexSelected];

View File

@ -31,7 +31,6 @@ define(function(require) {
var FireedgeValidator = require("utils/fireedge-validator");
var Websocket = require("utils/websocket");
var VMRemoteActions = require("utils/remote-actions");
var UtilsFoundation = require("utils/foundation/utils");
/*
CONSTANTS
@ -170,8 +169,6 @@ define(function(require) {
VMsTableUtils.tooltipCharters();
UtilsFoundation.update(null);
FireedgeValidator.validateFireedgeToken(function(token) {
if (Websocket.disconnected()) {
Websocket.start(token);

View File

@ -27,7 +27,7 @@ define(function(require) {
var RESOURCE = "VM";
var XML_ROOT = "VM";
var TEMPLATE_ATTR = 'USER_TEMPLATE';
var TEMPLATE_ATTR = "USER_TEMPLATE";
var _columns = [
Locale.tr("ID"),
@ -46,11 +46,11 @@ define(function(require) {
];
return {
'elementArray': _elementArray,
'emptyElementArray': _emptyElementArray,
'tooltipCharters': showCharterInfo,
'columns': _columns,
'leasesClock': leasesClock
"elementArray": _elementArray,
"emptyElementArray": _emptyElementArray,
"tooltipCharters": showCharterInfo,
"columns": _columns,
"leasesClock": leasesClock
};
function checkTime(startTime, addedEndTime, warningTime, rtnTime){
@ -65,7 +65,7 @@ define(function(require) {
var operator = addedEndTime.replace(regexNumber, "");
var finalTime = date;
switch (operator) {
case '-':
case "-":
finalTime = date - added;
break;
default:
@ -88,7 +88,7 @@ define(function(require) {
var wtime = date;
switch (operator) {
case '-':
case "-":
wtime = finalTime - warning;
break;
default:
@ -137,7 +137,7 @@ define(function(require) {
);
}
}
})
});
$(".describeCharter").off("mouseleave").on("mouseleave", function(e){
$(this).find("."+classInfo).remove();
});
@ -146,11 +146,11 @@ define(function(require) {
function leasesClock(element){
var rtn = "";
if(
element &&
element.STIME &&
element.USER_TEMPLATE &&
element.USER_TEMPLATE.SCHED_ACTION &&
config &&
element &&
element.STIME &&
element.USER_TEMPLATE &&
element.USER_TEMPLATE.SCHED_ACTION &&
config &&
config.system_config &&
config.system_config.leases
){
@ -164,27 +164,27 @@ define(function(require) {
}
actionsArray.some(function(action){
if(
action &&
action.ACTION &&
action.TIME &&
leases &&
leases[action.ACTION] &&
leases[action.ACTION].time &&
!isNaN(parseInt(leases[action.ACTION].time)) &&
action &&
action.ACTION &&
action.TIME &&
leases &&
leases[action.ACTION] &&
leases[action.ACTION].time &&
!isNaN(parseInt(leases[action.ACTION].time)) &&
leases[action.ACTION].color
){
if(checkTime(element.STIME, action.TIME)){
rtn = $("<i/>",{class:"describeCharter fa fa-clock",data_start:element.STIME, data_add:action.TIME, data_action:action.ACTION}).css({"position":"relative","color":leases[action.ACTION].color});
if(
leases[action.ACTION].warning &&
leases[action.ACTION].warning.time &&
leases[action.ACTION].warning &&
leases[action.ACTION].warning.time &&
leases[action.ACTION].warning.color
){
if(checkTime(element.STIME, action.TIME, leases[action.ACTION].warning.time)){
rtn.css("color", leases[action.ACTION].warning.color);
}
}
rtn = rtn.prop('outerHTML');
rtn = rtn.prop("outerHTML");
return true;
}
}
@ -238,13 +238,13 @@ define(function(require) {
var color_html = Status.state_lock_to_color("VM", value_state, element_json[RESOURCE.toUpperCase()]["LOCK"]);
return [
'<input class="check_item" '+
'style="vertical-align: inherit;"'+
'type="checkbox" '+
'id="' + RESOURCE.toLowerCase() + '_' + element.ID + '" '+
'name="selected_items" '+
'value="' + element.ID + '" '+
'state="'+element.STATE+'" lcm_state="'+element.LCM_STATE+'"/>'+color_html,
"<input class=\"check_item\" "+
"style=\"vertical-align: inherit;\""+
"type=\"checkbox\" "+
"id=\"" + RESOURCE.toLowerCase() + "_" + element.ID + "\" "+
"name=\"selected_items\" "+
"value=\"" + element.ID + "\" "+
"state=\""+element.STATE+"\" lcm_state=\""+element.LCM_STATE+"\"/>"+color_html,
element.ID,
element.NAME,
element.UNAME,
@ -255,7 +255,7 @@ define(function(require) {
Humanize.prettyTimeDatatable(element.STIME),
actions,
TemplateUtils.htmlEncode(TemplateUtils.templateToString(element)),
(LabelsUtils.labelsStr(element[TEMPLATE_ATTR])||''),
(LabelsUtils.labelsStr(element[TEMPLATE_ATTR])||""),
btoa(unescape(encodeURIComponent(JSON.stringify(search)))),
leasesClock(element)
];
@ -264,9 +264,9 @@ define(function(require) {
function _emptyElementArray(vmId) {
return [
'<input class="check_item" type="checkbox" id="' + RESOURCE.toLowerCase() + '_' +
vmId + '" name="selected_items" value="' +
vmId + '"/>',
"<input class=\"check_item\" type=\"checkbox\" id=\"" + RESOURCE.toLowerCase() + "_" +
vmId + "\" name=\"selected_items\" value=\"" +
vmId + "\"/>",
vmId,
"",
"",

View File

@ -1,29 +0,0 @@
/* -------------------------------------------------------------------------- */
/* Copyright 2002-2021, OpenNebula Project, OpenNebula Systems */
/* */
/* Licensed under the Apache License, Version 2.0 (the "License"); you may */
/* not use this file except in compliance with the License. You may obtain */
/* a copy of the License at */
/* */
/* http://www.apache.org/licenses/LICENSE-2.0 */
/* */
/* Unless required by applicable law or agreed to in writing, software */
/* distributed under the License is distributed on an "AS IS" BASIS, */
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
/* See the License for the specific language governing permissions and */
/* limitations under the License. */
/* -------------------------------------------------------------------------- */
define(function(require) {
require('foundation')
function _update(context) {
$('.ips-dropdown', context).foundation();
$('.rdp-buttons', context).foundation();
}
return {
'update': _update
}
});

View File

@ -15,18 +15,16 @@
/* -------------------------------------------------------------------------- */
define(function(require) {
require('foundation')
require("foundation");
var OpenNebulaVM = require('opennebula/vm');
var OpenNebulaService = require('opennebula/service');
var UtilsFoundation = require("utils/foundation/utils");
var OpenNebulaVM = require("opennebula/vm");
var OpenNebulaService = require("opennebula/service");
var TemplateInfo = require("hbs!./info");
var TemplateInfo = require('hbs!./info');
function printInfoConnection(context, info) {
context.empty()
info && context.append(TemplateInfo(info))
UtilsFoundation.update(context);
context.empty();
info && context.append(TemplateInfo(info));
if (info && info.name) {
document.title = info.name;
@ -34,27 +32,27 @@ define(function(require) {
}
function decodeInfoConnection(info_encode) {
if (!info_encode) return undefined
if (!info_encode) return undefined;
try {
var json = atob(info_encode)
var info = JSON.parse(json)
var json = atob(info_encode);
var info = JSON.parse(json);
var stateId = OpenNebulaVM.STATES[info.state]
var lcmStateId = OpenNebulaVM.LCM_STATES[info.state]
var stateClass = OpenNebulaVM.stateClass(stateId) || OpenNebulaVM.lcmStateClass(lcmStateId)
var stateId = OpenNebulaVM.STATES[info.state];
var lcmStateId = OpenNebulaVM.LCM_STATES[info.state];
var stateClass = OpenNebulaVM.stateClass(stateId) || OpenNebulaVM.lcmStateClass(lcmStateId);
var service = OpenNebulaService.getService(info.service_id)
var service = OpenNebulaService.getService(info.service_id);
return $.extend(info, { stateClass, service })
return $.extend(info, { stateClass, service });
} catch (err) {
console.log(err)
console.log(err);
}
}
return {
'printInfoConnection': printInfoConnection,
'decodeInfoConnection': decodeInfoConnection
}
"printInfoConnection": printInfoConnection,
"decodeInfoConnection": decodeInfoConnection
};
});

View File

@ -17,28 +17,27 @@
define(function (require) {
/* DEPENDENCIES */
var Locale = require('utils/locale');
var Notifier = require('utils/notifier');
var OpenNebula = require('opennebula');
var OpenNebulaUser = require('opennebula/user');
var Sunstone = require('sunstone');
var TemplateUtils = require('utils/template-utils');
var Tree = require('./tree');
var UtilsFoundation = require("utils/foundation/utils");
var Locale = require("utils/locale");
var Notifier = require("utils/notifier");
var OpenNebula = require("opennebula");
var OpenNebulaUser = require("opennebula/user");
var Sunstone = require("sunstone");
var TemplateUtils = require("utils/template-utils");
var Tree = require("./tree");
var LABELS_ATTR = 'LABELS';
var LABELS_ATTR = "LABELS";
return {
'labelsStr': _labelsStr,
'deserializeLabels': _deserializeLabels,
'makeTree': _makeTree,
'insertLabelsMenu': _insertLabelsMenu,
'insertLabelsDropdown': _insertLabelsDropdown,
'clearLabelsFilter': _clearLabelsFilter,
'setLabelsFilter': _setLabelsFilter,
'getLabelsFilter': _getLabelsFilter,
'getLabels': _getLabels,
'getLabel': _getLabel
"labelsStr": _labelsStr,
"deserializeLabels": _deserializeLabels,
"makeTree": _makeTree,
"insertLabelsMenu": _insertLabelsMenu,
"insertLabelsDropdown": _insertLabelsDropdown,
"clearLabelsFilter": _clearLabelsFilter,
"setLabelsFilter": _setLabelsFilter,
"getLabelsFilter": _getLabelsFilter,
"getLabels": _getLabels,
"getLabel": _getLabel
};
/* FUNCTION DEFINITIONS */
@ -60,25 +59,25 @@ define(function (require) {
* @param {string} [opts.placeholder] - Message to be shown in no labels are defined
*/
function _insertLabelsMenu(opts) {
var context = opts.context || $('#li_' + opts.tabName);
var context = opts.context || $("#li_" + opts.tabName);
var dataTable = opts.dataTable || Sunstone.getDataTable(opts.tabName).dataTable;
var labelsColumn = opts.labelsColumn || Sunstone.getDataTable(opts.tabName).labelsColumn;
var labelsPath = opts.labelsPath;
var labels = _getLabels(dataTable, labelsColumn, labelsPath);
$('.labels-tree', context).remove();
$(".labels-tree", context).remove();
if ($.isEmptyObject(labels)) {
if (opts.placeholder) {
context.html('<div class="text-center">' + opts.placeholder + '</div>');
context.html("<div class=\"text-center\">" + opts.placeholder + "</div>");
}
} else {
context.append(Tree.html(_makeTree(labels), true));
context.off('click', '.labeltree-line');
context.off("click", ".labeltree-line");
Tree.setup($('.labels-tree', context));
Tree.setup($(".labels-tree", context));
var currentLabel = $('span[one-label-full-name="' + _getLabelsFilter(dataTable) + '"]', context);
var currentLabel = $("span[one-label-full-name=\"" + _getLabelsFilter(dataTable) + "\"]", context);
if (currentLabel.length == 0) {
_clearLabelsFilter(dataTable, labelsColumn);
@ -91,16 +90,16 @@ define(function (require) {
/*
Filter datatable when a label in the left menu is clicked
*/
context.off('click', '.labeltree-line');
context.on('click', '.labeltree-line', function () {
context.off("click", ".labeltree-line");
context.on("click", ".labeltree-line", function () {
var span = $(".one-label", this);
if ($(span).hasClass("active")) {
if (opts.tabName && !Sunstone.rightListVisible($('#' + opts.tabName))) {
if (opts.tabName && !Sunstone.rightListVisible($("#" + opts.tabName))) {
Sunstone.showTab(opts.tabName);
}
var label = $(span).attr('one-label-full-name');
var label = $(span).attr("one-label-full-name");
_setLabelsFilter(dataTable, labelsColumn, label);
} else {
@ -117,14 +116,14 @@ define(function (require) {
var dataTable = tabTable.dataTable;
var labelsColumn = tabTable.labelsColumn;
var labelsDropdown = $('#' + tabName + 'LabelsDropdown');
var labelsDropdown = $("#" + tabName + "LabelsDropdown");
OpenNebulaUser.show({
data: {
id: config['user_id']
id: config["user_id"]
},
success: function (request, user_json) {
var labels_persis = '';
var labels_persis = "";
if (user_json["USER"]["TEMPLATE"]) {
if (user_json["USER"]["TEMPLATE"]["LABELS"]) {
labels_persis = user_json["USER"]["TEMPLATE"]["LABELS"];
@ -134,15 +133,15 @@ define(function (require) {
labels_persis = _deserializeLabels(labels_persis);
var array_labels_yaml = [];
var labels_yaml = {};
if (config['all_labels'][0] != "") {
$.each(config['all_labels'], function (index) {
array_labels_yaml.push(config['all_labels'][index] + '_YAML');
if (labels[config['all_labels'][index]]) {
delete labels[config['all_labels'][index]];
if (config["all_labels"][0] != "") {
$.each(config["all_labels"], function (index) {
array_labels_yaml.push(config["all_labels"][index] + "_YAML");
if (labels[config["all_labels"][index]]) {
delete labels[config["all_labels"][index]];
}
});
labels_yaml = _deserializeLabels(array_labels_yaml.join(','));
labels_yaml = _deserializeLabels(array_labels_yaml.join(","));
}
var keys = Object.keys(labels_persis).sort();
for (var i = 0; i < keys.length; i++) {
@ -155,27 +154,27 @@ define(function (require) {
$.extend(labels, labels_persis);
var html_yaml = "";
if (!$.isEmptyObject(labels_yaml)) {
html_yaml = '<h6>' + Locale.tr('System Labels') + '</h6>' +
'<div class="labeltree-container">' +
html_yaml = "<h6>" + Locale.tr("System Labels") + "</h6>" +
"<div class=\"labeltree-container\">" +
Tree.html(_makeTree(labels_yaml), false) +
'</div>';
"</div>";
}
labelsDropdown.html(
'<div>' +
'<h6>' + Locale.tr('Edit Labels') + '</h6>' +
'<div class="labeltree-container">' +
"<div>" +
"<h6>" + Locale.tr("Edit Labels") + "</h6>" +
"<div class=\"labeltree-container\">" +
Tree.html(_makeTree(labels), false) +
'</div>' +
"</div>" +
html_yaml +
'<div class="input-container">' +
'<input type="text" class="newLabelInput" placeholder="' + Locale.tr("Add Label") + '"/>' +
'</div>' +
'</div>');
"<div class=\"input-container\">" +
"<input type=\"text\" class=\"newLabelInput\" placeholder=\"" + Locale.tr("Add Label") + "\"/>" +
"</div>" +
"</div>");
Tree.setup(labelsDropdown);
recountLabels();
$('[data-toggle="' + tabName + 'LabelsDropdown"]').off('click');
$('[data-toggle="' + tabName + 'LabelsDropdown"]').on('click', function () {
$("[data-toggle=\"" + tabName + "LabelsDropdown\"]").off("click");
$("[data-toggle=\"" + tabName + "LabelsDropdown\"]").on("click", function () {
recountLabels();
});
}
@ -193,93 +192,93 @@ define(function (require) {
var selectedItems = tabTable.elements();
$.each(selectedItems, function (index, resourceId) {
labelsStr = _getLabel(tabName, dataTable, labelsColumn, resourceId);
if (labelsStr != '') {
$.each(labelsStr.split(','), function () {
if (labelsStr != "") {
$.each(labelsStr.split(","), function () {
if (labelsIndexed[this]) {
labelsIndexed[this] += 1
labelsIndexed[this] += 1;
} else {
labelsIndexed[this] = 1
labelsIndexed[this] = 1;
}
})
});
}
});
// Set checkboxes (check|minus) depending on the number of items
// Reset label checkboxes
$('.labelsCheckbox', labelsDropdown)
.removeClass('fa-minus-square')
.removeClass('fa-check-square')
.addClass('fa-square');
$(".labelsCheckbox", labelsDropdown)
.removeClass("fa-minus-square")
.removeClass("fa-check-square")
.addClass("fa-square");
var labelsCheckbox;
$.each(labelsIndexed, function (labelName, numberOfItems) {
labelsCheckbox = $('.labelsCheckbox',
$('[one-label-full-name="' + labelName + '"]', labelsDropdown).closest('li'));
labelsCheckbox = $(".labelsCheckbox",
$("[one-label-full-name=\"" + labelName + "\"]", labelsDropdown).closest("li"));
if (labelsCheckbox.length > 0) {
if (numberOfItems == selectedItems.length) {
$(labelsCheckbox[0])
.removeClass('fa-square')
.addClass('fa-check-square');
.removeClass("fa-square")
.addClass("fa-check-square");
} else {
$(labelsCheckbox[0])
.removeClass('fa-square')
.addClass('fa-minus-square');
.removeClass("fa-square")
.addClass("fa-minus-square");
}
}
});
$('.newLabelInput', labelsDropdown).focus();
$(".newLabelInput", labelsDropdown).focus();
}
/*
Check/Uncheck label & Update Templates
*/
labelsDropdown.off('click', '.labeltree-line');
labelsDropdown.on('click', '.labeltree-line', function () {
labelsDropdown.off("click", ".labeltree-line");
labelsDropdown.on("click", ".labeltree-line", function () {
var action;
var that = $(".labelsCheckbox", this);
if ($(that).hasClass('fa-square')) {
action = 'add';
$(that).removeClass('fa-square').addClass('fa-check-square');
if ($(that).hasClass("fa-square")) {
action = "add";
$(that).removeClass("fa-square").addClass("fa-check-square");
} else {
action = 'remove';
$(that).removeClass('fa-check-square fa-minus-square').addClass('fa-square');
action = "remove";
$(that).removeClass("fa-check-square fa-minus-square").addClass("fa-square");
}
OpenNebulaUser.show({
data: {
id: config['user_id']
id: config["user_id"]
},
success: function (request, user_json) {
var labels_persis = '';
var labels_persis = "";
if (user_json["USER"]["TEMPLATE"]) {
if (user_json["USER"]["TEMPLATE"]["LABELS"]) {
labels_persis = user_json["USER"]["TEMPLATE"]["LABELS"];
}
}
var labelName = $('.one-label', $(that).closest('li')).attr('one-label-full-name');
var labelName = $(".one-label", $(that).closest("li")).attr("one-label-full-name");
var labelsArray, labelsArray_persis, labelIndex;
var selectedItems = tabTable.elements();
if (labels_persis != '') {
labelsArray_persis = labels_persis.split(',')
if (labels_persis != "") {
labelsArray_persis = labels_persis.split(",");
} else {
labelsArray_persis = []
labelsArray_persis = [];
}
$.each(selectedItems, function (index, resourceId) {
labelsStr = _getLabel(tabName, dataTable, labelsColumn, resourceId);
if (labelsStr != '') {
labelsArray = labelsStr.split(',')
if (labelsStr != "") {
labelsArray = labelsStr.split(",");
} else {
labelsArray = []
labelsArray = [];
}
labelIndex = $.inArray(labelName, labelsArray);
if (action == 'add' && labelIndex == -1) {
labelsArray.push(labelName)
if (action == "add" && labelIndex == -1) {
labelsArray.push(labelName);
_updateResouceLabels(tabName, resourceId, labelsArray);
} else if (action == 'remove' && labelIndex != -1) {
} else if (action == "remove" && labelIndex != -1) {
if ((!labelsArray_persis || (labelsArray_persis && $.inArray(labelName, labelsArray_persis) == -1)) ||
(!config['all_labels'] || (config['all_labels'] && $.inArray(labelName, config['all_labels']) == -1))) {
(!config["all_labels"] || (config["all_labels"] && $.inArray(labelName, config["all_labels"]) == -1))) {
labelsArray.splice(labelIndex, 1);
_updateResouceLabels(tabName, resourceId, labelsArray);
}
@ -292,21 +291,21 @@ define(function (require) {
/*
Add a new label when ENTER is presed in the input
*/
labelsDropdown.off('keypress', '.newLabelInput');
labelsDropdown.on('keypress', '.newLabelInput', function (e) {
labelsDropdown.off("keypress", ".newLabelInput");
labelsDropdown.on("keypress", ".newLabelInput", function (e) {
var ev = e || window.event;
var key = ev.keyCode;
var labelName = $(this).val().trim();
if (key == 13 && !ev.altKey && labelName !== '') {
if (key == 13 && !ev.altKey && labelName !== "") {
var labelsArray;
var labelClean = transformLabelToCleanFormat(labelName)
var selectedItems = tabTable.elements()
var labelClean = transformLabelToCleanFormat(labelName);
var selectedItems = tabTable.elements();
$.each(selectedItems, function (_, resourceId) {
labelsStr = _getLabel(tabName, dataTable, labelsColumn, resourceId);
if (labelsStr != '') {
labelsArray = labelsStr.split(',');
if (labelsStr != "") {
labelsArray = labelsStr.split(",");
} else {
labelsArray = [];
}
@ -338,9 +337,9 @@ define(function (require) {
var tabTable = Sunstone.getDataTable(tabName);
if (resource == "ServiceTemplate" || resource == "Service") {
var templateStr = '{"' + LABELS_ATTR.toLowerCase() + '":"' + labelsArray.join(',') + '"}';
var templateStr = "{\"" + LABELS_ATTR.toLowerCase() + "\":\"" + labelsArray.join(",") + "\"}";
} else {
var templateStr = LABELS_ATTR + '="' + labelsArray.join(',') + '"';
var templateStr = LABELS_ATTR + "=\"" + labelsArray.join(",") + "\"";
}
OpenNebula[resource].append({
@ -357,24 +356,24 @@ define(function (require) {
},
success: function (request, response) {
tabTable.updateElement(request, response);
if (Sunstone.rightInfoVisible($('#' + tabName))) {
if (Sunstone.rightInfoVisible($("#" + tabName))) {
Sunstone.insertPanels(tabName, response);
}
_insertLabelsMenu({ 'tabName': tabName });
_insertLabelsMenu({ "tabName": tabName });
_insertLabelsDropdown(tabName);
},
error: Notifier.onError
});
},
error: Notifier.onError
})
});
}
function _labelsStr(elementTemplate) {
if (elementTemplate &&
elementTemplate.BODY &&
if (elementTemplate &&
elementTemplate.BODY &&
elementTemplate.BODY[LABELS_ATTR.toLowerCase()]
) {
return TemplateUtils.htmlEncode(elementTemplate.BODY[LABELS_ATTR.toLowerCase()]);
@ -388,9 +387,9 @@ define(function (require) {
if (labelsStr) {
var parent;
$.each(labelsStr.split(','), function () {
$.each(labelsStr.split(","), function () {
parent = indexedLabels;
$.each(this.split('/'), function () {
$.each(this.split("/"), function () {
if (parent[this] == undefined) {
parent[this] = {};
}
@ -404,7 +403,7 @@ define(function (require) {
function _makeTree(indexedLabels, currentLabel) {
var treeRoot = {
htmlStr: '',
htmlStr: "",
subTree: []
};
@ -413,7 +412,7 @@ define(function (require) {
for (var i = 0; i < keys.length; i++) {
var folderName = keys[i];
var childs = indexedLabels[folderName];
treeRoot.subTree.push(_makeSubTree('', folderName, childs, currentLabel));
treeRoot.subTree.push(_makeSubTree("", folderName, childs, currentLabel));
}
return treeRoot;
@ -446,19 +445,19 @@ define(function (require) {
var fullName = parentName + folderName;
if (persis) {
var htmlStr =
'<span class="secondary one-label" persis="true" title="' + fullName + '" one-label-full-name="' + fullName + '">' +
"<span class=\"secondary one-label\" persis=\"true\" title=\"" + fullName + "\" one-label-full-name=\"" + fullName + "\">" +
folderName +
'</span>';
"</span>";
} else if (yaml) {
var htmlStr =
'<span class="secondary one-label" yaml="true" title="' + fullName + '" one-label-full-name="' + fullName + '">' +
"<span class=\"secondary one-label\" yaml=\"true\" title=\"" + fullName + "\" one-label-full-name=\"" + fullName + "\">" +
folderName +
'</span>';
"</span>";
} else {
var htmlStr =
'<span class="secondary one-label" title="' + fullName + '" one-label-full-name="' + fullName + '">' +
"<span class=\"secondary one-label\" title=\"" + fullName + "\" one-label-full-name=\"" + fullName + "\">" +
folderName +
'</span>';
"</span>";
}
@ -471,7 +470,7 @@ define(function (require) {
for (var i = 0; i < keys.length; i++) {
var subFolderName = keys[i];
var subChilds = childs[subFolderName];
tree.subTree.push(_makeSubTree(fullName + '/', subFolderName, subChilds, currentLabel));
tree.subTree.push(_makeSubTree(fullName + "/", subFolderName, subChilds, currentLabel));
}
return tree;
@ -485,21 +484,20 @@ define(function (require) {
// Make the label safe, it may contain regexp special characters. Source:
// https://developer.mozilla.org/en/docs/Web/JavaScript/Guide/Regular_Expressions
var escapedLabel = label.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
var escapedLabel = label.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
var regExp = '^' + escapedLabel + '$|' +
',' + escapedLabel + '$|' +
'^' + escapedLabel + ',|' +
',' + escapedLabel + ','
var regExp = "^" + escapedLabel + "$|" +
"," + escapedLabel + "$|" +
"^" + escapedLabel + ",|" +
"," + escapedLabel + ",";
dataTable.data("sunstone-label-filter", label);
dataTable.fnFilter(regExp, labelsColumn, true, false);
UtilsFoundation.update(null);
}
function _clearLabelsFilter(dataTable, labelsColumn) {
dataTable.removeData("sunstone-label-filter");
dataTable.fnFilter('', labelsColumn, true, false);
dataTable.fnFilter("", labelsColumn, true, false);
}
function _getLabelsFilter(dataTable) {
@ -512,25 +510,25 @@ define(function (require) {
$.each(dataTable.fnGetData(), function () {
if (labelsPath) {
tmp = this;
$.each(labelsPath.split('.'), function () {
$.each(labelsPath.split("."), function () {
if (tmp) {
tmp = tmp[this];
}
});
if (tmp && tmp != '') {
if (tmp && tmp != "") {
labels.push(tmp);
}
} else {
if (this[labelsColumn] != '') {
if (this[labelsColumn] != "") {
labels.push(this[labelsColumn]);
}
}
})
return _deserializeLabels(labels.join(','));
});
return _deserializeLabels(labels.join(","));
}
function _getLabel(tabName, dataTable, labelsColumn, resourceId) {
if (Sunstone.rightInfoVisible($('#' + tabName))) {
if (Sunstone.rightInfoVisible($("#" + tabName))) {
var element = Sunstone.getElementRightInfo(tabName);
if (element) {
var template;
@ -543,17 +541,17 @@ define(function (require) {
if (template["BODY"] && template["BODY"][LABELS_ATTR.toLowerCase()]) {
return template["BODY"][LABELS_ATTR.toLowerCase()];
} else {
return template[LABELS_ATTR] || '';
return template[LABELS_ATTR] || "";
}
} else {
return '';
return "";
}
} else {
return '';
return "";
}
} else {
var nodes = dataTable.fnGetNodes();
var tr = $('.check_item[value="' + resourceId + '"]', nodes).closest('tr');
var tr = $(".check_item[value=\"" + resourceId + "\"]", nodes).closest("tr");
var aData = dataTable.fnGetData(tr);
return aData[labelsColumn];
}
@ -562,44 +560,44 @@ define(function (require) {
/**
* Returns the label with a clean format
* @param {string} label
*
*
* Eg: ubuntu linux/alpine => Ubuntu Linux/Alpine
*/
function transformLabelToCleanFormat(label) {
let SEPARATOR_SUB_TREE = '/'
let SEPARATOR_SUB_TREE = "/";
return $.map(label.split(SEPARATOR_SUB_TREE), function(tree) {
return firstLetterToUppercase(tree);
}).join(SEPARATOR_SUB_TREE)
}).join(SEPARATOR_SUB_TREE);
}
/**
* Returns the same string but with first letter in uppercase
* Returns the same string but with first letter in uppercase
* @param {string} phrase
*/
function firstLetterToUppercase(phrase) {
let words = splitPhraseWithSpaces(phrase)
let words = splitPhraseWithSpaces(phrase);
return $.map(words, function(word) {
return capitalize(word.toLowerCase());
}).join(' ')
}).join(" ");
}
/**
* Separate words from phrase using regex to split with white spaces
* @param {string} [phrase] - Phrase
*/
function splitPhraseWithSpaces(phrase = '') {
let validRegex = /[^ ]+/g
function splitPhraseWithSpaces(phrase = "") {
let validRegex = /[^ ]+/g;
return String(phrase).match(validRegex)
return String(phrase).match(validRegex);
}
/**
* Convert first letter to upper case
* @param {string} string
* @param {string} string
*/
function capitalize(string) {
return string[0].toUpperCase() + string.slice(1)
return string[0].toUpperCase() + string.slice(1);
}
});

View File

@ -15,8 +15,8 @@
/* -------------------------------------------------------------------------- */
define(function(require) {
var Locale = require('utils/locale'),
Sunstone = require('sunstone'),
var Locale = require("utils/locale"),
Sunstone = require("sunstone"),
Config = require("sunstone-config"),
OpenNebulaVM = require("opennebula/vm"),
FireedgeValidator = require('utils/fireedge-validator'),
@ -25,17 +25,17 @@ define(function(require) {
function _callSpice(data) {
if (data.hasOwnProperty('id')) Sunstone.runAction('VM.startspice_action', String(data.id));
}
function _callVNC(data) {
if (data.hasOwnProperty('id')) Sunstone.runAction('VM.startvnc_action', String(data.id));
}
function _callSaveRDP(data) {
(data.hasOwnProperty('ip') && data.hasOwnProperty('name'))
? Sunstone.runAction('VM.save_rdp', data)
: Notifier.notifyError(Locale.tr('This VM needs a nic with rdp active'));
(data.hasOwnProperty("ip") && data.hasOwnProperty("name"))
? Sunstone.runAction("VM.save_rdp", data)
: Notifier.notifyError(Locale.tr("This VM needs a nic with rdp active"));
}
function _callSaveWFile(data) {
(
data.hasOwnProperty("id") &&
@ -64,125 +64,127 @@ define(function(require) {
/**
* Guacamole actions
*/
function _callGuacVNC(data) {
(data.hasOwnProperty('id'))
? Sunstone.runAction('VM.startguac_action', String(data.id), 'vnc')
: Notifier.notifyError(Locale.tr('VNC - Invalid action'));
(data.hasOwnProperty("id"))
? Sunstone.runAction("VM.startguac_action", String(data.id), "vnc")
: Notifier.notifyError(Locale.tr("VNC - Invalid action"));
}
function _callGuacRDP(data) {
(data.hasOwnProperty('id'))
? Sunstone.runAction('VM.startguac_action', String(data.id), 'rdp')
: Notifier.notifyError(Locale.tr('RDP - Invalid action'));
(data.hasOwnProperty("id"))
? Sunstone.runAction("VM.startguac_action", String(data.id), "rdp")
: Notifier.notifyError(Locale.tr("RDP - Invalid action"));
}
function _callGuacSSH(data) {
(data.hasOwnProperty('id'))
? Sunstone.runAction('VM.startguac_action', String(data.id), 'ssh')
: Notifier.notifyError(Locale.tr('SSH - Invalid action'));
(data.hasOwnProperty("id"))
? Sunstone.runAction("VM.startguac_action", String(data.id), "ssh")
: Notifier.notifyError(Locale.tr("SSH - Invalid action"));
}
/**
* Render actions
*/
function buttonVnc(id = '') {
var icon = $('<i>', { class: 'fas fa-desktop' })
function buttonVnc(id = "") {
var icon = $("<i>", { class: "fas fa-desktop" });
var button = $('<button>', {
title: 'vnc',
class: 'vnc remote-vm',
'data-id': id
})
var button = $("<button>", {
title: "vnc",
class: "vnc remote-vm",
"data-id": id
});
return $('<div>').append(button.append(icon)).html()
return $("<div>").append(button.append(icon)).html();
}
function buttonSSH(id = '') {
var icon = $('<i>', { class: 'fas fa-terminal' })
function buttonSSH(id = "") {
var icon = $("<i>", { class: "fas fa-terminal" });
var button = $('<button>', {
title: 'ssh',
class: 'ssh remote-vm',
'data-id': id
})
var button = $("<button>", {
title: "ssh",
class: "ssh remote-vm",
"data-id": id
});
return $('<div>').append(button.append(icon)).html()
return $("<div>").append(button.append(icon)).html();
}
function buttonSpice(id = '') {
var icon = $('<i>', { class: 'fas fa-desktop' })
function buttonSpice(id = "") {
var icon = $("<i>", { class: "fas fa-desktop" });
var button = $('<button>', {
title: 'spice',
class: 'spice remote-vm',
'data-id': id
})
var button = $("<button>", {
title: "spice",
class: "spice remote-vm",
"data-id": id
});
return $('<div>').append(button.append(icon)).html()
return $("<div>").append(button.append(icon)).html();
}
function buttonWFile(id = '', data = {}) {
var icon = $('<i>', { class: 'fas fa-external-link-square-alt' })
function buttonWFile(id = "", data = {}) {
var icon = $("<i>", { class: "fas fa-external-link-square-alt" });
var button = $('<button>', {
title: 'download virt-viewer file',
class: 'w-file remote-vm',
'data-id': id,
'data-type': data.type,
'data-port': data.port,
'data-hostname':data.hostname
})
var button = $("<button>", {
title: "download virt-viewer file",
class: "w-file remote-vm",
"data-id": id,
"data-type": data.type,
"data-port": data.port,
"data-hostname":data.hostname
});
return $('<div>').append(button.append(icon)).html()
return $("<div>").append(button.append(icon)).html();
}
function dropdownRDP(id = '', ip = '', vm = {}) {
var icon = $('<i>', { class: 'fab fa-windows' })
var dropdownButton = $('<button>', { title:'RDP menu', class: 'remote-vm' })
function dropdownRDP(id = "", ip = "", vm = {}) {
var icon = $("<i>", { class: "fab fa-windows" });
var dropdownButton = $("<button>", { title:"RDP menu", class: "remote-vm" });
var dropdownMenu = $('<ul>', {
class: 'dropdown menu rdp-buttons',
'data-dropdown-menu': ''
})
var dropdownMenu = $("<ul>", {
class: "dropdown-menu-css"
});
var buttonsEnabled = []
var buttonsEnabled = [];
Config.isTabActionEnabled("vms-tab", "VM.rdp") &&
buttonsEnabled.push($('<li>').append(buttonRDP(id)));
buttonsEnabled.push($("<li>").append(buttonRDP(id)));
Config.isTabActionEnabled("vms-tab", "VM.save_rdp") &&
buttonsEnabled.push($('<li>').append(buttonSaveRDP(ip, vm)));
buttonsEnabled.push($("<li>").append(buttonSaveRDP(ip, vm)));
if (buttonsEnabled.length === 0) return '';
if (buttonsEnabled.length === 0) return "";
var menu = $('<ul>', { class: 'menu' }).append(buttonsEnabled)
var menu = $("<ul>", { class: "menu" }).append(buttonsEnabled);
return $('<div>').append(
return $("<div>").append(
dropdownMenu.append(
$('<li>').append([dropdownButton.append(icon), menu])
[
$("<li>").append(dropdownButton.append(icon)),
$("<li>", {class:"menu-hide"}).append(menu)
]
)
).html()
).html();
}
function buttonRDP(id = '') {
var icon = $('<i>', { class: 'fas fa-desktop' })
.css({ width: '2em', 'text-align': 'center' })
var text = $('<span>', { text: Locale.tr('HTML') })
var button = $('<a>', { class: 'rdp', 'data-id': id })
function buttonRDP(id = "") {
var icon = $("<i>", { class: "fas fa-desktop" })
.css({ width: "2em", "text-align": "center" });
return $('<div>').append(button.append([icon, text])).html()
var text = $("<span>", { text: Locale.tr("HTML") });
var button = $("<a>", { class: "rdp", "data-id": id });
return $("<div>").append(button.append([icon, text])).html();
}
function buttonSaveRDP(ip = "", vm = {}) {
var icon = $('<i>', { class: 'fas fa-file' })
.css({ width: '2em', 'text-align': 'center' })
var text = $('<span>', { text: Locale.tr('RDP Client') })
var button = $('<a>', { class: 'save-rdp', 'data-name': vm.NAME, 'data-ip': ip })
var icon = $("<i>", { class: "fas fa-file" })
.css({ width: "2em", "text-align": "center" });
var text = $("<span>", { text: Locale.tr("Client") });
var button = $("<a>", { class: "save-rdp", "data-name": vm.NAME, "data-ip": ip });
var username, password;
@ -195,14 +197,14 @@ define(function(require) {
}
}
username && button.attr('data-username', username)
password && button.attr('data-password', password)
username && button.attr("data-username", username);
password && button.attr("data-password", password);
return $('<div>').append(button.append([icon, text])).html()
return $("<div>").append(button.append([icon, text])).html();
}
function _renderActionsHtml(vm) {
var actions = '';
var actions = "";
if (OpenNebulaVM.isVNCSupported(vm)) {
actions += buttonVnc(vm.ID);
@ -212,23 +214,23 @@ define(function(require) {
}
var wFile = OpenNebulaVM.isWFileSupported(vm);
actions += wFile ? buttonWFile(vm.ID, wFile) : '';
actions += wFile ? buttonWFile(vm.ID, wFile) : "";
var rdpIp = OpenNebulaVM.isConnectionSupported(vm, 'rdp');
actions += rdpIp ? dropdownRDP(vm.ID, rdpIp, vm) : '';
var rdpIp = OpenNebulaVM.isConnectionSupported(vm, "rdp");
actions += rdpIp ? dropdownRDP(vm.ID, rdpIp, vm) : "";
var ssh = OpenNebulaVM.isConnectionSupported(vm, 'ssh');
actions += ssh && Config.isTabActionEnabled("vms-tab", "VM.rdp") ? buttonSSH(vm.ID) : '';
var ssh = OpenNebulaVM.isConnectionSupported(vm, "ssh");
actions += ssh && Config.isTabActionEnabled("vms-tab", "VM.rdp") ? buttonSSH(vm.ID) : "";
if(config &&
config["system_config"] &&
config["system_config"]["allow_vnc_federation"] &&
config["system_config"]["allow_vnc_federation"] === 'no' &&
config["id_own_federation"] &&
config["zone_id"] &&
if(config &&
config["system_config"] &&
config["system_config"]["allow_vnc_federation"] &&
config["system_config"]["allow_vnc_federation"] === "no" &&
config["id_own_federation"] &&
config["zone_id"] &&
config["id_own_federation"] !== config["zone_id"])
{
actions = '';
actions = "";
}
return "<div style='display: flex; align-items: end; gap:5px'>"+actions+"</div>";
@ -236,38 +238,38 @@ define(function(require) {
function _bindActionsToContext(context) {
$(context)
.off("click", '.w-file')
.on("click", '.w-file', function(evt) {
.off("click", ".w-file")
.on("click", ".w-file", function(evt) {
evt.preventDefault();
_callSaveWFile($(this).data());
evt.stopPropagation();
})
.off("click", '.save-rdp')
.on("click", '.save-rdp', function(evt) {
.off("click", ".save-rdp")
.on("click", ".save-rdp", function(evt) {
evt.preventDefault();
_callSaveRDP($(this).data());
evt.stopPropagation();
})
.off("click", '.rdp')
.off("click", ".rdp")
.on("click", ".rdp", function(evt) {
evt.preventDefault();
_callGuacRDP($(this).data());
evt.stopPropagation();
})
.off("click", '.ssh')
.off("click", ".ssh")
.on("click", ".ssh", function(evt) {
evt.preventDefault();
_callGuacSSH($(this).data());
evt.stopPropagation();
})
.off("click", '.spice')
.on("click", '.spice', function(evt) {
.off("click", ".spice")
.on("click", ".spice", function(evt) {
evt.preventDefault();
_callSpice($(this).data());
evt.stopPropagation();
})
.off("click", '.vnc')
.on("click", '.vnc', function(evt) {
.off("click", ".vnc")
.on("click", ".vnc", function(evt) {
evt.preventDefault();
var data = $(this).data();
@ -277,17 +279,17 @@ define(function(require) {
success: function(response) {
FireedgeValidator.validateFireedgeToken(
function() {
OpenNebulaVM.isVMRCSupported(response) ? _callVMRC(data) : _callGuacVNC(data)
OpenNebulaVM.isVMRCSupported(response) ? _callVMRC(data) : _callGuacVNC(data);
},
function() {
_callVNC(data)
_callVNC(data);
}
);
}
});
evt.stopPropagation();
})
});
}
/**

View File

@ -19,30 +19,29 @@ define(function(require) {
DEPENDENCIES
*/
require('datatables.net');
require('datatables.foundation');
var LabelsUtils = require('utils/labels/utils');
var Locale = require('utils/locale');
var Notifier = require('utils/notifier');
var OpenNebula = require('opennebula');
var Sunstone = require('sunstone');
var SunstoneConfig = require('sunstone-config');
var Tips = require('utils/tips');
var UtilsFoundation = require("utils/foundation/utils");
require("datatables.net");
require("datatables.foundation");
var LabelsUtils = require("utils/labels/utils");
var Locale = require("utils/locale");
var Notifier = require("utils/notifier");
var OpenNebula = require("opennebula");
var Sunstone = require("sunstone");
var SunstoneConfig = require("sunstone-config");
var Tips = require("utils/tips");
/*
TEMPLATES
*/
var TemplateEmptyTable = require('hbs!./tab-datatable/empty-table');
var TemplateDataTableHTML = require('hbs!./tab-datatable/table');
var TemplateSearchInputHTML = require('hbs!./tab-datatable/search-input');
var TemplateEmptyTable = require("hbs!./tab-datatable/empty-table");
var TemplateDataTableHTML = require("hbs!./tab-datatable/table");
var TemplateSearchInputHTML = require("hbs!./tab-datatable/search-input");
/*
CONSTANTS
*/
var SPINNER = '<img src="images/ajax-loader.gif" alt="retrieving" class="loading_img"/>';
var SPINNER = "<img src=\"images/ajax-loader.gif\" alt=\"retrieving\" class=\"loading_img\"/>";
/*
GLOBAL INITIALIZATION
@ -53,7 +52,7 @@ define(function(require) {
dom:
"t"+
"<'row'<'small-6 columns'li><'small-6 columns'p>>",
renderer: 'foundation',
renderer: "foundation",
autoWidth: false,
language: {
"url": "../locale/languages/" + datatable_lang,
@ -123,7 +122,7 @@ define(function(require) {
});
if (that.selectOptions.starred_icon == undefined) {
that.selectOptions.starred_icon = '<i class="fas fa-star fa-fw"></i>';
that.selectOptions.starred_icon = "<i class=\"fas fa-star fa-fw\"></i>";
}
}
@ -133,42 +132,42 @@ define(function(require) {
}
that.dataTableHTML = TemplateDataTableHTML({
'dataTableId': this.dataTableId,
'columns': this.columns,
'conf': this.conf,
'selectOptions': this.selectOptions});
"dataTableId": this.dataTableId,
"columns": this.columns,
"conf": this.conf,
"selectOptions": this.selectOptions});
that.searchInputHTML = TemplateSearchInputHTML({
'dataTableSearchId': this.dataTableId + 'Search',
'searchDropdownHTML': this.conf.searchDropdownHTML
"dataTableSearchId": this.dataTableId + "Search",
"searchDropdownHTML": this.conf.searchDropdownHTML
});
return that;
}
TabDatatable.prototype = {
'initialize': _initialize,
'initCheckAllBoxes': _initCheckAllBoxes,
'tableCheckboxesListener': _tableCheckboxesListener,
'onlyOneCheckboxListener': _onlyOneCheckboxListener,
'infoListener': _infoListener,
'updateElement': _updateElement,
'elements': _elements,
'updateView': _updateView,
'getElementData': _getElementData,
'waitingNodes': _waitingNodes,
'recountCheckboxes': _recountCheckboxes,
'filter': _filter,
'resetResourceTableSelect': _resetResourceTableSelect,
'refreshResourceTableSelect': _refreshResourceTableSelect,
'selectResourceTableSelect': _selectResourceTableSelect,
'retrieveResourceTableSelect': _retrieveResourceTableSelect,
'idInput': _idInput,
'initSelectResourceTableSelect': _initSelectResourceTableSelect,
'updateFn': _updateFn,
'list': _list,
'clearLabelsFilter': _clearLabelsFilter,
'getLabelsFilter': _getLabelsFilter
"initialize": _initialize,
"initCheckAllBoxes": _initCheckAllBoxes,
"tableCheckboxesListener": _tableCheckboxesListener,
"onlyOneCheckboxListener": _onlyOneCheckboxListener,
"infoListener": _infoListener,
"updateElement": _updateElement,
"elements": _elements,
"updateView": _updateView,
"getElementData": _getElementData,
"waitingNodes": _waitingNodes,
"recountCheckboxes": _recountCheckboxes,
"filter": _filter,
"resetResourceTableSelect": _resetResourceTableSelect,
"refreshResourceTableSelect": _refreshResourceTableSelect,
"selectResourceTableSelect": _selectResourceTableSelect,
"retrieveResourceTableSelect": _retrieveResourceTableSelect,
"idInput": _idInput,
"initSelectResourceTableSelect": _initSelectResourceTableSelect,
"updateFn": _updateFn,
"list": _list,
"clearLabelsFilter": _clearLabelsFilter,
"getLabelsFilter": _getLabelsFilter
};
return TabDatatable;
@ -187,37 +186,36 @@ define(function(require) {
this.initSelectResourceTableSelect();
} else {
this.dataTableOptions.pageLength = parseInt(config['user_config']['page_length']);
this.dataTableOptions.pageLength = parseInt(config["user_config"]["page_length"]);
}
this.dataTable = $('#' + this.dataTableId).dataTable(this.dataTableOptions);
this.dataTable = $("#" + this.dataTableId).dataTable(this.dataTableOptions);
// Remember page length only for non selectable datatables
if (!this.conf.select) {
this.dataTable.on( 'length.dt', function ( e, settings, len ) {
if (config['user_config']['page_length'] != len){
config['user_config']['page_length'] = len;
var sunstone_setting = {'TABLE_DEFAULT_PAGE_LENGTH': len};
Sunstone.runAction("User.append_sunstone_setting", config['user_id'], sunstone_setting);
this.dataTable.on( "length.dt", function ( e, settings, len ) {
if (config["user_config"]["page_length"] != len){
config["user_config"]["page_length"] = len;
var sunstone_setting = {"TABLE_DEFAULT_PAGE_LENGTH": len};
Sunstone.runAction("User.append_sunstone_setting", config["user_id"], sunstone_setting);
}
});
}
$('#' + this.dataTableId + 'Search').on('input', function() {
$("#" + this.dataTableId + "Search").on("input", function() {
that.dataTable.fnFilter($(this).val());
UtilsFoundation.update(null);
return false;
});
if(that.conf.searchDropdownHTML != undefined){
var context = $('#' + this.dataTableId + 'Search-wrapper');
var context = $("#" + this.dataTableId + "Search-wrapper");
if (that.setupSearch != undefined){
that.setupSearch(context);
} else {
_setupSearch(that, context);
}
$("a.advanced-search-clear", context).on('click', function(){
$("a.advanced-search-clear", context).on("click", function(){
$("input,select", context).val("").trigger("input");
that.clearLabelsFilter();
@ -232,24 +230,24 @@ define(function(require) {
}
});
$("button.advanced-search", context).on('click', function(){
$('#' + that.dataTableId + 'Search-dropdown', context).foundation('close');
$("button.advanced-search", context).on("click", function(){
$("#" + that.dataTableId + "Search-dropdown", context).foundation("close");
that.dataTable.fnDraw(true);
return false;
});
$("#"+ this.dataTableId +"Search-selectTYPE", context).on('change', function(){
that.dataTable.fnDraw(true);
$("#"+ this.dataTableId +"Search-selectTYPE", context).on("change", function(){
that.dataTable.fnDraw(true);
return false;
});
}
this.dataTable.on('draw.dt', function() {
this.dataTable.on("draw.dt", function() {
that.recountCheckboxes();
});
if (this.selectOptions && this.selectOptions.id_index) {
this.dataTable.fnSort([[this.selectOptions.id_index, config['user_config']['table_order']]]);
this.dataTable.fnSort([[this.selectOptions.id_index, config["user_config"]["table_order"]]]);
} else {
this.dataTable.fnSort([[1, SunstoneConfig.tableOrder]]);
}
@ -290,13 +288,13 @@ define(function(require) {
}
}
Foundation.reflow($('#' + this.dataTableId + 'Search-dropdown'), 'dropdown');
Foundation.reflow($("#" + this.dataTableId + "Search-dropdown"), "dropdown");
// For some reason the dropdown forces horizontal and vertical scrollbars,
// and breaks the full-screen modal positioning (VNC). It gets fixed once
// the dropdown is shown+hidden, so we force it now
$('#' + this.dataTableId + 'Search-wrapper button.search-dropdown').click();
$('#' + this.dataTableId + 'Search-wrapper button.search-dropdown').click();
$("#" + this.dataTableId + "Search-wrapper button.search-dropdown").click();
$("#" + this.dataTableId + "Search-wrapper button.search-dropdown").click();
}
@ -323,7 +321,7 @@ define(function(require) {
that.searchOps[name] = op;
});
$("[search-field]", context).on('input change', function(){
$("[search-field]", context).on("input change", function(){
var name = $(this).attr("search-field");
if($(this).attr("type") == "date"){
@ -339,7 +337,7 @@ define(function(require) {
}
});
that.dataTable.on('search.dt', function() {
that.dataTable.on("search.dt", function() {
var empty = true;
for(var i=0; i < that.searchFields.length; i++){
@ -433,20 +431,20 @@ define(function(require) {
//Shows run a custom action when clicking on rows.
function _infoListener(info_action) {
var that = this;
this.dataTable.on("click", 'tbody tr', function(e) {
if ($(e.target).is('input') || $(e.target).is('select') || $(e.target).is('option')) {
this.dataTable.on("click", "tbody tr", function(e) {
if ($(e.target).is("input") || $(e.target).is("select") || $(e.target).is("option")) {
return true;
}
if (info_action) {
//If ctrl is hold down, make check_box click
if (e.ctrlKey || e.metaKey || $(e.target).is('input')) {
$('.check_item', this).trigger('click');
if (e.ctrlKey || e.metaKey || $(e.target).is("input")) {
$(".check_item", this).trigger("click");
} else {
info_action(that, this);
}
} else {
$('.check_item', this).trigger('click');
$(".check_item", this).trigger("click");
}
return true;
@ -457,14 +455,14 @@ define(function(require) {
//check and uncheck all the checkboxes of its elements.
function _initCheckAllBoxes() {
var that = this;
this.dataTable.on("change", '.check_all', function() {
var table = $(this).closest('.dataTables_wrapper');
this.dataTable.on("change", ".check_all", function() {
var table = $(this).closest(".dataTables_wrapper");
if ($(this).is(":checked")) { //check all
$('tbody input.check_item', table).prop('checked', true).change();
$('td', table).addClass('markrowchecked');
$("tbody input.check_item", table).prop("checked", true).change();
$("td", table).addClass("markrowchecked");
} else { //uncheck all
$('tbody input.check_item', table).prop('checked', false).change();
$('td', table).removeClass('markrowchecked');
$("tbody input.check_item", table).prop("checked", false).change();
$("td", table).removeClass("markrowchecked");
};
that.recountCheckboxes();
@ -474,61 +472,61 @@ define(function(require) {
//Handle the activation of action buttons and the check_all box
//when elements in a datatable are modified.
function _recountCheckboxes() {
var table = $('tbody', this.dataTable);
var table = $("tbody", this.dataTable);
var context;
if (this.conf.customTabContext) {
context = this.conf.customTabContext;
} else {
context = table.parents('.tab');
if ($(".sunstone-info", context).is(':visible')) {
context = table.parents(".tab");
if ($(".sunstone-info", context).is(":visible")) {
return;
}
}
var nodes = $('tr', table); //visible nodes
var nodes = $("tr", table); //visible nodes
var total_length = nodes.length;
var checked_length = $('input.check_item:checked', nodes).length;
var checked_length = $("input.check_item:checked", nodes).length;
if (checked_length) { //at least 1 element checked
//enable action buttons
$('.top_button, .list_button', context).prop('disabled', false);
$(".top_button, .list_button", context).prop("disabled", false);
//enable checkall box
if (total_length == checked_length) {
$('.check_all', this.dataTable).prop('checked', true);
$(".check_all", this.dataTable).prop("checked", true);
} else {
$('.check_all', this.dataTable).prop('checked', false);
$(".check_all", this.dataTable).prop("checked", false);
};
} else { //no elements cheked
//disable action buttons, uncheck checkAll
$('.check_all', this.dataTable).prop('checked', false);
$('.top_button, .list_button', context).prop('disabled', true).attr('disabled', 'disabled');
$(".check_all", this.dataTable).prop("checked", false);
$(".top_button, .list_button", context).prop("disabled", true).attr("disabled", "disabled");
};
//any case the create dialog buttons should always be enabled.
$('.create_dialog_button', context).prop('disabled', false);
$('.alwaysActive', context).prop('disabled', false);
$(".create_dialog_button", context).prop("disabled", false);
$(".alwaysActive", context).prop("disabled", false);
}
//Init action buttons and checkboxes listeners
function _tableCheckboxesListener() {
//Initialization - disable all buttons
var context = this.conf.customTabContext || this.dataTable.parents('.tab');
var context = this.conf.customTabContext || this.dataTable.parents(".tab");
$('.last_action_button', context).prop('disabled', true);
$('.top_button, .list_button', context).prop('disabled', true);
$(".last_action_button", context).prop("disabled", true);
$(".top_button, .list_button", context).prop("disabled", true);
//These are always enabled
$('.create_dialog_button', context).prop('disabled', false);
$('.alwaysActive', context).prop('disabled', false);
$(".create_dialog_button", context).prop("disabled", false);
$(".alwaysActive", context).prop("disabled", false);
//listen to changes in the visible inputs
var that = this;
this.dataTable.on("change", 'tbody input.check_item', function() {
this.dataTable.on("change", "tbody input.check_item", function() {
if ($(this).is(":checked")) {
$(this).parents('tr').children().addClass('markrowchecked');
$(this).parents("tr").children().addClass("markrowchecked");
} else {
$(this).parents('tr').children().removeClass('markrowchecked');
$(this).parents("tr").children().removeClass("markrowchecked");
}
that.recountCheckboxes();
@ -541,12 +539,12 @@ define(function(require) {
function _onlyOneCheckboxListener() {
var that = this;
this.dataTable.on("change", 'tbody input.check_item', function() {
var checked = $(this).is(':checked');
$('td', that.dataTable).removeClass('markrowchecked');
$('input.check_item:checked', that.dataTable).prop('checked', false);
$("td", $(this).closest('tr')).addClass('markrowchecked')
$(this).prop('checked', checked);
this.dataTable.on("change", "tbody input.check_item", function() {
var checked = $(this).is(":checked");
$("td", that.dataTable).removeClass("markrowchecked");
$("input.check_item:checked", that.dataTable).prop("checked", false);
$("td", $(this).closest("tr")).addClass("markrowchecked");
$(this).prop("checked", checked);
});
}
@ -571,13 +569,13 @@ define(function(require) {
} catch(e){}
}
that.dataTable.DataTable().page.len(parseInt(config['user_config']['page_length']));
that.dataTable.DataTable().page.len(parseInt(config["user_config"]["page_length"]));
var row_id_index = this.dataTable.attr("row_id");
if (row_id_index != undefined) {
$.each($(that.dataTable.fnGetNodes()), function() {
if ($('td.markrow', this).length != 0) {
if ($("td.markrow", this).length != 0) {
var aData = that.dataTable.fnGetData(this);
selected_row_id = aData[row_id_index];
@ -587,11 +585,11 @@ define(function(require) {
}
$.each($(that.dataTable.fnGetNodes()), function() {
if ($('td.markrowchecked', this).length != 0) {
if (!isNaN($($('td', $(this))[1]).html())) {
checked_row_ids.push($($('td', $(this))[1]).html());
if ($("td.markrowchecked", this).length != 0) {
if (!isNaN($($("td", $(this))[1]).html())) {
checked_row_ids.push($($("td", $(this))[1]).html());
} else {
checked_row_ids.push($($('td', $(this))[0]).html());
checked_row_ids.push($($("td", $(this))[0]).html());
}
}
});
@ -652,23 +650,23 @@ define(function(require) {
var aData = that.dataTable.fnGetData(this);
if (aData[row_id_index] == selected_row_id) {
$('td', this)[0].click();
$("td", this)[0].click();
}
});
}
if (checked_row_ids.length != 0) {
$.each($(that.dataTable.fnGetNodes()), function() {
var current_id = $($('td', this)[1]).html();
var current_id = $($("td", this)[1]).html();
if (isNaN(current_id)) {
current_id = $($('td', this)[0]).html();
current_id = $($("td", this)[0]).html();
}
if (current_id) {
if ($.inArray(current_id, checked_row_ids) != -1) {
$('input.check_item:not(:checked)', this).first().click();
$('td', this).addClass('markrowchecked');
$("input.check_item:not(:checked)", this).first().click();
$("td", this).addClass("markrowchecked");
}
}
});
@ -676,18 +674,17 @@ define(function(require) {
if (that.labelsColumn &&
SunstoneConfig.isTabEnabled(that.tabId) &&
$("#" + that.tabId).is(':visible')) {
$("#" + that.tabId).is(":visible")) {
LabelsUtils.insertLabelsDropdown(that.tabId);
if (SunstoneConfig.isTabActionEnabled(that.tabId, that.resource+".menu_labels")){
LabelsUtils.insertLabelsMenu({'tabName': that.tabId});
LabelsUtils.insertLabelsMenu({"tabName": that.tabId});
}
}
if (that.postUpdateView) {
that.postUpdateView();
UtilsFoundation.update(null);
}
if(that.conf.searchDropdownHTML != undefined){
@ -699,7 +696,7 @@ define(function(require) {
if(dlist.length > 0){
that.searchSets[name].forEach(function(val){
st += '<option value="' + val + '"></option>';
st += "<option value=\"" + val + "\"></option>";
});
dlist.html(st);
@ -718,30 +715,28 @@ define(function(require) {
$.each(that.dataTable.fnGetData(), function(index, aData) {
if (aData[that.selectOptions.id_index] === elementId) {
var nodes = that.dataTable.fnGetNodes();
var checkId = '#' + that.resource.toLowerCase() + '_' + elementId;
var checkVal = $(checkId, nodes).prop('checked');
var checkId = "#" + that.resource.toLowerCase() + "_" + elementId;
var checkVal = $(checkId, nodes).prop("checked");
that.dataTable.fnUpdate(element, index, undefined, false);
if (checkVal) {
$(checkId, nodes).prop('checked', checkVal);
$(checkId, nodes).prop("checked", checkVal);
}
that.recountCheckboxes();
return false;
}
});
UtilsFoundation.update(null);
}
function _getElementData(id, resource_tag) {
// TODO If the element is not included in the visible rows of
// the table, it will not be included in the fnGetNodes response
var nodes = this.dataTable.fnGetNodes();
var tr = $('#' + resource_tag + '_' + id, nodes).closest('tr');
var tr = $("#" + resource_tag + "_" + id, nodes).closest("tr");
return this.dataTable.fnGetData(tr);
}
function _waitingNodes() {
$('tr input.check_item:visible', this.dataTable).replaceWith(SPINNER);
$("tr input.check_item:visible", this.dataTable).replaceWith(SPINNER);
}
//returns an array of ids of selected elements in a dataTable
@ -755,7 +750,7 @@ define(function(require) {
selected_nodes.push(Sunstone.rightInfoResourceId(tab));
} else {
//Which rows of the datatable are checked?
var nodes = $('tbody input.check_item:checked', this.dataTable);
var nodes = $("tbody input.check_item:checked", this.dataTable);
$.each(nodes, function() {
selected_nodes.push($(this).val());
});
@ -785,7 +780,7 @@ define(function(require) {
function _initSelectResourceTableSelect() {
var that = this;
var section = $('#' + that.dataTableId + 'Container');
var section = $("#" + that.dataTableId + "Container");
if (that.selectOptions.id_index == undefined) {
that.selectOptions.id_index = 0;
@ -811,64 +806,64 @@ define(function(require) {
that.dataTableOptions.fnRowCallback = function(nRow, aData, iDisplayIndex, iDisplayIndexFull) {
var row_id = aData[that.selectOptions.id_index];
var ids = $('#selected_ids_row_' + that.dataTableId, section).data("ids");
var ids = $("#selected_ids_row_" + that.dataTableId, section).data("ids");
if (ids != undefined && ids[row_id]) {
$("td", nRow).addClass('markrowchecked');
$('input.check_item', nRow).prop('checked', true);
$("td", nRow).addClass("markrowchecked");
$("input.check_item", nRow).prop("checked", true);
} else {
$("td", nRow).removeClass('markrowchecked');
$('input.check_item', nRow).prop('checked', false);
$("td", nRow).removeClass("markrowchecked");
$("input.check_item", nRow).prop("checked", false);
}
};
} else {
that.dataTableOptions.fnRowCallback = function(nRow, aData, iDisplayIndex, iDisplayIndexFull) {
var row_id = aData[that.selectOptions.id_index];
var selected_id = $('#selected_resource_id_' + that.dataTableId, section).val();
var selected_id = $("#selected_resource_id_" + that.dataTableId, section).val();
if (row_id == selected_id) {
$("td", nRow).addClass('markrow');
$('input.check_item', nRow).prop('checked', true);
$("td", nRow).addClass("markrow");
$("input.check_item", nRow).prop("checked", true);
} else {
$("td", nRow).removeClass('markrow');
$('input.check_item', nRow).prop('checked', false);
$("td", nRow).removeClass("markrow");
$("input.check_item", nRow).prop("checked", false);
}
};
}
$('#refresh_button_' + that.dataTableId, section).off("click");
section.on('click', '#refresh_button_' + that.dataTableId, function() {
$("#refresh_button_" + that.dataTableId, section).off("click");
section.on("click", "#refresh_button_" + that.dataTableId, function() {
that.updateFn();
return false;
});
$('#' + that.dataTableId + '_search', section).on('input', function() {
$("#" + that.dataTableId + "_search", section).on("input", function() {
that.dataTable.fnFilter($(this).val());
return false;
})
});
if (that.selectOptions.read_only) {
$('#selected_ids_row_' + that.dataTableId, section).hide();
$("#selected_ids_row_" + that.dataTableId, section).hide();
} else if (that.selectOptions.multiple_choice) {
$('#selected_resource_' + that.dataTableId, section).hide();
$('#select_resource_' + that.dataTableId, section).hide();
$("#selected_resource_" + that.dataTableId, section).hide();
$("#select_resource_" + that.dataTableId, section).hide();
$('#selected_resource_multiple_' + that.dataTableId, section).hide();
$('#select_resource_multiple_' + that.dataTableId, section).show();
$("#selected_resource_multiple_" + that.dataTableId, section).hide();
$("#select_resource_multiple_" + that.dataTableId, section).show();
} else {
$('#selected_resource_' + that.dataTableId, section).hide();
$('#select_resource_' + that.dataTableId, section).show();
$("#selected_resource_" + that.dataTableId, section).hide();
$("#select_resource_" + that.dataTableId, section).show();
$('#selected_resource_multiple_' + that.dataTableId, section).hide();
$('#select_resource_multiple_' + that.dataTableId, section).hide();
$("#selected_resource_multiple_" + that.dataTableId, section).hide();
$("#select_resource_multiple_" + that.dataTableId, section).hide();
}
$('#selected_resource_name_' + that.dataTableId, section).hide();
$("#selected_resource_name_" + that.dataTableId, section).hide();
$('#selected_ids_row_' + that.dataTableId, section).data("options", that.selectOptions);
$("#selected_ids_row_" + that.dataTableId, section).data("options", that.selectOptions);
if (that.selectOptions.multiple_choice) {
$('#selected_ids_row_' + that.dataTableId, section).data("ids", {});
$("#selected_ids_row_" + that.dataTableId, section).data("ids", {});
function row_click(row, aData) {
that.dataTable.unbind("draw");
@ -876,18 +871,18 @@ define(function(require) {
var row_id = aData[that.selectOptions.id_index];
var row_name = aData[that.selectOptions.name_index];
var ids = $('#selected_ids_row_' + that.dataTableId, section).data("ids");
var ids = $("#selected_ids_row_" + that.dataTableId, section).data("ids");
if (ids[row_id]) {
delete ids[row_id];
// Happens if row is not yet rendered (i.e. higher unvisited page)
if (row != undefined) {
$("td", row).removeClass('markrowchecked');
$('input.check_item', row).prop('checked', false);
$("td", row).removeClass("markrowchecked");
$("input.check_item", row).prop("checked", false);
}
$('#selected_ids_row_' + that.dataTableId + ' span[row_id="' + row_id + '"]', section).remove();
$("#selected_ids_row_" + that.dataTableId + " span[row_id=\"" + row_id + "\"]", section).remove();
that.selectOptions.unselect_callback(aData, that.selectOptions);
} else {
@ -895,13 +890,13 @@ define(function(require) {
// Happens if row is not yet rendered (i.e. higher unvisited page)
if (row != undefined) {
$("td", row).addClass('markrowchecked');
$('input.check_item', row).prop('checked', true);
$("td", row).addClass("markrowchecked");
$("input.check_item", row).prop("checked", true);
}
var attr = {row_id:row_id, class:"radius label"};
var span = $("<span/>",attr).text(row_name);
$('#selected_ids_row_' + that.dataTableId, section).append(span);
$("#selected_ids_row_" + that.dataTableId, section).append(span);
if(that.selectOptions.click && typeof that.selectOptions.click === "function"){
span.attr("title",Locale.tr("just click if you want to delete the resource"));
span.append($("<i/>",{class: "fas fa-times"}).css({"margin-left":"5px"}));
@ -912,17 +907,17 @@ define(function(require) {
}
if ($.isEmptyObject(ids)) {
$('#selected_resource_multiple_' + that.dataTableId, section).hide();
$('#select_resource_multiple_' + that.dataTableId, section).show();
$("#selected_resource_multiple_" + that.dataTableId, section).hide();
$("#select_resource_multiple_" + that.dataTableId, section).show();
} else {
$('#selected_resource_multiple_' + that.dataTableId, section).show();
$('#select_resource_multiple_' + that.dataTableId, section).hide();
$("#selected_resource_multiple_" + that.dataTableId, section).show();
$("#select_resource_multiple_" + that.dataTableId, section).hide();
}
return true;
};
$('#' + that.dataTableId + ' tbody', section).on("click", "tr", function() {
$("#" + that.dataTableId + " tbody", section).on("click", "tr", function() {
var aData = that.dataTable.fnGetData(this);
if(aData != undefined){
@ -930,8 +925,8 @@ define(function(require) {
}
});
$(section).on("click", '#selected_ids_row_' + that.dataTableId + ' span.fa.fa-times', function() {
var row_id = $(this).parent("span").attr('row_id');
$(section).on("click", "#selected_ids_row_" + that.dataTableId + " span.fa.fa-times", function() {
var row_id = $(this).parent("span").attr("row_id");
var found = false;
@ -946,43 +941,43 @@ define(function(require) {
});
if (!found) {
var ids = $('#selected_ids_row_' + that.dataTableId, section).data("ids");
var ids = $("#selected_ids_row_" + that.dataTableId, section).data("ids");
delete ids[row_id];
$('#selected_ids_row_' + that.dataTableId + ' span[row_id="' + row_id + '"]', section).remove();
$("#selected_ids_row_" + that.dataTableId + " span[row_id=\"" + row_id + "\"]", section).remove();
if ($.isEmptyObject(ids)) {
$('#selected_resource_multiple_' + that.dataTableId, section).hide();
$('#select_resource_multiple_' + that.dataTableId, section).show();
$("#selected_resource_multiple_" + that.dataTableId, section).hide();
$("#select_resource_multiple_" + that.dataTableId, section).show();
} else {
$('#selected_resource_multiple_' + that.dataTableId, section).show();
$('#select_resource_multiple_' + that.dataTableId, section).hide();
$("#selected_resource_multiple_" + that.dataTableId, section).show();
$("#select_resource_multiple_" + that.dataTableId, section).hide();
}
}
that.selectOptions.unselect_callback(aData, that.selectOptions);
});
} else {
$('#' + that.dataTableId + ' tbody', section).delegate("tr", "click", function(e) {
$("#" + that.dataTableId + " tbody", section).delegate("tr", "click", function(e) {
that.dataTable.unbind("draw");
var wasChecked = $("td.markrow", this).hasClass("markrow");
var aData = that.dataTable.fnGetData(this);
var check = aData != undefined && !wasChecked;
$("td", that.dataTable).removeClass('markrow');
$("td", this).toggleClass('markrow', check);
$('tbody input.check_item', that.dataTable).prop('checked', check);
$("td", that.dataTable).removeClass("markrow");
$("td", this).toggleClass("markrow", check);
$("tbody input.check_item", that.dataTable).prop("checked", check);
$('#selected_resource_' + that.dataTableId, section).toggle(check);
$('#select_resource_' + that.dataTableId, section).toggle(!check);
$("#selected_resource_" + that.dataTableId, section).toggle(check);
$("#select_resource_" + that.dataTableId, section).toggle(!check);
$('#selected_resource_id_' + that.dataTableId, section)
.val(function() { return check ? aData[that.selectOptions.id_index] : "" }).trigger("change");
$('#selected_resource_name_' + that.dataTableId, section)
.text(function() { return check ? aData[that.selectOptions.name_index] : "" }).trigger("change");
$("#selected_resource_id_" + that.dataTableId, section)
.val(function() { return check ? aData[that.selectOptions.id_index] : ""; }).trigger("change");
$("#selected_resource_name_" + that.dataTableId, section)
.text(function() { return check ? aData[that.selectOptions.name_index] : ""; }).trigger("change");
$('#selected_resource_name_' + that.dataTableId, section).toggle(check);
$("#selected_resource_name_" + that.dataTableId, section).toggle(check);
$('#selected_resource_id_' + that.dataTableId, section).removeData("pending_select");
$("#selected_resource_id_" + that.dataTableId, section).removeData("pending_select");
var callback = check ? "select_callback" : "unselect_callback";
that.selectOptions[callback](aData, that.selectOptions);
@ -995,32 +990,32 @@ define(function(require) {
function _resetResourceTableSelect() {
var that = this;
var section = $('#' + that.dataTableId + 'Container');
var section = $("#" + that.dataTableId + "Container");
// TODO: do for multiple_choice
// TODO: works for more than one page?
$("td.markrow", that.dataTable).removeClass('markrow');
$('tbody input.check_item', that.dataTable).prop('checked', false);
$("td.markrow", that.dataTable).removeClass("markrow");
$("tbody input.check_item", that.dataTable).prop("checked", false);
$('#' + that.dataTableId + '_search', section).val("").trigger("input");
$('#selected_resource_id_' + that.dataTableId, section).val("").trigger("change");
$('#selected_resource_name_' + that.dataTableId, section).text("").trigger("change").hide();
$('#refresh_button_' + that.dataTableId).click();
$("#" + that.dataTableId + "_search", section).val("").trigger("input");
$("#selected_resource_id_" + that.dataTableId, section).val("").trigger("change");
$("#selected_resource_name_" + that.dataTableId, section).text("").trigger("change").hide();
$("#refresh_button_" + that.dataTableId).click();
$('#selected_resource_' + that.dataTableId, section).hide();
$('#select_resource_' + that.dataTableId, section).show();
$("#selected_resource_" + that.dataTableId, section).hide();
$("#select_resource_" + that.dataTableId, section).show();
}
// Returns an ID, or an array of IDs for that.selectOptions.multiple_choice
function _retrieveResourceTableSelect() {
var that = this;
var section = $('#' + that.dataTableId + 'Container');
var section = $("#" + that.dataTableId + "Container");
if (that.selectOptions.multiple_choice) {
var ids = $('#selected_ids_row_' + that.dataTableId, section).data("ids");
var ids = $("#selected_ids_row_" + that.dataTableId, section).data("ids");
var arr = [];
@ -1030,7 +1025,7 @@ define(function(require) {
return arr;
} else {
return $('#selected_resource_id_' + that.dataTableId, section).val();
return $("#selected_resource_id_" + that.dataTableId, section).val();
}
}
@ -1041,20 +1036,20 @@ define(function(require) {
*/
function _idInput() {
var that = this;
var section = $('#' + that.dataTableId + 'Container');
var section = $("#" + that.dataTableId + "Container");
if (that.selectOptions.multiple_choice) {
return $('#selected_ids_row_' + that.dataTableId, section);
return $("#selected_ids_row_" + that.dataTableId, section);
} else {
return $('#selected_resource_id_' + that.dataTableId, section);
return $("#selected_resource_id_" + that.dataTableId, section);
}
}
// Clicks the refresh button
function _refreshResourceTableSelect() {
var that = this;
var section = $('#' + that.dataTableId + 'Container');
$('#refresh_button_' + that.dataTableId, section).click();
var section = $("#" + that.dataTableId + "Container");
$("#refresh_button_" + that.dataTableId, section).click();
}
/**
@ -1067,14 +1062,14 @@ define(function(require) {
function _selectResourceTableSelect(selectedResources) {
var that = this;
var section = $('#' + that.dataTableId + 'Container');
var section = $("#" + that.dataTableId + "Container");
if (that && that.selectOptions && that.selectOptions.multiple_choice) {
that.refreshResourceTableSelect(section, that.dataTableId);
var data_ids = {};
$('#selected_ids_row_' + that.dataTableId + ' span[row_id]', section).remove();
$("#selected_ids_row_" + that.dataTableId + " span[row_id]", section).remove();
if (selectedResources.ids == undefined) {
selectedResources.ids = [];
@ -1101,26 +1096,26 @@ define(function(require) {
span.off("click").on("click", that.selectOptions.click);
}
$('#selected_ids_row_' + that.dataTableId, section).append(span);
$("#selected_ids_row_" + that.dataTableId, section).append(span);
});
$('#selected_ids_row_' + that.dataTableId, section).data("ids", data_ids);
$("#selected_ids_row_" + that.dataTableId, section).data("ids", data_ids);
if ($.isEmptyObject(data_ids)) {
$('#selected_resource_multiple_' + that.dataTableId, section).hide();
$('#select_resource_multiple_' + that.dataTableId, section).show();
$("#selected_resource_multiple_" + that.dataTableId, section).hide();
$("#select_resource_multiple_" + that.dataTableId, section).show();
} else {
$('#selected_resource_multiple_' + that.dataTableId, section).show();
$('#select_resource_multiple_' + that.dataTableId, section).hide();
$("#selected_resource_multiple_" + that.dataTableId, section).show();
$("#select_resource_multiple_" + that.dataTableId, section).hide();
}
that.dataTable.fnDraw();
} else {
$("td.markrow", that.dataTable).removeClass('markrow');
$('tbody input.check_item', that.dataTable).prop('checked', false);
$("td.markrow", that.dataTable).removeClass("markrow");
$("tbody input.check_item", that.dataTable).prop("checked", false);
$('#selected_resource_' + that.dataTableId, section).show();
$('#select_resource_' + that.dataTableId, section).hide();
$("#selected_resource_" + that.dataTableId, section).show();
$("#select_resource_" + that.dataTableId, section).hide();
var row_id = undefined;
var row_name = "";
@ -1148,11 +1143,11 @@ define(function(require) {
}
if (row_id !== undefined) {
$('#selected_resource_id_' + that.dataTableId, section).val(row_id).trigger("change");
$("#selected_resource_id_" + that.dataTableId, section).val(row_id).trigger("change");
}
$('#selected_resource_name_' + that.dataTableId, section).text(row_name).trigger("change");
$('#selected_resource_name_' + that.dataTableId, section).show();
$("#selected_resource_name_" + that.dataTableId, section).text(row_name).trigger("change");
$("#selected_resource_name_" + that.dataTableId, section).show();
that.refreshResourceTableSelect(section, that.dataTableId);
}
@ -1187,7 +1182,7 @@ define(function(require) {
if (that.selectOptions.starred_ids != undefined){
if (that.selectOptions.starred_ids_map[this[that.xmlRoot].ID]){
elementArray[that.selectOptions.name_index] =
(that.selectOptions.starred_icon + ' ' +
(that.selectOptions.starred_icon + " " +
elementArray[that.selectOptions.name_index]);
} else {
elementArray[that.selectOptions.name_index] =
@ -1200,21 +1195,21 @@ define(function(require) {
delete fixed_ids_map[this[that.xmlRoot].ID];
}
});
that.updateView(null, list_array, true);
var section = $('#' + that.dataTableId + 'Container');
var selectedResources = $('#selected_resource_id_' + that.dataTableId, section).data("pending_select");
var section = $("#" + that.dataTableId + "Container");
var selectedResources = $("#selected_resource_id_" + that.dataTableId, section).data("pending_select");
if (selectedResources != undefined){
$('#selected_resource_id_' + that.dataTableId, section).removeData("pending_select");
$("#selected_resource_id_" + that.dataTableId, section).removeData("pending_select");
that.selectResourceTableSelect(selectedResources);
}
}
};
var error_func = function(request, error_json, container) {
success_func(request, []);
Notifier.onError(request, error_json, container);
}
};
var pool_filter = SunstoneConfig.isChangedFilter()? -4 : -2;
if (that.selectOptions.zone_id == undefined) {
OpenNebula[that.resource].list({
@ -1250,10 +1245,10 @@ define(function(require) {
function _clearLabelsFilter() {
LabelsUtils.clearLabelsFilter(this.dataTable, this.labelsColumn);
LabelsUtils.insertLabelsMenu({'tabName': this.tabId});
LabelsUtils.insertLabelsMenu({"tabName": this.tabId});
}
function _getLabelsFilter() {
return LabelsUtils.getLabelsFilter(this.dataTable);
}
})
});

View File

@ -280,6 +280,40 @@ select.mb_input_unit {
line-height: 1.4rem;
}
ul.dropdown-menu-css{
position: relative;
margin: 0;
list-style: none;
& > .menu-hide{
display: none;
position: absolute;
background-color: $white;
padding: 5px;
-webkit-box-shadow: 5px 5px 10px 0px $black;
-moz-box-shadow: 5px 5px 10px 0px $black;
box-shadow: 5px 5px 10px 0px $black;
z-index: 999999;
& ul{
margin: 0;
list-style: none;
& > li{
display: inline-block;
}
}
}
& > li.menu-hide.upper{
top: 0px;
}
&:hover > li{
display: block;
}
}
@media screen and (min-width: 64em){
.medium-hide {
display: none !important;