diff --git a/src/sunstone/public/js/one-ui_views.js b/src/sunstone/public/js/one-ui_views.js
index fb67fc85b3..c2a2e9d53e 100644
--- a/src/sunstone/public/js/one-ui_views.js
+++ b/src/sunstone/public/js/one-ui_views.js
@@ -21,25 +21,28 @@
var dataTable_hosts=null;
//~ var dataTable_clusters=null;
-var dataTable_vMachines=null;
-var dataTable_vNetworks=null;
-var dataTable_users=null;
-var dataTable_images=null;
-var host_list_json = {};
-var cluster_list_json = {};
-var vmachine_list_json = {};
-var network_list_json = {};
-var user_list_json = {};
-var image_list_json = {};
-var hosts_select="";
-var clusters_select="";
-var vnetworks_select="";
-var images_select="";
+//~ var dataTable_vMachines=null;
+//~ var dataTable_vNetworks=null;
+//~ var dataTable_users=null;
+//~ var dataTable_images=null;
+//~ var host_list_json = {};
+//~ var cluster_list_json = {};
+//~ var vmachine_list_json = {};
+//~ var network_list_json = {};
+//~ var user_list_json = {};
+//~ var image_list_json = {};
+//~ var hosts_select="";
+//~ var clusters_select="";
+//~ var vnetworks_select="";
+//~ var images_select="";
var cookie = {};
var username = '';
var uid = '';
var spinner = '';
+
+
+
/*######################################################################
* DOCUMENT READY FUNCTIONS
* ###################################################################*/
@@ -229,12 +232,12 @@ function initDataTables(){
}
//Adds a listener to checks all the elements of a table
-function initCheckAllBoxes(){
+function initCheckAllBoxes(datatable){
//not showing nice in that position
//$('.check_all').button({ icons: {primary : "ui-icon-check" },
// text : true});
- $('.check_all').css({"border":"2px"});
- $('.check_all').click(function(){
+ $('.check_all',datatable).css({"border":"2px"});
+ $('.check_all',datatable).click(function(){
if ($(this).attr("checked")) {
$('tbody input:checkbox',
$(this).parents("table")).each(function(){
@@ -761,6 +764,9 @@ function actionButtonListener(){
});
}
+
+
+
function preloadTables(){
dataTable_hosts.fnClearTable();
addElement([
@@ -2180,17 +2186,14 @@ function setupTips(){
//Crawls the user dataTable for that. If such user is not found,
//we return the uid.
function getUserName(uid){
+ nodes = dataTable_users.fnGetData();
user = "uid "+uid;
- if (dataTable_users != null){
- nodes = dataTable_users.fnGetData();
- $.each(nodes,function(){
- if (uid == this[1]) {
- user = this[2];
- return false;
- }
- });
- };
-
+ $.each(nodes,function(){
+ if (uid == this[1]) {
+ user = this[2];
+ return false;
+ }
+ });
return user;
}
@@ -2556,13 +2559,13 @@ function emptyDashboard(){
$("#dashboard .value_td span").html(spinner);
}
-function updateDashboard(what){
+function updateDashboard(what,json_info){
db = $('#dashboard');
switch (what){
case "hosts":
- total_hosts=host_list_json.length;
+ total_hosts=json_info.length;
active_hosts=0;
- $.each(host_list_json,function(){
+ $.each(json_info,function(){
if (parseInt(this.HOST.STATE) < 3){
active_hosts++;}
});
@@ -2570,14 +2573,14 @@ function updateDashboard(what){
$('#active_hosts',db).html(active_hosts);
break;
case "clusters":
- total_clusters=cluster_list_json.length;
+ total_clusters=json_info.length;
$('#total_clusters',db).html(total_clusters);
break;
case "vms":
- total_vms=vmachine_list_json.length;
+ total_vms=json_info.length;
running_vms=0;
failed_vms=0;
- $.each(vmachine_list_json,function(){
+ $.each(json_info,function(){
vm_state = parseInt(this.VM.STATE);
if (vm_state == 3){
running_vms++;
@@ -2592,8 +2595,8 @@ function updateDashboard(what){
break;
case "vnets":
public_vnets=0;
- total_vnets=network_list_json.length;
- $.each(network_list_json,function(){
+ total_vnets=json_info.length;
+ $.each(json_info,function(){
if (parseInt(this.VNET.PUBLIC)){
public_vnets++;}
});
@@ -2601,13 +2604,13 @@ function updateDashboard(what){
$('#public_vnets',db).html(public_vnets);
break;
case "users":
- total_users=user_list_json.length;
+ total_users=json_info.length;
$('#total_users',db).html(total_users);
break;
case "images":
- total_images=image_list_json.length;
+ total_images=json_info.length;
public_images=0;
- $.each(image_list_json,function(){
+ $.each(json_info,function(){
if (parseInt(this.IMAGE.PUBLIC)){
public_images++;}
});
diff --git a/src/sunstone/public/js/plugins/hosts-tab.js b/src/sunstone/public/js/plugins/hosts-tab.js
new file mode 100644
index 0000000000..a1abcefe54
--- /dev/null
+++ b/src/sunstone/public/js/plugins/hosts-tab.js
@@ -0,0 +1,444 @@
+/* -------------------------------------------------------------------------- */
+/* Copyright 2002-2011, OpenNebula Project Leads (OpenNebula.org) */
+/* */
+/* 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. */
+/* -------------------------------------------------------------------------- */
+
+/*Host tab plugin*/
+
+var host_tab_content =
+'
" + msg;
+
+ $.jGrowl(msg, {theme: "jGrowl-notify-error", sticky: true });
+}
+
+// Returns an HTML string with the json keys and values in the form
+// key: value
+// It recursively explores objects, and flattens their contents in
+// the result.
+function prettyPrintJSON(template_json){
+ str = ""
+ for (field in template_json) {
+ if (typeof template_json[field] == 'object'){
+ str += prettyPrintJSON(template_json[field]) + '
';
+ } else {
+ str += '
'+field+'
'+template_json[field]+'
';
+ };
+ };
+ return str;
+}
+
+//Adds a listener to checks all the elements of a table
+function initCheckAllBoxes(datatable){
+ //not showing nice in that position
+ //$('.check_all').button({ icons: {primary : "ui-icon-check" },
+ // text : true});
+ $('.check_all',datatable).css({"border":"2px"});
+ $('.check_all',datatable).click(function(){
+ if ($(this).attr("checked")) {
+ $('tbody input:checkbox',
+ $(this).parents("table")).each(function(){
+ $(this).attr("checked","checked");
+ });
+
+ } else {
+ $('tbody input:checkbox',
+ $(this).parents("table")).each(function(){
+ $(this).removeAttr("checked");
+ }); }
+ });
+}
diff --git a/src/sunstone/public/js/sunstone.js b/src/sunstone/public/js/sunstone.js
new file mode 100644
index 0000000000..7c631040af
--- /dev/null
+++ b/src/sunstone/public/js/sunstone.js
@@ -0,0 +1,472 @@
+/* -------------------------------------------------------------------------- */
+/* Copyright 2002-2011, OpenNebula Project Leads (OpenNebula.org) */
+/* */
+/* 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. */
+/* -------------------------------------------------------------------------- */
+
+
+//TODOs: handle confirm and confirm with select dialogs
+
+var cookie = {};
+var username = '';
+var uid = '';
+var spinner = '';
+
+
+var Sunstone = {
+
+
+ "addAction" : function (name,action_obj) {
+ SunstoneCfg.config.actions[name] = action_obj;
+ },
+
+ "updateAction" : function(action,new_action) {
+
+ },
+
+ "removeAction" : function(action) {
+
+ },
+
+ "addMainTab" : function(tab_id,title_arg,content_arg) {
+ SunstoneCfg["tabs"][tab_id] = {title: title_arg,
+ content: content_arg};
+ },
+
+ "updateMainTab" : function(tab_id,new_content){
+
+ },
+
+ "removeMainTab" : function(tab_id) {
+
+ },
+
+ "runAction" : function(action, data_arg, extra_param){
+
+ var actions = Sunstone.actions;
+ if (!actions[action]){
+ notifyError("Action "+action+" not defined");
+ return;
+ }
+
+ var action_cfg = actions[action];
+
+ var call = action_cfg.run;
+ var callback = action_cfg.callback;
+ var err = action_cfg.callback;
+ var notify = action_cfg.notify;
+
+
+ //We ease the use of:
+ // * Create call
+ // * Confirm and confirm with select calls
+ // * Calls on multiple elements
+ // * Other calls
+ switch (actions[action].type){
+
+ case "create","single":
+ call({data:data_arg, success: callback,error:err});
+ break;
+ case "confirm":
+ tip = actions.tip;
+ //popup confirm dialog (action,tip).
+ break;
+ case "confirm_with_select":
+ tip = OpenNebula.Views.Actions[action].tip;
+ select = OpenNebula.Views.Actions[action].select;
+ //popup confirm dialog with select(action,tip,select)
+ break;
+ case "list":
+ call({success: callback, error:err});
+ break;
+ case "multiple":
+ //run on the list of nodes that come on the data
+ $.each(data_arg,function(){
+ if (extra_param){
+ call(this,callback,error)
+ } else {
+ call(this,extra_param,callback,error)
+ }
+ });
+ break;
+ default:
+ //we have supposedly altered an action and we want it to do
+ //something completely different
+ call(data,extra_param);
+ }
+
+ },
+
+ "runActionOnDatatableNodes": function(action,datatable){
+ if (dataTable != null){
+
+ //Which rows of the datatable are checked?
+ var nodes = $('input:checked',dataTable.fnGetNodes());
+ var data = [];
+ $.each(nodes,function(){
+ data.push($(this).val());
+ }
+ runAction(action,data);
+
+ } else {
+ notifyError("Unknown datatable");
+ };
+ }//meter coma y seguir aquĆ
+
+}
+
+var SunstoneCfg = {
+ "config" = {
+
+ "actions" : {
+
+ "VM.create" = {
+
+ },
+
+ "VM.deploy" = {
+
+ },
+
+ "VM.migrate" = {
+
+ },
+
+ "VM.livemigrate" = {
+
+ },
+
+ "VM.hold" = {
+
+ },
+
+ "VM.release" = {
+
+ },
+
+ "VM.suspend" = {
+
+ },
+
+ "VM.resume" = {
+
+ },
+
+ "VM.stop" = {
+
+ },
+
+ "VM.restart" = {
+
+ },
+
+ "VM.shutdown" = {
+
+ },
+
+ "VM.cancel" = {
+
+ },
+
+ "VM.delete" = {
+
+ },
+
+ "Network.publish" = {
+
+ },
+
+ "Network.unpublish" = {
+
+ },
+
+ "Network.delete" = {
+
+ },
+
+ "User.create" = {
+
+ },
+
+ "User.delete" = {
+
+ },
+
+ "Image.enable" = {
+
+ },
+
+ "Image.disable" = {
+
+ },
+
+ "Image.persistent" = {
+
+ },
+
+ "Image.nonpersistent" = {
+
+ },
+
+ "Image.publish" = {
+
+ },
+
+ "Image.unpublish" = {
+
+ },
+
+ "Image.delete" = {
+
+ }
+ },
+
+ "tabs" = {
+
+ },
+
+ "info_panels" = {
+
+ }
+
+ }
+
+}
+
+//plugins have done their jobs when we execute this
+$(document).ready(){
+ readCookie();
+ setLogin();
+ insertTabs();
+ insertButtons();
+
+
+ initListButtons();
+ setupCreateDialogs(); //listener for create
+ setupTips();
+
+ //action button listener! -> plugins deal with that
+
+
+ $('button').button();
+ $('div#select_helpers').hide();
+ emptyDashboard();
+
+ $(".ui-widget-overlay").live("click", function (){
+ $("div:ui-dialog:visible").dialog("close");
+ });
+
+ //Dashboard link listener
+ $("#dashboard_table h3 a").live("click", function (){
+ var tab = $(this).attr('href');
+ showTab(tab);
+ return false;
+ });
+
+ //Close select lists...
+ $('*:not(.action_list,.list_button)').click(function(){
+ $('.action_list:visible').hide();
+ });
+
+}
+
+
+//reads the cookie and places its info in the 'cookie' var
+function readCookie(){
+ $.each(document.cookie.split("; "), function(i,e){
+ var e_split = e.split("=");
+ var key = e_split[0];
+ var value = e_split[1];
+ cookie[key] = value;
+ });
+}
+
+//sets the user info in the top bar and creates a listner in the signout button
+function setLogin(){
+ username = cookie["one-user"];
+ uid = cookie["one-user_id"];
+
+ $("#user").html(username);
+ $("#logout").click(function(){
+ OpenNebula.Auth.logout({success:function(){
+ window.location.href = "/login";
+ }
+ });
+ return false;
+ });
+}
+
+
+function insertTabs(){
+ var tab_info;
+ for (tab in SunstoneCfg["tabs"]){
+ tab_info = SunstoneCfg["tabs"].tab;
+ $("div.inner_center").append('');
+ $('div#'+tab_info.tab_id).html(tab_info.content);
+
+ $('ul#navigation').append('