diff --git a/src/cloud/occi/lib/occi-server.rb b/src/cloud/occi/lib/occi-server.rb index 2eae976ee6..3c84e43d81 100755 --- a/src/cloud/occi/lib/occi-server.rb +++ b/src/cloud/occi/lib/occi-server.rb @@ -48,6 +48,8 @@ $: << RUBY_LIB_LOCATION+"/cloud" # For the Repository Manager require 'rubygems' require 'sinatra' require 'yaml' +require 'erb' +require 'tempfile' require 'OCCIServer' require 'CloudAuth' @@ -73,6 +75,7 @@ CloudServer.print_configuration(conf) ############################################################################## use Rack::Session::Pool, :key => 'occi' set :public, Proc.new { File.join(root, "ui/public") } +set :views, settings.root + '/ui/views' set :config, conf if CloudServer.is_port_open?(settings.config[:server], @@ -291,5 +294,16 @@ get '/ui' do if !authorized? return File.read(File.dirname(__FILE__)+'/ui/templates/login.html') end - return File.read(File.dirname(__FILE__)+'/ui/templates/index.html') + + erb :index + #return File.read(File.dirname(__FILE__)+'/ui/templates/index.html') +end + +post '/ui/upload' do + file = Tempfile.new('uploaded_image') + request.params['file'] = file.path #so we can re-use occi post_storage() + file.write(request.env['rack.input'].read) + #file.close # this would allow that file is garbage-collected + result,rc = @occi_server.post_storage(request) + treat_response(result,rc) end diff --git a/src/cloud/occi/lib/ui/public/css/application.css b/src/cloud/occi/lib/ui/public/css/application.css index 80ce873be6..e4934e76e9 100644 --- a/src/cloud/occi/lib/ui/public/css/application.css +++ b/src/cloud/occi/lib/ui/public/css/application.css @@ -170,7 +170,7 @@ fieldset div{ fieldset input, fieldset textarea{ - width:180px; + width:140px; /*border-top:1px solid #555; border-left:1px solid #555; border-bottom:1px solid #ccc; @@ -182,7 +182,7 @@ fieldset textarea{ } fieldset select{ - width:184px; + width:144px; /*border-top:1px solid #555; border-left:1px solid #555; border-bottom:1px solid #ccc; @@ -211,7 +211,7 @@ legend{ label{ float: left; - width:120px; + width:100px; padding:0 1em; text-align:left; } @@ -289,8 +289,9 @@ textarea:focus{ } .form_buttons { - margin-top:25px; - text-align:right; + margin-top:6px; + text-align:left; + margin-bottom:20px; } .add_remove_button { @@ -319,11 +320,13 @@ tr.odd td, tr.even td{ } tr.odd:hover{ - background-color: #E69138 !important; + background-color: #0098C3 !important; + color: white; } tr.even:hover{ - background-color: #E69138 !important; + color: white; + background-color: #0098C3 !important; } .show_hide label{ @@ -367,7 +370,7 @@ tr.even:hover{ margin: 20px; text-align: left; display: inline-block; - width:43%; + width:85%; vertical-align:top; overflow:auto; } @@ -551,7 +554,7 @@ ul.action_list li a{ } ul.action_list li a:hover{ - color:#E69138; + color:#0098C3; } @@ -567,4 +570,19 @@ ul.action_list li a:hover{ .ui-layout-resizer-open-hover, /* hover-color to 'resize' */ .ui-layout-resizer-dragging { background: #EEE; +} + +.dashboard_img { + padding-left:10px; + border:0; + height:40px; +} + +.dashboard_p { + color: #353735; + text-align:justify; +} + +.dashboard_p p{ + padding-top:5px; } \ No newline at end of file diff --git a/src/cloud/occi/lib/ui/public/css/layout.css b/src/cloud/occi/lib/ui/public/css/layout.css index 63630c8911..283bf1e7a6 100644 --- a/src/cloud/occi/lib/ui/public/css/layout.css +++ b/src/cloud/occi/lib/ui/public/css/layout.css @@ -93,7 +93,7 @@ body { font-weight: bold; } .sunstone-color { - color: #E69138; + color: #0098C3; } #logo-wrapper { @@ -140,12 +140,12 @@ background-image: -moz-linear-gradient( linear, left top, right top, - color-stop(0.95, #E69138), + color-stop(0.95, #0098C3), color-stop(1, rgb(53,55,53)) ); background-image: -moz-linear-gradient( left center, - #E69138 95%, + #0098C3 95%, rgb(53,55,53) 100% ); /* diff --git a/src/cloud/occi/lib/ui/public/css/login.css b/src/cloud/occi/lib/ui/public/css/login.css index 4843efacf9..e086897b3f 100644 --- a/src/cloud/occi/lib/ui/public/css/login.css +++ b/src/cloud/occi/lib/ui/public/css/login.css @@ -52,7 +52,7 @@ div#logo_sunstone { top: 80px; margin-left: auto; margin-right: auto; - background: url(../images/opennebula-sunstone-big.png) no-repeat center; + background: url(../images/opennebula-selfservice-big.png) no-repeat center; vertical-align: center; } diff --git a/src/cloud/occi/lib/ui/public/images/ajax-loader.gif b/src/cloud/occi/lib/ui/public/images/ajax-loader.gif index 6f0e2ddb68..cf69d7879b 100644 Binary files a/src/cloud/occi/lib/ui/public/images/ajax-loader.gif and b/src/cloud/occi/lib/ui/public/images/ajax-loader.gif differ diff --git a/src/cloud/occi/lib/ui/public/images/one-compute.png b/src/cloud/occi/lib/ui/public/images/one-compute.png new file mode 100644 index 0000000000..93cfa43614 Binary files /dev/null and b/src/cloud/occi/lib/ui/public/images/one-compute.png differ diff --git a/src/cloud/occi/lib/ui/public/images/one-network.png b/src/cloud/occi/lib/ui/public/images/one-network.png new file mode 100644 index 0000000000..a59f6334cd Binary files /dev/null and b/src/cloud/occi/lib/ui/public/images/one-network.png differ diff --git a/src/cloud/occi/lib/ui/public/images/one-storage.png b/src/cloud/occi/lib/ui/public/images/one-storage.png new file mode 100644 index 0000000000..5ec80f21c8 Binary files /dev/null and b/src/cloud/occi/lib/ui/public/images/one-storage.png differ diff --git a/src/cloud/occi/lib/ui/public/images/opennebula-selfservice-big.png b/src/cloud/occi/lib/ui/public/images/opennebula-selfservice-big.png new file mode 100644 index 0000000000..add8ed9d26 Binary files /dev/null and b/src/cloud/occi/lib/ui/public/images/opennebula-selfservice-big.png differ diff --git a/src/cloud/occi/lib/ui/public/images/opennebula-selfservice-small.png b/src/cloud/occi/lib/ui/public/images/opennebula-selfservice-small.png new file mode 100644 index 0000000000..d2fa63708f Binary files /dev/null and b/src/cloud/occi/lib/ui/public/images/opennebula-selfservice-small.png differ diff --git a/src/cloud/occi/lib/ui/public/images/opennebula-sunstone-big.png b/src/cloud/occi/lib/ui/public/images/opennebula-sunstone-big.png deleted file mode 100644 index 74b70be13d..0000000000 Binary files a/src/cloud/occi/lib/ui/public/images/opennebula-sunstone-big.png and /dev/null differ diff --git a/src/cloud/occi/lib/ui/public/images/opennebula-sunstone-small.png b/src/cloud/occi/lib/ui/public/images/opennebula-sunstone-small.png deleted file mode 100644 index 7b411542c2..0000000000 Binary files a/src/cloud/occi/lib/ui/public/images/opennebula-sunstone-small.png and /dev/null differ diff --git a/src/cloud/occi/lib/ui/public/images/pbar.gif b/src/cloud/occi/lib/ui/public/images/pbar.gif index b9d8856a73..a36f520314 100644 Binary files a/src/cloud/occi/lib/ui/public/images/pbar.gif and b/src/cloud/occi/lib/ui/public/images/pbar.gif differ diff --git a/src/cloud/occi/lib/ui/public/js/layout.js b/src/cloud/occi/lib/ui/public/js/layout.js index ab4f193001..71b0098548 100644 --- a/src/cloud/occi/lib/ui/public/js/layout.js +++ b/src/cloud/occi/lib/ui/public/js/layout.js @@ -18,12 +18,12 @@ var activeTab; var outerLayout, innerLayout; function hideDialog(){ - innerLayout.close("south"); + innerLayout.close("east"); } function popDialog(content){ $("#dialog").html(content); - innerLayout.open("south"); + innerLayout.open("east"); } function popDialogLoading(){ @@ -92,15 +92,16 @@ $(document).ready(function () { , west__resizable: false }); - var factor = 0.6; - var dialog_height = Math.floor($(".outer-center").height()*factor); + var factor = 0.45; + var dialog_height = Math.floor($(".outer-center").width()*factor); innerLayout = $('div.outer-center').layout({ fxName: "slide" , initClosed: true , center__paneSelector: ".inner-center" - , south__paneSelector: ".inner-south" - , south__size: dialog_height + , east__paneSelector: ".inner-east" + , east__size: dialog_height + , east__minSize: 400 , spacing_open: 5 // ALL panes , spacing_closed: 5 // ALL panes }); diff --git a/src/cloud/occi/lib/ui/public/js/occi.js b/src/cloud/occi/lib/ui/public/js/occi.js index ab9a0897c9..2fe3c61ff2 100644 --- a/src/cloud/occi/lib/ui/public/js/occi.js +++ b/src/cloud/occi/lib/ui/public/js/occi.js @@ -14,7 +14,7 @@ /* limitations under the License. */ /* -------------------------------------------------------------------------- */ -//Simple recursion +//Convert json into the XML that OCCI server can understand function json2xml(element,root_key) { var xml = ""; if (!root_key) root_key="ROOT"; @@ -28,7 +28,7 @@ function json2xml(element,root_key) { //do not wrap arrays in root_key return xml; - } else + } else xml += json2xml(value,key); }); } else { //its a simple value. Base condition @@ -225,7 +225,9 @@ var OCCI = { dataType: "xml ONEjson", data: data, success: function(response){ - return callback ? callback(request, response) : null; + var res = {}; + res[resource] = response; + return callback ? callback(request, res) : null; }, error: function(response){ return callback_error ? @@ -310,9 +312,9 @@ var OCCI = { var callback = params.success; var callback_error = params.error; var id = params.data.id; - var body = json2xml(params.data.body,resource) + var body = json2xml(params.data.body,resource); - var request = OCCI.Helper.request(resource,method, [id, body]); + var request = OCCI.Helper.request(resource,method, id); $.ajax({ url: resource.toLowerCase() + "/" + id, @@ -428,35 +430,13 @@ var OCCI = { OCCI.Action.show(params,OCCI.Network.resource); }, "publish": function(params){ - params.data.body = { "public": "YES" } + params.data.body = { "PUBLIC": "YES" }; OCCI.Action.update(params,OCCI.Network.resource,"publish"); }, "unpublish": function(params){ - params.data.body = { "public": "NO" } - OCCI.Action.update(params,OpenNebula.Network.resource,"unpublish"); + params.data.body = { "PUBLIC": "NO" }; + OCCI.Action.update(params,OCCI.Network.resource,"unpublish"); }, -/* - "addleases" : function(params){ - var action_obj = params.data.extra_param; - OpenNebula.Action.simple_action(params, - OpenNebula.Network.resource, - "addleases", - action_obj); - }, - "rmleases" : function(params){ - var action_obj = params.data.extra_param; - OpenNebula.Action.simple_action(params, - OpenNebula.Network.resource, - "rmleases", - action_obj); - }, - "update": function(params){ - var action_obj = {"template_raw" : params.data.extra_param }; - OpenNebula.Action.simple_action(params, - OpenNebula.Network.resource, - "update", - action_obj); - },*/ }, "VM": { @@ -484,25 +464,27 @@ var OCCI = { }, "cancel": function(params){ params.data.body = { state : "CANCEL" }; - OCCI.Action.simple_action(params,OCCI.VM.resource,"cancel"); + OCCI.Action.update(params,OCCI.VM.resource,"cancel"); }, "suspend": function(params){ params.data.body = { state : "SUSPENDED" }; - OCCI.Action.simple_action(params,OCCI.VM.resource,"suspend"); + OCCI.Action.update(params,OCCI.VM.resource,"suspend"); }, "resume": function(params){ params.data.body = { state : "RESUME" }; - OCCI.Action.simple_action(params,OCCI.VM.resource,"resume"); + OCCI.Action.update(params,OCCI.VM.resource,"resume"); }, "done": function(params){ params.data.body = { state : "DONE" }; - OCCI.Action.simple_action(params,OCCI.VM.resource,"done"); - }, - "saveas": function(params){ - var action_obj = params.data.extra_param; - OCCI.Action.simple_action(params,OCCI.VM.resource, - "saveas",action_obj); + OCCI.Action.update(params,OCCI.VM.resource,"done"); }, + "saveas" : function(params){ + var obj = params.data.extra_param; + var disk_id = obj.disk_id; + var im_name = obj.image_name; + params.data.body = ''; + OCCI.Action.update(params,OCCI.VM.resource,"saveas"); + } /* "vnc" : function(params,startstop){ var callback = params.success; var callback_error = params.error; @@ -543,7 +525,26 @@ var OCCI = { "resource": "STORAGE", "create": function(params){ - OCCI.Action.create(params,OCCI.Image.resource); + var callback = params.success; + var callback_error = params.error; + var data = {occixml : json2xml(params.data,OCCI.Image.resource)}; + var request = OCCI.Helper.request(OCCI.Image.resource,"create", data); + + $.ajax({ + type: 'POST', + url: "storage", + data: data, + dataType: "xml ONEjson", + success: function(response){ + var res = {}; + res["STORAGE"] = response; + return callback ? callback(request, res) : null; + }, + error: function(response){ + return callback_error ? + callback_error(request, OCCI.Error(response)) : null; + } + }); }, "delete": function(params){ OCCI.Action.delete(params,OCCI.Image.resource); @@ -554,41 +555,22 @@ var OCCI = { "show": function(params){ OCCI.Action.show(params,OCCI.Image.resource); }, - "update": function(params){ - var action_obj = {"template_raw" : params.data.extra_param }; - OCCI.Action.simple_action(params, - OCCI.Image.resource, - "update", - action_obj); - }, - "fetch_template" : function(params){ - OCCI.Action.show(params,OCCI.Image.resource,"template"); - }, - "enable": function(params){ - OCCI.Action.simple_action(params,OCCI.Image.resource,"enable"); - }, - "disable": function(params){ - OCCI.Action.simple_action(params,OCCI.Image.resource,"disable"); - }, "publish": function(params){ - OCCI.Action.simple_action(params,OCCI.Image.resource,"publish"); + params.data.body = { "PUBLIC":"YES" }; + OCCI.Action.update(params,OCCI.Image.resource,"publish"); }, "unpublish": function(params){ - OCCI.Action.simple_action(params,OCCI.Image.resource,"unpublish"); + params.data.body = { "PUBLIC":"NO" }; + OCCI.Action.update(params,OCCI.Image.resource,"unpublish"); }, "persistent": function(params){ - OCCI.Action.simple_action(params,OCCI.Image.resource,"persistent"); + params.data.body = { "PERSISTENT":"YES" }; + OCCI.Action.update(params,OCCI.Image.resource,"persistent"); }, "nonpersistent": function(params){ - OCCI.Action.simple_action(params,OCCI.Image.resource,"nonpersistent"); + params.data.body = { "PERSISTENT":"NO" }; + OCCI.Action.update(params,OCCI.Image.resource,"nonpersistent"); }, - "chtype": function(params){ - var action_obj = {"type" : params.data.extra_param}; - OCCI.Action.simple_action(params, - OCCI.Image.resource, - "chtype", - action_obj); - } }, "Template" : { @@ -637,17 +619,4 @@ var OCCI = { } }, - "Acl" : { - "resource" : "ACL", - - "create" : function(params){ - OCCI.Action.create(params,OCCI.Acl.resource); - }, - "delete" : function(params){ - OCCI.Action.delete(params,OCCI.Acl.resource); - }, - "list" : function(params){ - OCCI.Action.list(params,OCCI.Acl.resource); - } - } } diff --git a/src/cloud/occi/lib/ui/public/js/plugins/acls-tab.js b/src/cloud/occi/lib/ui/public/js/plugins/acls-tab.js deleted file mode 100644 index f0515f0bcb..0000000000 --- a/src/cloud/occi/lib/ui/public/js/plugins/acls-tab.js +++ /dev/null @@ -1,503 +0,0 @@ -/* -------------------------------------------------------------------------- */ -/* 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. */ -/* -------------------------------------------------------------------------- */ - -/*ACLs tab plugin*/ -var dataTable_acls; -var $create_acl_dialog; - -var acls_tab_content = -'
\ -
\ -
\ -\ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ -
'+tr("All")+''+tr("ID")+''+tr("Applies to")+''+tr("Affected resources")+''+tr("Resource ID / Owned by")+''+tr("Allowed operations")+'
\ -
'; - -var create_acl_tmpl = -'
\ -
\ -
\ - \ - \ -
\ - \ - '+tr("Hosts")+'
\ - '+tr("Virtual Machines")+'
\ - '+tr("Virtual Networks")+'
\ - '+tr("Images")+'
\ - '+tr("Templates")+'
\ - '+tr("Users")+'
\ - '+tr("Groups")+'
\ -
\ - \ - '+tr("All")+'
\ - '+tr("Specific ID")+'
\ - '+tr("Owned by group")+'
\ -
\ - \ - \ -
\ - \ - \ -
\ - \ - '+tr("Create")+'
\ - '+tr("Delete")+'
\ - '+tr("Use")+'
\ - '+tr("Manage")+'
\ - '+tr("Get Information")+'
\ - '+tr("Get Pool of resources")+'
\ - '+tr("Get Pool of my/group\'s resources")+'
\ - '+tr("Change owner")+'
\ - '+tr("Deploy")+'
\ -
\ - \ - \ -
\ -
\ -
\ -
\ - \ - \ -
\ -
\ -
'; - -var acl_actions = { - "Acl.create" : { - type: "create", - call: OpenNebula.Acl.create, - callback: function(){ - Sunstone.runAction("Acl.list"); - }, - error: onError, - notify: true - }, - - "Acl.create_dialog" : { - type: "custom", - call: popUpCreateAclDialog - }, - - "Acl.list" : { - type: "list", - call: OpenNebula.Acl.list, - callback: updateAclsView, - error: onError - }, - - "Acl.refresh" : { - type: "custom", - call: function () { - waitingNodes(dataTable_acls); - Sunstone.runAction("Acl.list"); - } - }, - - "Acl.autorefresh" : { - type: "custom", - call: function(){ - OpenNebula.Acl.list({ - timeout: true, - success: updateAclsView, - error: onError - }); - } - }, - - "Acl.delete" : { - type: "multiple", - call: OpenNebula.Acl.delete, - callback: deleteAclElement, - elements: aclElements, - error: onError, - notify: true - }, -} - -var acl_buttons = { - "Acl.refresh" : { - type: "image", - text: tr("Refresh list"), - img: "images/Refresh-icon.png" - }, - "Acl.create_dialog" : { - type: "create_dialog", - text: tr("+ New") - }, - "Acl.delete" : { - type: "action", - text: tr("Delete") - } -} - -var acls_tab = { - title: tr("ACLs"), - content: acls_tab_content, - buttons: acl_buttons -} - -Sunstone.addActions(acl_actions); -Sunstone.addMainTab('acls_tab',acls_tab); - -//Returns selected elements on the acl datatable -function aclElements(){ - return getSelectedNodes(dataTable_acls); -} - -//Receives a segment of an ACL and translates: -// * -> All -// @1 -> Group 1 (tries to translate "1" into group name) -// #1 -> User 1 (tries to translate "1" into username) -//Translation of usernames and groupnames depends on -//group and user plugins tables. -function parseUserAcl(user){ - var user_str=""; - if (user[0] == '*'){ - user_str = tr("All"); - } else { - if (user[0] == '#'){ - user_str=tr("User")+" "; - user_str+= getUserName(user.substring(1)); - } - else if (user[0] == '@'){ - user_str=tr("Group "); - user_str+= getGroupName(user.substring(1)); - }; - }; - return user_str; -} - -//Similar to above, but #1 means resource with "ID 1" -function parseResourceAcl(user){ - var user_str=""; - if (user[0] == '*'){ - user_str = tr("All"); - } else { - if (user[0] == '#'){ - user_str=tr("ID")+" "; - user_str+= user.substring(1); - } - else if (user[0] == '@'){ - user_str=tr("Group")+" "; - user_str+= getGroupName(user.substring(1)); - }; - }; - return user_str; -} - -//Parses a full ACL string, and translates it into -//a legible array -//to be put in the datatable fields. -function parseAclString(string) { - var space_split = string.split(' '); - var user = space_split[0]; - var resources = space_split[1]; - var rights = space_split[2]; - - //User - var user_str=parseUserAcl(user); - - - //Resources - var resources_str=""; - var resources_array = resources.split('/'); - var belonging_to = parseResourceAcl(resources_array[1]); - resources_array = resources_array[0].split('+'); - for (var i=0; i', - acl.ID, - acl_array[0], - acl_array[1], - acl_array[2], - acl_array[3] - ] -} - - -// Callback to delete a single element from the dataTable -function deleteAclElement(request){ - deleteElement(dataTable_acls,'#acl_'+request.request.data); -} - -//update the datatable with new data -function updateAclsView(request,list){ - var list_array = []; - $.each(list,function(){ - list_array.push(aclElementArray(this)); - }); - updateView(list_array,dataTable_acls); - updateDashboard("acls",list); -} - -function setupCreateAclDialog(){ - dialogs_context.append('
'); - $create_acl_dialog = $('#create_acl_dialog',dialogs_context); - var dialog = $create_acl_dialog; - dialog.html(create_acl_tmpl); - var height = Math.floor($(window).height()*0.8); //set height to a percentage of the window - //Prepare jquery dialog - dialog.dialog({ - autoOpen: false, - modal:true, - width: 650, - height: height - }); - - $('#res_subgroup_all',dialog).attr('checked','checked'); - $('#res_id',dialog).attr('disabled','disabled'); - $('#belonging_to',dialog).attr('disabled','disabled'); - - $('button',dialog).button(); - - $('.res_subgroup',dialog).click(function(){ - var value = $(this).val(); - var context = $(this).parent(); - switch (value) { - case "*": - $('#res_id',context).attr('disabled','disabled'); - $('#belonging_to',context).attr('disabled','disabled'); - break; - case "res_id": - $('#res_id',context).removeAttr('disabled'); - $('#belonging_to').attr('disabled','disabled'); - break; - case "belonging_to": - $('#res_id',context).attr('disabled','disabled'); - $('#belonging_to',context).removeAttr('disabled'); - break; - }; - }); - - $('input#res_id',dialog).keyup(function(){ - $(this).trigger("change"); - }); - - //update the rule preview every time some field changes - $('input,select',dialog).change(function(){ - var context = $('#create_acl_form',$create_acl_dialog); - var user = $('#applies',context).val(); - - if ($('#applies :selected',context).hasClass("user")){ - user='#'+user; - } else if ($('#applies :selected',context).hasClass("group")){ - user = '@'+user; - }; - - var resources = ""; - $('.resource_cb:checked',context).each(function(){ - resources+=$(this).val()+'+'; - }); - if (resources.length) { resources = resources.substring(0,resources.length-1) }; - - var belonging=""; - var mode = $('.res_subgroup:checked',context).val(); - switch (mode) { - case "*": - belonging="*"; - break; - case "res_id": - belonging="#"+$('#res_id',context).val(); - break; - case "belonging_to": - belonging="@"+$('#belonging_to',context).val(); - break; - } - - - var rights = ""; - $('.right_cb:checked',context).each(function(){ - rights+=$(this).val()+'+'; - }); - if (rights.length) { rights = rights.substring(0,rights.length-1) }; - - var acl_string = user + ' ' + resources + '/' + belonging + ' ' + rights; - $('#acl_preview',context).val(acl_string); - - }); - - $('#create_acl_form',dialog).submit(function(){ - var user = $('#applies',this).val(); - if (!user.length) { - notifyError(tr("Please specify to who this ACL applies")); - return false; - }; - - var resources = $('.resource_cb:checked',this).length; - if (!resources) { - notifyError(tr("Please select at least one resource")); - return false; - } - - var mode = $('.res_subgroup:checked',this).val(); - switch (mode) { - case "res_id": - var l=$('#res_id',this).val().length; - if (!l){ - notifyError(tr("Please provide a resource ID for the resource(s) in this rule")); - return false; - } - break; - case "belonging_to": - var l=$('#belonging_to',this).val().length; - if (!l){ - notifyError("Please select a group to which the selected resources belong to"); - return false; - } - break; - } - - var rights = $('.right_cb:checked',this).length; - if (!rights) { - notifyError("Please select at least one operation"); - return false; - } - - var acl_string = $('#acl_preview',this).val(); - - var acl_json = { "acl" : acl_string }; - Sunstone.runAction("Acl.create",acl_json); - $create_acl_dialog.dialog('close'); - return false; - }); -} - -// Before popping up the dialog, some prepartions are -// required: we have to put the right options in the -// selects. -function popUpCreateAclDialog(){ - var users = $(''); - $('.empty_value',users).remove(); - $('option',users).addClass("user"); - users.prepend(''); - - var groups = $(''); - $('.empty_value',groups).remove(); - $('option',groups).addClass("group"); - groups.prepend(''); - - var dialog = $create_acl_dialog; - $('#applies',dialog).html(''+ - users.html()+groups.html()); - $('#belonging_to',dialog).html(groups_select); - - $('#applies',dialog).trigger("change"); - dialog.dialog('open'); -} - -// Prepare the autorefresh of the list -function setAclAutorefresh(){ - setInterval(function(){ - var checked = $('input.check_item:checked',dataTable_acls); - var filter = $("#datatable_acls_filter input",dataTable_acls.parents("#datatable_acls_wrapper")).attr('value'); - if (!checked.length && !filter.length){ - Sunstone.runAction("Acl.autorefresh"); - } - },INTERVAL+someTime()); - -} - -$(document).ready(function(){ - //if we are not oneadmin, our tab will not even be in the DOM. - dataTable_acls = $("#datatable_acls",main_tabs_context).dataTable({ - "bJQueryUI": true, - "bSortClasses": false, - "sPaginationType": "full_numbers", - "bAutoWidth":false, - "aoColumnDefs": [ - { "bSortable": false, "aTargets": ["check"] }, - { "sWidth": "60px", "aTargets": [0] }, - { "sWidth": "35px", "aTargets": [1] } - ], - "oLanguage": (datatable_lang != "") ? - { - sUrl: "locale/"+lang+"/"+datatable_lang - } : "" - }); - dataTable_acls.fnClearTable(); - addElement([ - spinner, - '','','','',''],dataTable_acls); - - Sunstone.runAction("Acl.list"); - - setupCreateAclDialog(); - setAclAutorefresh(); - - initCheckAllBoxes(dataTable_acls); - tableCheckboxesListener(dataTable_acls); - //shortenedInfoFields('#datatable_acls'); - -}) diff --git a/src/cloud/occi/lib/ui/public/js/plugins/vms-tab.js b/src/cloud/occi/lib/ui/public/js/plugins/compute.js similarity index 60% rename from src/cloud/occi/lib/ui/public/js/plugins/vms-tab.js rename to src/cloud/occi/lib/ui/public/js/plugins/compute.js index eaa0190df2..e7c510c783 100644 --- a/src/cloud/occi/lib/ui/public/js/plugins/vms-tab.js +++ b/src/cloud/occi/lib/ui/public/js/plugins/compute.js @@ -18,6 +18,7 @@ var INCLUDE_URI = "vendor/noVNC/include/"; var VM_HISTORY_LENGTH = 40; +/* function loadVNC(){ var script = ''; document.write(script); @@ -46,6 +47,8 @@ var vm_graphs = [ history_length : VM_HISTORY_LENGTH } ]; +*/ + var vms_tab_content = '
\ @@ -56,15 +59,7 @@ var vms_tab_content = \ '+tr("All")+'\ '+tr("ID")+'\ - '+tr("Owner")+'\ - '+tr("Group")+'\ '+tr("Name")+'\ - '+tr("Status")+'\ - '+tr("CPU")+'\ - '+tr("Memory")+'\ - '+tr("Hostname")+'\ - '+tr("Start Time")+'\ - '+tr("VNC Access")+'\ \ \ \ @@ -73,26 +68,49 @@ var vms_tab_content =
'; var create_vm_tmpl ='
\ -
\ -
\ +
\ \
\ - \ -
\ - \ - \ -
\
\
\ -
\ - \ - \ + \ +
\ +
\ +
\ + \ + \ +
\ +
\ + \ + \ +
\ +
\ + \ + \ +
\ +
\ +
\ \ -\
'; -var vmachine_list_json = {}; +var vm_dashboard = '
\ +one-compute\ +

'+tr("This is a list of your current compute resources. Virtual Machines use previously defined images and networks. You can easily create a new compute element by cliking \"new\" and filling-in an easy wizard.")+'

\ +

'+tr("You can also manage compute resources and perform actions such as stop, resume, shutdown or cancel.")+'

\ +

'+tr("Additionally, you can take a \"snapshot\" of the storage attached to these resources. They will be saved as new resources, visible from the Storage view and re-usable.")+'

\ +

'+tr("There are currently")+' '+tr("virtual machines")+'.

\ +
'; + + var dataTable_vMachines; var $create_vm_dialog; var $saveas_vm_dialog; @@ -101,13 +119,11 @@ var rfb; var vm_actions = { "VM.create" : { - type: "custom", - call: function(id,name) { - Sunstone.runAction("Template.instantiate",id,name); - Sunstone.runAction("VM.list"); - }, + type: "create", + call: OCCI.VM.create, callback: addVMachineElement, - error: onError + error: onError, + notify: true }, "VM.create_dialog" : { @@ -117,21 +133,21 @@ var vm_actions = { "VM.list" : { type: "list", - call: OpenNebula.VM.list, + call: OCCI.VM.list, callback: updateVMachinesView, error: onError }, "VM.show" : { type: "single", - call: OpenNebula.VM.show, + call: OCCI.VM.show, callback: updateVMachineElement, error: onError }, "VM.showinfo" : { type: "single", - call: OpenNebula.VM.show, + call: OCCI.VM.show, callback: updateVMInfo, error: onError }, @@ -147,58 +163,13 @@ var vm_actions = { "VM.autorefresh" : { type: "custom", call : function() { - OpenNebula.VM.list({timeout: true, success: updateVMachinesView,error: onError}); + OCCI.VM.list({timeout: true, success: updateVMachinesView,error: onError}); }, }, - "VM.deploy" : { - type: "multiple", - call: OpenNebula.VM.deploy, - callback: vmShow, - elements: vmElements, - error: onError, - notify: true - }, - - "VM.migrate" : { - type: "multiple", - call: OpenNebula.VM.migrate, - callback: vmShow, - elements: function() { return getSelectedNodes(dataTable_vMachines); }, - error: onError, - notify: true - }, - - "VM.livemigrate" : { - type: "multiple", - call: OpenNebula.VM.livemigrate, - callback: vmShow, - elements: vmElements, - error: onError, - notify: true - }, - - "VM.hold" : { - type: "multiple", - call: OpenNebula.VM.hold, - callback: vmShow, - elements: vmElements, - error: onError, - notify: true - }, - - "VM.release" : { - type: "multiple", - call: OpenNebula.VM.release, - callback: vmShow, - elements: vmElements, - error: onError, - notify: true - }, - "VM.suspend" : { type: "multiple", - call: OpenNebula.VM.suspend, + call: OCCI.VM.suspend, callback: vmShow, elements: vmElements, error: onError, @@ -207,7 +178,7 @@ var vm_actions = { "VM.resume" : { type: "multiple", - call: OpenNebula.VM.resume, + call: OCCI.VM.resume, callback: vmShow, elements: vmElements, error: onError, @@ -216,25 +187,34 @@ var vm_actions = { "VM.stop" : { type: "multiple", - call: OpenNebula.VM.stop, + call: OCCI.VM.stop, callback: vmShow, elements: vmElements, error: onError, notify: true }, - "VM.restart" : { + "VM.done" : { type: "multiple", - call: OpenNebula.VM.restart, + call: OCCI.VM.done, callback: vmShow, elements: vmElements, error: onError, notify: true }, - "VM.resubmit" : { + "VM.shutdown" : { type: "multiple", - call: OpenNebula.VM.resubmit, + call: OCCI.VM.shutdown, + callback: vmShow, + elements: vmElements, + error: onError, + notify: true + }, + + "VM.cancel" : { + type: "multiple", + call: OCCI.VM.cancel, callback: vmShow, elements: vmElements, error: onError, @@ -251,73 +231,21 @@ var vm_actions = { "VM.saveas" : { type: "single", - call: OpenNebula.VM.saveas, + call: OCCI.VM.saveas, callback: vmShow, error:onError }, "VM.saveas_disks" : { type: "single", - call: OpenNebula.VM.show, + call: OCCI.VM.show, callback: saveasDisksCallback, error: onError }, - - "VM.shutdown" : { - type: "multiple", - call: OpenNebula.VM.shutdown, - callback: vmShow, - elements: vmElements, - error: onError, - notify: true - }, - - "VM.cancel" : { - type: "multiple", - call: OpenNebula.VM.cancel, - callback: vmShow, - elements: vmElements, - error: onError, - notify: true - }, - - "VM.delete" : { - type: "multiple", - call: OpenNebula.VM.delete, - callback: deleteVMachineElement, - elements: vmElements, - error: onError, - notify: true - }, - - "VM.log" : { - type: "single", - call: OpenNebula.VM.log, - callback: function(req,res) { - //after calling VM.log we process the answer - //update the tab and pop it up again - res = res['vm_log']; - var log_lines = res.split("\n"); - var colored_log = ''; - for (var i = 0; i < log_lines.length;i++){ - var line = log_lines[i]; - if (line.match(/\[E\]/)){ - line = ''+line+''; - } - colored_log += line + "\n"; - } - - $('#vm_log_tab').html('
'+colored_log+'
') - }, - error: function(request,error_json){ - $("#vm_log pre").html(''); - onError(request,error_json); - } - }, - + /* "VM.startvnc" : { type: "single", - call: OpenNebula.VM.startvnc, + call: OCCI.VM.startvnc, callback: vncCallback, error: onError, notify: true @@ -325,14 +253,14 @@ var vm_actions = { "VM.stopvnc" : { type: "single", - call: OpenNebula.VM.stopvnc, + call: OCCI.VM.stopvnc, error: onError, notify: true }, "VM.monitor" : { type: "monitor", - call : OpenNebula.VM.monitor, + call : OCCI.VM.monitor, callback: function(req,response) { var info = req.request.data[0].monitor; plot_graph(response,'#vm_monitoring_tab', @@ -342,33 +270,16 @@ var vm_actions = { }, "VM.monitor_all" : { type: "monitor_global", - call: OpenNebula.VM.monitor_all, + call: OCCI.VM.monitor_all, callback: function(req,response) { var info = req.request.data[0].monitor; plot_global_graph(response,info); }, error: onError }, - "VM.chown" : { - type: "multiple", - call: OpenNebula.VM.chown, - callback: vmShow, - elements: vmElements, - error: onError, - notify: true - }, - "VM.chgrp" : { - type: "multiple", - call: OpenNebula.VM.chgrp, - callback: vmShow, - elements: vmElements, - error: onError, - notify: true - } + */ } - - var vm_buttons = { "VM.refresh" : { type: "image", @@ -382,22 +293,6 @@ var vm_buttons = { alwaysActive: true }, - "VM.chown" : { - type: "confirm_with_select", - text: tr("Change owner"), - select: users_sel, - tip: tr("Select the new owner")+":", - condition: mustBeAdmin - }, - - "VM.chgrp" : { - type: "confirm_with_select", - text: tr("Change group"), - select: groups_sel, - tip: tr("Select the new group")+":", - condition: mustBeAdmin - }, - "VM.shutdown" : { type: "confirm", text: tr("Shutdown"), @@ -407,38 +302,6 @@ var vm_buttons = { "action_list" : { type: "select", actions: { - "VM.deploy" : { - type: "confirm_with_select", - text: tr("Deploy"), - tip: tr("This will deploy the selected VMs on the chosen host"), - select: hosts_sel, - condition: mustBeAdmin - }, - "VM.migrate" : { - type: "confirm_with_select", - text: tr("Migrate"), - tip: tr("This will migrate the selected VMs to the chosen host"), - select: hosts_sel, - condition: mustBeAdmin - - }, - "VM.livemigrate" : { - type: "confirm_with_select", - text: tr("Live migrate"), - tip: tr("This will live-migrate the selected VMs to the chosen host"), - select: hosts_sel, - condition: mustBeAdmin - }, - "VM.hold" : { - type: "confirm", - text: tr("Hold"), - tip: tr("This will hold selected pending VMs from being deployed") - }, - "VM.release" : { - type: "confirm", - text: tr("Release"), - tip: tr("This will release held machines") - }, "VM.suspend" : { type: "confirm", text: tr("Suspend"), @@ -454,29 +317,19 @@ var vm_buttons = { text: tr("Stop"), tip: "This will stop selected VMs" }, - "VM.restart" : { - type: "confirm", - text: tr("Restart"), - tip: tr("This will redeploy selected VMs (in UNKNOWN or BOOT state)") - }, - "VM.resubmit" : { - type: "confirm", - text: tr("Resubmit"), - tip: tr("This will resubmits VMs to PENDING state") - }, - "VM.saveasmultiple" : { - type: "action", - text: tr("Save as") - }, "VM.cancel" : { type: "confirm", text: tr("Cancel"), tip: tr("This will cancel selected VMs") + }, + "VM.saveasmultiple" : { + type: "action", + text: tr("Save as") } } }, - "VM.delete" : { + "VM.done" : { type: "confirm", text: tr("Delete"), tip: tr("This will delete the selected VMs from the database") @@ -485,21 +338,20 @@ var vm_buttons = { var vm_info_panel = { "vm_info_tab" : { - title: tr("Virtual Machine information"), + title: tr("Compute resource information"), content: "" }, - "vm_template_tab" : { - title: tr("VM template"), - content: "" - }, - "vm_log_tab" : { - title: tr("VM log"), - content: "" - } } +var vm_create_panel = { + "vm_create_panel" : { + title: tr("Create Virtual Machine"), + content: create_vm_tmpl + }, +}; + var vms_tab = { - title: tr("Virtual Machines"), + title: tr("Compute"), content: vms_tab_content, buttons: vm_buttons } @@ -507,6 +359,7 @@ var vms_tab = { Sunstone.addActions(vm_actions); Sunstone.addMainTab('vms_tab',vms_tab); Sunstone.addInfoPanel('vm_info_panel',vm_info_panel); +Sunstone.addInfoPanel('vm_create_panel',vm_create_panel); function vmElements() { @@ -514,7 +367,7 @@ function vmElements() { } function vmShow(req) { - Sunstone.runAction("VM.show",req.request.data[0]); +// Sunstone.runAction("VM.show",req.request.data[0]); } // Returns a human readable running time for a VM @@ -525,34 +378,23 @@ function str_start_time(vm){ // Returns an array formed by the information contained in the vm_json // and ready to be introduced in a dataTable function vMachineElementArray(vm_json){ - var vm = vm_json.VM; - var state = OpenNebula.Helper.resource_state("vm",vm.STATE); - var hostname = "--"; + var vm = vm_json.COMPUTE; + var id,name; - if (state == "ACTIVE" || state == "SUSPENDED"){ - if (vm.HISTORY_RECORDS.HISTORY.constructor == Array){ - hostname = vm.HISTORY_RECORDS.HISTORY[vm.HISTORY_RECORDS.HISTORY.length-1].HOSTNAME; - } else { - hostname = vm.HISTORY_RECORDS.HISTORY.HOSTNAME; - }; - }; - - if (state == "ACTIVE") { - state = OpenNebula.Helper.resource_state("vm_lcm",vm.LCM_STATE); + if (vm.name){ + id = vm.href.split("/"); + id = id[id.length-1]; + name = vm.name; + } + else { + id = vm.ID; + name = vm.NAME; }; return [ - '', - vm.ID, - vm.UNAME, - vm.GNAME, - vm.NAME, - state, - vm.CPU, - humanize_size(vm.MEMORY), - hostname, - str_start_time(vm), - vncIcon(vm) + '', + id, + name, ]; } @@ -572,7 +414,7 @@ function vMachineInfoListener(){ // Callback to refresh a single element from the list function updateVMachineElement(request, vm_json){ - var id = vm_json.VM.ID; + var id = vm_json.COMPUTE.ID; var element = vMachineElementArray(vm_json); updateSingleElement(element,dataTable_vMachines,'#vm_'+id) } @@ -584,7 +426,7 @@ function deleteVMachineElement(request){ // Callback to add an element to the list function addVMachineElement(request,vm_json){ - var id = vm_json.VM.ID; + var id = vm_json.COMPUTE.ID; var element = vMachineElementArray(vm_json); addElement(element,dataTable_vMachines); } @@ -599,22 +441,14 @@ function updateVMachinesView(request, vmachine_list){ }); updateView(vmachine_list_array,dataTable_vMachines); - updateDashboard("vms",vmachine_list); + //updateDashboard("vms",vmachine_list); } // Refreshes the information panel for a VM function updateVMInfo(request,vm){ - var vm_info = vm.VM; - var vm_state = OpenNebula.Helper.resource_state("vm",vm_info.STATE); - var hostname = "--" - if (vm_state == "ACTIVE" || vm_state == "SUSPENDED") { - if (vm_info.HISTORY_RECORDS.HISTORY.constructor == Array){ - hostname = vm_info.HISTORY_RECORDS.HISTORY[vm_info.HISTORY_RECORDS.HISTORY.length-1].HOSTNAME - } else { - hostname = vm_info.HISTORY_RECORDS.HISTORY.HOSTNAME; - }; - }; + var vm_info = vm.COMPUTE; + var vm_state = OCCI.Helper.resource_state("vm",vm_info.STATE); var info_tab = { title : tr("VM information"), @@ -632,125 +466,148 @@ function updateVMInfo(request,vm){ '+tr("Name")+'\ '+vm_info.NAME+'\ \ - \ - '+tr("Owner")+'\ - '+vm_info.UNAME+'\ - \ - \ - '+tr("Group")+'\ - '+vm_info.GNAME+'\ - \ \ '+tr("State")+'\ '+tr(vm_state)+'\ \ \ - '+tr("LCM State")+'\ - '+tr(OpenNebula.Helper.resource_state("vm_lcm",vm_info.LCM_STATE))+'\ + '+tr("CPU")+'\ + '+vm_info.CPU+'\ \ \ - '+tr("Hostname")+'\ - '+ hostname +'\ + '+tr("Memory")+'\ + '+vm_info.MEMORY+'\ \ - \ - '+tr("Start time")+'\ - '+pretty_time(vm_info.STIME)+'\ - \ - \ - '+tr("Deploy ID")+'\ - '+(typeof(vm_info.DEPLOY_ID) == "object" ? "-" : vm_info.DEPLOY_ID)+'\ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ -
'+tr("Monitoring information")+'
'+tr("Net_TX")+''+vm_info.NET_TX+'
'+tr("Net_RX")+''+vm_info.NET_RX+'
'+tr("Used Memory")+''+humanize_size(vm_info.MEMORY)+'
'+tr("Used CPU")+''+vm_info.CPU+'
'+tr("VNC Session")+''+vncIcon(vm_info)+'
' - } - - var template_tab = { - title: tr("VM Template"), - content: - '\ - '+ - prettyPrintJSON(vm_info.TEMPLATE)+ - '
'+tr("VM template")+'
' - } - - var log_tab = { - title: tr("VM log"), - content: '
'+spinner+'
' + \ + \ +
\ +
' } + /* var monitoring_tab = { title: tr("Monitoring information"), content: generateMonitoringDivs(vm_graphs,"vm_monitor_") } + */ Sunstone.updateInfoPanelTab("vm_info_panel","vm_info_tab",info_tab); - Sunstone.updateInfoPanelTab("vm_info_panel","vm_template_tab",template_tab); - Sunstone.updateInfoPanelTab("vm_info_panel","vm_log_tab",log_tab); - Sunstone.updateInfoPanelTab("vm_info_panel","vm_monitoring_tab",monitoring_tab); + //Sunstone.updateInfoPanelTab("vm_info_panel","vm_monitoring_tab",monitoring_tab); //Pop up the info panel and asynchronously get vm_log and stats Sunstone.popUpInfoPanel("vm_info_panel"); - Sunstone.runAction("VM.log",vm_info.ID); - for (var i=0; i'); - //Insert HTML in place - $create_vm_dialog = $('#create_vm_dialog') - var dialog = $create_vm_dialog; - dialog.html(create_vm_tmpl); - - //Prepare jquery dialog - dialog.dialog({ - autoOpen: false, - modal: true, - width: 400 - }); +// Open creation dialog +function popUpCreateVMDialog(){ + Sunstone.popUpInfoPanel("vm_create_panel"); + var dialog = $('#dialog'); + $create_vm_dialog = dialog; $('button',dialog).button(); + $('#create_vm',dialog).button({ + icons: { + primary: "ui-icon-check" + }, + text: false + }); + $('#reset_vm',dialog).button({ + icons: { + primary: "ui-icon-document" + }, + text: false + }); + $('.vm_close_dialog_link',dialog).button({ + icons: { + primary: "ui-icon-closethick" + }, + text: false + }); + + var net_select = makeSelectOptions(dataTable_vNetworks, + 1,//id_col + 2,//name_col + [], + [], + true + ); + + $('#network_box',dialog).html(net_select); + + var image_select = makeSelectOptions(dataTable_images, + 1,//id_col + 2,//name_col + [], + [], + true); + + $('#disk_box',dialog).html(image_select); + + $('#network_box,#disk_box',dialog).change(function(){ + $(this).val(""); + return false; + }); + + $('#network_box option,#disk_box option',dialog).click(function(){ + var bold = $(this).css("font-weight") == "700"; //bold + if (bold){//unbold, unmark + $(this).css("font-weight","400"); + $(this).removeAttr('clicked'); + } + else {//bold,mark + $(this).css("font-weight","700"); + $(this).attr('clicked','clicked'); + } + return false; + }); + $('#create_vm_form',dialog).submit(function(){ var vm_name = $('#vm_name',this).val(); - var template_id = $('#template_id',this).val(); + var instance_type = $('#instance_type',this).val(); var n_times = $('#vm_n_times',this).val(); var n_times_int=1; - if (!template_id.length){ - notifyError(tr("You have not selected a template")); - return false; - } + if (!vm_name.length){ + notifyError("Please specify a name for the virtual machine"); + }; + + var vm = { + "NAME" : vm_name, + "INSTANCE_TYPE" : instance_type, + }; + + var href = location.protocol + "//" + location.host; + + var disks = $('#disk_box option[clicked="clicked"]'); + if (disks.length){ + vm["DISK"] = []; + + disks.each(function(){ + var value = $(this).val(); + vm["DISK"].push(''); + }); + }; + + var nets = $('#network_box option[clicked="clicked"]'); + + if (nets.length){ + vm["NETWORK"] = []; + + nets.each(function(){ + var value = $(this).val(); + vm["NETWORK"].push(''); + }); + }; if (n_times.length){ n_times_int=parseInt(n_times,10); @@ -761,22 +618,17 @@ function setupCreateVMDialog(){ vm_name = $('#template_id option:selected',this).text(); } for (var i=0; i< n_times_int; i++){ - Sunstone.runAction("Template.instantiate",template_id,vm_name+"_"+i); + Sunstone.runAction("VM.create",vm); }; } else { - Sunstone.runAction("Template.instantiate",template_id,vm_name); + Sunstone.runAction("VM.create",vm); }; - Sunstone.runAction("VM.list"); - $create_vm_dialog.dialog('close'); + popUpVMDashboard(); return false; }); } -// Open creation dialog -function popUpCreateVMDialog(){ - $create_vm_dialog.dialog('open'); -} //Prepares a dialog to saveas a VM function setupSaveasDialog(){ @@ -812,7 +664,6 @@ function setupSaveasDialog(){ var id = $('#vm_id',this).text(); var disk_id = $('#vm_disk_id',this).val(); var image_name = $('#image_name',this).val(); - var type = $('#image_type',this).val(); if (!id.length || !disk_id.length || !image_name.length) { notifyError(tr("Skipping VM ")+id+". "+ @@ -822,7 +673,6 @@ function setupSaveasDialog(){ var obj = { disk_id : disk_id, image_name : image_name, - type: type }; args.push(id); Sunstone.runAction("VM.saveas",id,obj); @@ -865,15 +715,6 @@ function popUpSaveasDialog(elems){ \ \ \ -
\ - \ - \ -
\ \ '; $('#saveas_tabs',dialog).append(tab); @@ -885,34 +726,40 @@ function popUpSaveasDialog(elems){ } function saveasDisksCallback(req,response){ - var vm_info = response.VM; + var vm_info = response.COMPUTE; var id=vm_info.ID; var select=""; var gen_option = function(id, name, source){ if (name){ - return ''; + return ''; } else { - return ''; + return ''; } } - var disks = vm_info.TEMPLATE.DISK; + var disks = vm_info.DISK; if (!disks) { select = '';} else if (disks.constructor == Array) //several disks { for (var i=0;i'; @@ -1057,6 +904,8 @@ function vmMonitorError(req,error_json){ $('#vm_monitoring_tab '+id).html('
'+message+'
'); } +*/ + // At this point the DOM is ready and the sunstone.js ready() has been run. $(document).ready(function(){ @@ -1067,15 +916,13 @@ $(document).ready(function(){ "bAutoWidth":false, "aoColumnDefs": [ { "bSortable": false, "aTargets": ["check"] }, - { "sWidth": "60px", "aTargets": [0,6,7] }, - { "sWidth": "35px", "aTargets": [1,10] }, - { "sWidth": "150px", "aTargets": [5,9] }, - { "sWidth": "100px", "aTargets": [2,3] } + { "sWidth": "60px", "aTargets": [0] }, + { "sWidth": "35px", "aTargets": [1] }, ], - "oLanguage": (datatable_lang != "") ? - { - sUrl: "locale/"+lang+"/"+datatable_lang - } : "" + "oLanguage": (datatable_lang != "") ? + { + sUrl: "locale/"+lang+"/"+datatable_lang + } : "" }); dataTable_vMachines.fnClearTable(); @@ -1084,12 +931,21 @@ $(document).ready(function(){ '','','','','','','','','',''],dataTable_vMachines); Sunstone.runAction("VM.list"); - setupCreateVMDialog(); + //setupCreateVMDialog(); setupSaveasDialog(); setVMAutorefresh(); - setupVNC(); + //setupVNC(); initCheckAllBoxes(dataTable_vMachines); tableCheckboxesListener(dataTable_vMachines); vMachineInfoListener(); + + $('#li_vms_tab a').click(function(){ + popUpVMDashboard(); + }); + + $('.vm_close_dialog_link').live("click",function(){ + popUpVMDashboard(); + return false; + }); }) \ No newline at end of file diff --git a/src/cloud/occi/lib/ui/public/js/plugins/dashboard-users-tab.js b/src/cloud/occi/lib/ui/public/js/plugins/dashboard-users-tab.js deleted file mode 100644 index f9a5ab61cd..0000000000 --- a/src/cloud/occi/lib/ui/public/js/plugins/dashboard-users-tab.js +++ /dev/null @@ -1,300 +0,0 @@ -/* -------------------------------------------------------------------------- */ -/* 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. */ -/* -------------------------------------------------------------------------- */ - -/** HISTORY_LENGTH currently ignored on server, but it doesn't harm to have it**/ -var HISTORY_LENGTH=40; -var GRAPH_AUTOREFRESH_INTERVAL=60000; //60 secs - -var graph1 = { - title : "graph1", - monitor_resources : "total,active,error", - history_length : HISTORY_LENGTH -}; - -var graph2 = { - title : "graph2", - monitor_resources : "cpu_usage", - history_length : HISTORY_LENGTH -}; - -var graph3 = { - title : "graph3", - monitor_resources : "mem_usage", - history_length : HISTORY_LENGTH -}; - -var graph4 = { - title : "graph4", - monitor_resources : "net_tx,net_rx", - history_length : HISTORY_LENGTH -}; - -var dashboard_tab_content = -'\ -\ -\ -\ -
\ -\ - \ - \ - \ - \ - \ - \ -
\ -
\ -

'+tr("Summary of resources")+'

\ -
\ -\ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ -
'+tr("VM Templates (total/public)")+'
'+tr("VM Instances")+' ('+ - tr("total")+'/'+ - tr("running")+'/'+ - tr("failed")+')
'+tr("Virtual Networks (total/public)")+'
'+tr("Images (total/public)")+'
\ -\ -
\ -
\ -
\ -
\ -

'+tr("Quickstart")+'

\ -
\ -
\ - \ - '+tr("VM Template")+'
\ - '+tr("VM Instance")+'
\ - '+tr("Virtual Network")+'
\ - '+tr("Image")+'
\ -
\ -
\ -
\ -
\ -\ - \ - \ - \ -
\ -
\ -

'+tr("Historical monitoring information")+'

\ -
\ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ -
'+tr("Total VM count")+'
'+spinner+'
'+tr("Total VM CPU")+'
'+spinner+'
'+tr("Total VM Memory")+'
'+spinner+'
'+tr("VM Network stats")+'
'+spinner+'
\ -
\ -
\ -
\ -
'; - -var dashboard_tab = { - title: tr("Dashboard"), - content: dashboard_tab_content -} - -Sunstone.addMainTab('dashboard_tab',dashboard_tab); - -function plot_global_graph(data,info){ - var context = $('#historical_table',main_tabs_context); - var id = info.title; - var monitoring = data.monitoring; - var serie; - var series = []; - var width = ($(window).width()-129)*48/100; - var mon_count = 0; - var labels_array = info.monitor_resources.split(','); - - $('#'+id,context).html('
'); - - for (var i=0; i\ -
\ -
\ -\ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ -
'+tr("All")+''+tr("ID")+''+tr("Name")+''+tr("Users")+'
\ -'; - -var create_group_tmpl = -'
\ -
\ -
\ - \ -
\ -
\ -
\ -
\ -
\ - \ - \ -
\ -
\ -
'; - - -var group_actions = { - "Group.create" : { - type: "create", - call : OpenNebula.Group.create, - callback : addGroupElement, - error : onError, - notify: true - }, - - "Group.create_dialog" : { - type: "custom", - call: popUpCreateGroupDialog - }, - - "Group.list" : { - type: "list", - call: OpenNebula.Group.list, - callback: updateGroupsView, - error: onError, - }, - - // "Group.showinfo" : { - // type: "custom", - // call: updateGroupInfo - // }, - - "Group.autorefresh" : { - type: "custom", - call: function () { - OpenNebula.Group.list({timeout: true, success: updateGroupsView,error: onError}); - } - }, - - "Group.refresh" : { - type: "custom", - call: function() { - waitingNodes(dataTable_groups); - Sunstone.runAction("Group.list"); - }, - error: onError - }, - - "Group.delete" : { - type: "multiple", - call : OpenNebula.Group.delete, - callback : deleteGroupElement, - error : onError, - elements: groupElements, - notify:true - }, - - // "Group.chown" : { - // type: "multiple", - // call : OpenNebula.Group.chown, - // callback : updateGroupElement, - // elements: function() { return getSelectedNodes(dataTable_groups); }, - // error : onError, - // notify:true - // }, - -} - -var group_buttons = { - "Group.refresh" : { - type: "image", - text: tr("Refresh list"), - img: "images/Refresh-icon.png" - }, - "Group.create_dialog" : { - type: "create_dialog", - text: tr("+ New Group") - }, - // "Group.chown" : { - // type: "confirm_with_select", - // text: "Change group owner", - // select: function(){return users_select}, - // tip: "Select the new group owner:", - // condition : True - // }, - - "Group.delete" : { - type: "action", - text: tr("Delete") - } -}; - -var groups_tab = { - title: tr("Groups"), - content: groups_tab_content, - buttons: group_buttons -} - -Sunstone.addActions(group_actions); -Sunstone.addMainTab('groups_tab',groups_tab); - -function groupElements(){ - return getSelectedNodes(dataTable_groups); -} - -function groupElementArray(group_json){ - var group = group_json.GROUP; - - var users_str=""; - if (group.USERS.ID && - group.USERS.ID.constructor == Array){ - for (var i=0; i', - group.ID, - group.NAME, - users_str ]; -} - -// function groupInfoListener(){ -// $('#groups_tab #tbodygroups tr',main_tabs_context).live("click",function(e){ -// //do nothing if we are clicking a checkbox! -// if ($(e.target).is('input')) {return true;} -// var aData = dataTable_groups.fnGetData(this); -// var id = $(aData[0]).val(); -// Sunstone.runAction("Group.showinfo",id); -// return false; -// }); -// } - -function updateGroupSelect(){ - groups_select = makeSelectOptions(dataTable_groups, - 1,//id_col - 2,//name_col - [],//status_cols - []//bad_status_cols - ); -} - -function updateGroupElement(request, group_json){ - var id = group_json.GROUP.ID; - var element = groupElementArray(group_json); - updateSingleElement(element,dataTable_groups,'#group_'+id); - //No need to update select as all items are in it always -} - -function deleteGroupElement(request){ - deleteElement(dataTable_groups,'#group_'+request.request.data); - updateGroupSelect(); -} - -function addGroupElement(request,group_json){ - var id = group_json.GROUP.ID; - var element = groupElementArray(group_json); - addElement(element,dataTable_groups); - updateGroupSelect(); -} - -//updates the list -function updateGroupsView(request, group_list){ - group_list_json = group_list; - var group_list_array = []; - - $.each(group_list,function(){ - group_list_array.push(groupElementArray(this)); - }); - - updateView(group_list_array,dataTable_groups); - updateGroupSelect(group_list); - updateDashboard("groups",group_list); -} - -//Prepares the dialog to create -function setupCreateGroupDialog(){ - dialogs_context.append('
'); - $create_group_dialog = $('#create_group_dialog',dialogs_context); - var dialog = $create_group_dialog; - - dialog.html(create_group_tmpl); - dialog.dialog({ - autoOpen: false, - modal: true, - width: 400 - }); - - $('button',dialog).button(); - - $('#create_group_form',dialog).submit(function(){ - var name=$('#name',this).val(); - var group_json = { "group" : { "name" : name }}; - Sunstone.runAction("Group.create",group_json); - $create_group_dialog.dialog('close'); - return false; - }); -} - -function popUpCreateGroupDialog(){ - $create_group_dialog.dialog('open'); - return false; -} - -//Prepares the autorefresh -function setGroupAutorefresh(){ - setInterval(function(){ - var checked = $('input.check_item:checked',dataTable_groups); - var filter = $("#datatable_groups_filter input",dataTable_groups.parents("#datatable_groups_wrapper")).attr('value'); - if (!checked.length && !filter.length){ - Sunstone.runAction("Group.autorefresh"); - } - },INTERVAL+someTime()); -} - -$(document).ready(function(){ - dataTable_groups = $("#datatable_groups",main_tabs_context).dataTable({ - "bJQueryUI": true, - "bSortClasses": false, - "sPaginationType": "full_numbers", - "bAutoWidth":false, - "aoColumnDefs": [ - { "bSortable": false, "aTargets": ["check"] }, - { "sWidth": "60px", "aTargets": [0] }, - { "sWidth": "35px", "aTargets": [1] } - ], - "oLanguage": (datatable_lang != "") ? - { - sUrl: "locale/"+lang+"/"+datatable_lang - } : "" - }); - - dataTable_groups.fnClearTable(); - addElement([ - spinner, - '','',''],dataTable_groups); - - Sunstone.runAction("Group.list"); - setupCreateGroupDialog(); - setGroupAutorefresh(); - - initCheckAllBoxes(dataTable_groups); - tableCheckboxesListener(dataTable_groups); -}) diff --git a/src/cloud/occi/lib/ui/public/js/plugins/hosts-tab.js b/src/cloud/occi/lib/ui/public/js/plugins/hosts-tab.js deleted file mode 100644 index ef76e692a9..0000000000 --- a/src/cloud/occi/lib/ui/public/js/plugins/hosts-tab.js +++ /dev/null @@ -1,634 +0,0 @@ -/* -------------------------------------------------------------------------- */ -/* 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*/ -/* HOST_HISTORY_LENGTH is ignored by server */ -var HOST_HISTORY_LENGTH = 40; -var host_graphs = [ - { - title : tr("CPU Monitoring information"), - monitor_resources : "cpu_usage,used_cpu,max_cpu", - humanize_figures : false, - history_length : HOST_HISTORY_LENGTH - }, - { - title: tr("Memory monitoring information"), - monitor_resources : "mem_usage,used_mem,max_mem", - humanize_figures : true, - history_length : HOST_HISTORY_LENGTH - } -] - - -var hosts_tab_content = -'
\ -
\ -
\ -\ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ -
' + tr("All") + '' + tr("id") + '' + tr("Name") + '' + tr("Running VMs") + '' + tr("CPU Use") + '' + tr("Memory use") + '' + tr("Status") + '
\ -
'; - -var create_host_tmpl = -'
\ -
\ - ' + tr("Host parameters") + '\ - \ -
\ -

' + tr("Drivers") + '

\ -
\ -
\ - \ - \ -
\ -
\ - \ - \ -
\ -
\ - \ - \ -
\ -
\ - \ - \ -
\ -
\ -
\ -
\ -
\ -
\ -
\ -
\ -
'; - -var hosts_select=""; -var dataTable_hosts; -var $create_host_dialog; - -//Setup actions -var host_actions = { - - "Host.create" : { - type: "create", - call : OpenNebula.Host.create, - callback : addHostElement, - error : onError, - notify: true - }, - - "Host.create_dialog" : { - type: "custom", - call: popUpCreateHostDialog - }, - - "Host.list" : { - type: "list", - call: OpenNebula.Host.list, - callback: updateHostsView, - error: onError - }, - - "Host.show" : { - type: "single", - call: OpenNebula.Host.show, - callback: updateHostElement, - error: onError - }, - - "Host.showinfo" : { - type: "single", - call: OpenNebula.Host.show, - callback: updateHostInfo, - error: onError - }, - - "Host.refresh" : { - type: "custom", - call: function(){ - waitingNodes(dataTable_hosts); - Sunstone.runAction("Host.list"); - }, - error: onError - }, - - "Host.autorefresh" : { - type: "custom", - call : function() { - OpenNebula.Host.list({timeout: true, success: updateHostsView,error: onError}); - } - }, - - "Host.enable" : { - type: "multiple", - call : OpenNebula.Host.enable, - callback : function (req) { - Sunstone.runAction("Host.show",req.request.data[0]); - }, - elements: hostElements, - error : onError, - notify: true - }, - - "Host.disable" : { - type: "multiple", - call : OpenNebula.Host.disable, - callback : function (req) { - Sunstone.runAction("Host.show",req.request.data[0]); - }, - elements: hostElements, - error : onError, - notify:true - }, - - "Host.delete" : { - type: "multiple", - call : OpenNebula.Host.delete, - callback : deleteHostElement, - elements: hostElements, - error : onError, - notify:true - }, - - "Host.monitor" : { - type: "monitor", - call : OpenNebula.Host.monitor, - callback: function(req,response) { - var info = req.request.data[0].monitor; - plot_graph(response,'#host_monitoring_tab', - 'host_monitor_',info); - }, - error: hostMonitorError - }, - - "Host.monitor_all" : { - type: "monitor_global", - call: OpenNebula.Host.monitor_all, - callback: function(req,response) { - var info = req.request.data[0].monitor; - plot_global_graph(response,info); - }, - error: onError - }, - - "Host.fetch_template" : { - type: "single", - call: OpenNebula.Host.fetch_template, - callback: function (request,response) { - $('#template_update_dialog #template_update_textarea').val(response.template); - }, - error: onError - }, - - "Host.update_dialog" : { - type: "custom", - call: function() { - popUpTemplateUpdateDialog("Host", - makeSelectOptions(dataTable_hosts, - 1,//id_col - 2,//name_col - [], - [] - ), - getSelectedNodes(dataTable_hosts)); - } - }, - - "Host.update" : { - type: "single", - call: OpenNebula.Host.update, - callback: function() { - notifyMessage(tr("Template updated correctly")); - }, - error: onError - } -}; - -var host_buttons = { - "Host.refresh" : { - type: "image", - text: tr("Refresh list"), - img: "images/Refresh-icon.png" - }, - "Host.create_dialog" : { - type: "create_dialog", - text: tr("+ New") - }, - "Host.update_dialog" : { - type: "action", - text: tr("Update a template"), - alwaysActive: true - }, - "Host.enable" : { - type: "action", - text: tr("Enable") - }, - "Host.disable" : { - type: "action", - text: tr("Disable") - }, - "Host.delete" : { - type: "action", - text: tr("Delete host") - } -}; - -var host_info_panel = { - "host_info_tab" : { - title: tr("Host information"), - content:"" - }, - - "host_template_tab" : { - title: tr("Host template"), - content: "" - }, - "host_monitoring_tab": { - title: tr("Monitoring information"), - content: "" - } -}; - - -var hosts_tab = { - title: tr("Hosts"), - content: hosts_tab_content, - buttons: host_buttons -} - -Sunstone.addActions(host_actions); -Sunstone.addMainTab('hosts_tab',hosts_tab); -Sunstone.addInfoPanel("host_info_panel",host_info_panel); - - -function hostElements(){ - return getSelectedNodes(dataTable_hosts); -} - -//Creates an array to be added to the dataTable from the JSON of a host. -function hostElementArray(host_json){ - - var host = host_json.HOST; - - //Calculate some values - var acpu = parseInt(host.HOST_SHARE.MAX_CPU); - if (!acpu) {acpu=100}; - acpu = acpu - parseInt(host.HOST_SHARE.CPU_USAGE); - - var total_mem = parseInt(host.HOST_SHARE.MAX_MEM); - var free_mem = parseInt(host.HOST_SHARE.FREE_MEM); - - var ratio_mem = 0; - if (total_mem) { - ratio_mem = Math.round(((total_mem - free_mem) / total_mem) * 100); - } - - - var total_cpu = parseInt(host.HOST_SHARE.MAX_CPU); - var used_cpu = Math.max(total_cpu - parseInt(host.HOST_SHARE.USED_CPU),acpu); - - var ratio_cpu = 0; - if (total_cpu){ - ratio_cpu = Math.round(((total_cpu - used_cpu) / total_cpu) * 100); - } - - - //progressbars html code - hardcoded jquery html result - var pb_mem = -'
\ -
\ - '+ratio_mem+'%\ -
\ -
'; - - var pb_cpu = -'
\ -
\ - '+ratio_cpu+'%\ -
\ -
'; - - - return [ - '', - host.ID, - host.NAME, - host.HOST_SHARE.RUNNING_VMS, //rvm - pb_cpu, - pb_mem, - OpenNebula.Helper.resource_state("host_simple",host.STATE) ]; -} - -//Listen to clicks on the tds of the tables and shows the info dialogs. -function hostInfoListener(){ - $('#tbodyhosts tr',dataTable_hosts).live("click",function(e){ - //do nothing if we are clicking a checkbox! - if ($(e.target).is('input')) {return true;} - popDialogLoading(); - var aData = dataTable_hosts.fnGetData(this); - var id = $(aData[0]).val(); - Sunstone.runAction("Host.showinfo",id); - return false; - }); -} - -//updates the host select by refreshing the options in it -function updateHostSelect(){ - hosts_select = makeSelectOptions(dataTable_hosts, - 1,//id_col - 2,//name_col - [6,6],//status_cols - ["ERROR","OFF"]//bad_st - ); -} - -//callback for an action affecting a host element -function updateHostElement(request, host_json){ - var id = host_json.HOST.ID; - var element = hostElementArray(host_json); - updateSingleElement(element,dataTable_hosts,'#host_'+id); - updateHostSelect(); -} - -//callback for actions deleting a host element -function deleteHostElement(req){ - deleteElement(dataTable_hosts,'#host_'+req.request.data); - updateHostSelect(); -} - -//call back for actions creating a host element -function addHostElement(request,host_json){ - var id = host_json.HOST.ID; - var element = hostElementArray(host_json); - addElement(element,dataTable_hosts); - updateHostSelect(); -} - -//callback to update the list of hosts. -function updateHostsView (request,host_list){ - var host_list_array = []; - - $.each(host_list,function(){ - //Grab table data from the host_list - host_list_array.push(hostElementArray(this)); - }); - - updateView(host_list_array,dataTable_hosts); - updateHostSelect(); - //dependency with the dashboard plugin - updateDashboard("hosts",host_list); -} - -//Updates the host info panel tab's content and pops it up -function updateHostInfo(request,host){ - var host_info = host.HOST; - - //Information tab - var info_tab = { - title : tr("Host information"), - content : - '\ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ -
' + tr("Host information") + ' - '+host_info.NAME+'
' + tr("id") + ''+host_info.ID+'
' + tr("State") + ''+tr(OpenNebula.Helper.resource_state("host",host_info.STATE))+'
' + tr("IM MAD") + ''+host_info.IM_MAD+'
' + tr("VM MAD") + ''+host_info.VM_MAD+'
'+ tr("VN MAD") +''+host_info.VN_MAD+'
'+ tr("TM MAD") +''+host_info.TM_MAD+'
\ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ -
' + tr("Host shares") + '
' + tr("Max Mem") + ''+humanize_size(host_info.HOST_SHARE.MAX_MEM)+'
' + tr("Used Mem (real)") + ''+humanize_size(host_info.HOST_SHARE.USED_MEM)+'
' + tr("Used Mem (allocated)") + ''+humanize_size(host_info.HOST_SHARE.MAX_USAGE)+'
' + tr("Used CPU (real)") + ''+host_info.HOST_SHARE.USED_CPU+'
' + tr("Used CPU (allocated)") + ''+host_info.HOST_SHARE.CPU_USAGE+'
' + tr("Running VMs") + ''+host_info.HOST_SHARE.RUNNING_VMS+'
' - } - - //Template tab - var template_tab = { - title : tr("Host template"), - content : - '\ - '+ - prettyPrintJSON(host_info.TEMPLATE)+ - '
' + tr("Host template") + '
' - } - - var monitor_tab = { - title: tr("Monitoring information"), - content : generateMonitoringDivs(host_graphs,"host_monitor_") - } - - //Sunstone.updateInfoPanelTab(info_panel_name,tab_name, new tab object); - Sunstone.updateInfoPanelTab("host_info_panel","host_info_tab",info_tab); - Sunstone.updateInfoPanelTab("host_info_panel","host_template_tab",template_tab); - Sunstone.updateInfoPanelTab("host_info_panel","host_monitoring_tab",monitor_tab); - - Sunstone.popUpInfoPanel("host_info_panel"); - //pop up panel while we retrieve the graphs - for (var i=0; i
'); - $create_host_dialog = $('div#create_host_dialog'); - var dialog = $create_host_dialog; - - dialog.html(create_host_tmpl); - dialog.dialog({ - autoOpen: false, - modal: true, - width: 500 - }); - - $('button',dialog).button(); - - //Handle the form submission - $('#create_host_form',dialog).submit(function(){ - if (!($('#name',this).val().length)){ - notifyError(tr("Host name missing!")); - return false; - } - var host_json = { - "host": { - "name": $('#name',this).val(), - "tm_mad": $('#tm_mad :selected',this).val(), - "vm_mad": $('#vmm_mad :selected',this).val(), - "vnm_mad": $('#vnm_mad :selected',this).val(), - "im_mad": $('#im_mad :selected',this).val() - } - } - - //Create the OpenNebula.Host. - //If it's successfull we refresh the list. - Sunstone.runAction("Host.create",host_json); - $create_host_dialog.dialog('close'); - return false; - }); -} - -//Open creation dialogs -function popUpCreateHostDialog(){ - $create_host_dialog.dialog('open'); - return false; -} - -//Prepares the autorefresh for hosts -function setHostAutorefresh() { - setInterval(function(){ - var checked = $('input.check_item:checked',dataTable_hosts); - var filter = $("#datatable_hosts_filter input",dataTable_hosts.parents('#datatable_hosts_wrapper')).attr('value'); - if (!checked.length && !filter.length){ - Sunstone.runAction("Host.autorefresh"); - } - },INTERVAL+someTime()); -} - -function hostMonitorError(req,error_json){ - var message = error_json.error.message; - var info = req.request.data[0].monitor; - var labels = info.monitor_resources; - var id_suffix = labels.replace(/,/g,'_'); - var id = '#host_monitor_'+id_suffix; - $('#host_monitoring_tab '+id).html('
'+message+'
'); -} - -function hosts_sel() { - return hosts_select; -} - -//This is executed after the sunstone.js ready() is run. -//Here we can basicly init the host datatable, preload it -//and add specific listeners -$(document).ready(function(){ - - //prepare host datatable - dataTable_hosts = $("#datatable_hosts",main_tabs_context).dataTable({ - "bJQueryUI": true, - "bSortClasses": false, - "bAutoWidth":false, - "sPaginationType": "full_numbers", - "aoColumnDefs": [ - { "bSortable": false, "aTargets": ["check"] }, - { "sWidth": "60px", "aTargets": [0,3] }, - { "sWidth": "35px", "aTargets": [1] }, - { "sWidth": "100px", "aTargets": [6] }, - { "sWidth": "200px", "aTargets": [4,5] } - ], - "oLanguage": (datatable_lang != "") ? - { - sUrl: "locale/"+lang+"/"+datatable_lang - } : "" - }); - - //preload it - dataTable_hosts.fnClearTable(); - addElement([ - spinner, - '','','','','',''],dataTable_hosts); - Sunstone.runAction("Host.list"); - - setupCreateHostDialog(); - - setHostAutorefresh(); - - initCheckAllBoxes(dataTable_hosts); - tableCheckboxesListener(dataTable_hosts); - hostInfoListener(); -}); diff --git a/src/cloud/occi/lib/ui/public/js/plugins/images-tab.js b/src/cloud/occi/lib/ui/public/js/plugins/images-tab.js deleted file mode 100644 index e17394b194..0000000000 --- a/src/cloud/occi/lib/ui/public/js/plugins/images-tab.js +++ /dev/null @@ -1,1060 +0,0 @@ -/* -------------------------------------------------------------------------- */ -/* 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. */ -/* -------------------------------------------------------------------------- */ - -/*Images tab plugin*/ - -var images_tab_content = -'
\ -
\ -
\ -\ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ -
'+tr("All")+''+tr("ID")+''+tr("Owner")+''+tr("Group")+''+tr("Name")+''+tr("Size")+''+tr("Type")+''+tr("Registration time")+''+tr("Public")+''+tr("Persistent")+''+tr("Status")+''+tr("#VMS")+'
\ -
'; - -var create_image_tmpl = -'
\ - \ -
\ -
\ -

'+ - tr("Fields marked with")+' '+ - tr("are mandatory")+'
\ -

\ -
\ - \ - \ -
'+tr("Name that the Image will get. Every image must have a unique name.")+'
\ -
\ -
\ - \ - \ -
'+tr("Human readable description of the image for other users.")+'
\ -
\ -
\ -
\ -
\ - \ - \ -
'+tr("Type of the image, explained in detail in the following section. If omitted, the default value is the one defined in oned.conf (install default is OS).")+'
\ -
\ -
\ - \ - \ -
'+tr("Public scope of the image")+'
\ -
\ -
\ - \ - \ -
'+tr("Persistence of the image")+'
\ -
\ -
\ - \ - \ -
'+tr("Prefix for the emulated device this image will be mounted at. For instance, “hd”, “sd”. If omitted, the default value is the one defined in oned.conf (installation default is “hd”).")+'
\ -
\ -
\ - \ - \ -
'+tr("Type of disk device to emulate.")+'
\ -
\ -
\ - \ - \ -
'+tr("Specific image mapping driver. KVM: raw, qcow2. XEN: tap:aio, file:")+'
\ -
\ -
\ -
\ -
\ - \ - \ -
\ - \ -
\ - \ - \ -
'+tr("Please choose path if you have a file-based image. Choose source otherwise or create an empty datablock disk.")+'

\ -
\ -
\ - \ - \ -
'+tr("Path to the original file that will be copied to the image repository. If not specified for a DATABLOCK type image, an empty image will be created.")+'
\ -
\ -
\ - \ - \ -
'+tr("Source to be used in the DISK attribute. Useful for not file-based images.")+'
\ -
\ -
\ - \ - \ -
'+tr("Size of the datablock in MB.")+'
\ -
\ -
\ - \ - \ -
'+tr("Type of file system to be built. This can be any value understood by mkfs unix command.")+'
\ -
\ -
\ -
\ -
\ - \ - \ - \ - \ - \ - \ -
\ - \ - \ -
\ -
\ -
\ -
\ - \ - \ -
\ -
\ -
\ -
\ -
\ -
\ -
\ -

'+tr("Write the image template here")+'

\ - \ -
\ -
\ -
\ - \ - \ -
\ -
\ -
\ -
\ -
'; - -var update_image_tmpl = - '
\ -

'+tr("Please, choose and modify the image you want to update")+':

\ -
\ - \ - \ -
\ -
\ - \ - \ -
\ -
\ - \ - \ -
\ - \ -
\ - \ -
\ -
\ -
\ - \ -
\ -
\ -
'; - -var dataTable_images; -var $create_image_dialog; - -var image_actions = { - - "Image.create" : { - type: "create", - call: OpenNebula.Image.create, - callback: addImageElement, - error: onError, - notify:true - }, - - "Image.create_dialog" : { - type: "custom", - call: popUpCreateImageDialog - }, - - "Image.list" : { - type: "list", - call: OpenNebula.Image.list, - callback: updateImagesView, - error: onError - }, - - "Image.show" : { - type : "single", - call: OpenNebula.Image.show, - callback: updateImageElement, - error: onError - }, - - "Image.showinfo" : { - type: "single", - call: OpenNebula.Image.show, - callback: updateImageInfo, - error: onError - }, - - "Image.refresh" : { - type: "custom", - call: function () { - waitingNodes(dataTable_images); - Sunstone.runAction("Image.list"); - }, - }, - - "Image.autorefresh" : { - type: "custom", - call: function() { - OpenNebula.Image.list({timeout: true, success: updateImagesView, error: onError}); - } - }, - - "Image.fetch_template" : { - type: "single", - call: OpenNebula.Image.fetch_template, - callback: function (request,response) { - $('#image_template_update_dialog #image_template_update_textarea').val(response.template); - }, - error: onError - }, - - "Image.update_dialog" : { - type: "custom", - call: function() { - popUpImageTemplateUpdateDialog(); - } - }, - - "Image.update" : { - type: "single", - call: OpenNebula.Image.update, - callback: function() { - notifyMessage(tr("Template updated correctly")); - }, - error: onError - }, - - "Image.enable" : { - type: "multiple", - call: OpenNebula.Image.enable, - callback: function (req) { - Sunstone.runAction("Image.show",req.request.data[0]); - }, - elements: imageElements, - error: onError, - notify: true - }, - - "Image.disable" : { - type: "multiple", - call: OpenNebula.Image.disable, - callback: function (req) { - Sunstone.runAction("Image.show",req.request.data[0]); - }, - elements: imageElements, - error: onError, - notify: true - }, - - "Image.persistent" : { - type: "multiple", - call: OpenNebula.Image.persistent, - callback: function (req) { - Sunstone.runAction("Image.show",req.request.data[0]); - }, - elements: imageElements, - error: onError, - notify: true - }, - - "Image.nonpersistent" : { - type: "multiple", - call: OpenNebula.Image.nonpersistent, - callback: function (req) { - Sunstone.runAction("Image.show",req.request.data[0]); - }, - elements: imageElements, - error: onError, - notify: true - }, - - "Image.publish" : { - type: "multiple", - call: OpenNebula.Image.publish, - callback: function (req) { - Sunstone.runAction("Image.show",req.request.data[0]); - }, - elements: imageElements, - error: onError, - notify: true - }, - - "Image.unpublish" : { - type: "multiple", - call: OpenNebula.Image.unpublish, - callback: function (req) { - Sunstone.runAction("Image.show",req.request.data[0]); - }, - elements: imageElements, - error: onError, - notify: true - }, - - "Image.delete" : { - type: "multiple", - call: OpenNebula.Image.delete, - callback: deleteImageElement, - elements: imageElements, - error: onError, - notify: true - }, - - "Image.chown" : { - type: "multiple", - call: OpenNebula.Image.chown, - callback: function (req) { - Sunstone.runAction("Image.show",req.request.data[0]); - }, - elements: imageElements, - error: onError, - notify: true - }, - - "Image.chgrp" : { - type: "multiple", - call: OpenNebula.Image.chgrp, - callback: function (req) { - Sunstone.runAction("Image.show",req.request.data[0]); - }, - elements: imageElements, - error: onError, - notify: true - }, - - "Image.chtype" : { - type: "single", - call: OpenNebula.Image.chtype, - callback: function (req) { - Sunstone.runAction("Image.show",req.request.data[0]); - }, - elements: imageElements, - error: onError, - notify: true - } - -} - - -var image_buttons = { - "Image.refresh" : { - type: "image", - text: tr("Refresh list"), - img: "images/Refresh-icon.png" - }, - "Image.create_dialog" : { - type: "create_dialog", - text: tr('+ New') - }, - "Image.update_dialog" : { - type: "action", - text: tr("Update a template"), - alwaysActive: true - }, - "Image.chown" : { - type: "confirm_with_select", - text: tr("Change owner"), - select: users_sel, - tip: tr("Select the new owner")+":", - condition: mustBeAdmin - }, - "Image.chgrp" : { - type: "confirm_with_select", - text: tr("Change group"), - select: groups_sel, - tip: tr("Select the new group")+":", - condition: mustBeAdmin - }, - "action_list" : { - type: "select", - actions: { - "Image.enable" : { - type: "action", - text: tr("Enable") - }, - "Image.disable" : { - type: "action", - text: tr("Disable") - }, - "Image.publish" : { - type: "action", - text: tr("Publish") - }, - "Image.unpublish" : { - type: "action", - text: tr("Unpublish") - }, - "Image.persistent" : { - type: "action", - text: tr("Make persistent") - }, - "Image.nonpersistent" : { - type: "action", - text: tr("Make non persistent") - } - } - }, - "Image.delete" : { - type: "action", - text: tr("Delete") - } -} - -var image_info_panel = { - "image_info_tab" : { - title: tr("Image information"), - content: "" - }, - - "image_template_tab" : { - title: tr("Image template"), - content: "" - } - -} - -var images_tab = { - title: tr("Images"), - content: images_tab_content, - buttons: image_buttons -} - -Sunstone.addActions(image_actions); -Sunstone.addMainTab('images_tab',images_tab); -Sunstone.addInfoPanel('image_info_panel',image_info_panel); - - -function imageElements() { - return getSelectedNodes(dataTable_images); -} - -// Returns an array containing the values of the image_json and ready -// to be inserted in the dataTable -function imageElementArray(image_json){ - //Changing this? It may affect to the is_public() and is_persistent() functions. - var image = image_json.IMAGE; - - var type = $(''); - - var value = OpenNebula.Helper.image_type(image.TYPE); - $('option[value="'+value+'"]',type).replaceWith(''); - - - - return [ - '', - image.ID, - image.UNAME, - image.GNAME, - image.NAME, - image.SIZE, - '', - pretty_time(image.REGTIME), - parseInt(image.PUBLIC) ? '' - : '', - parseInt(image.PERSISTENT) ? '' - : '', - OpenNebula.Helper.resource_state("image",image.STATE), - image.RUNNING_VMS - ]; -} - -// Set up the listener on the table TDs to show the info panel -function imageInfoListener(){ - $('#tbodyimages tr',dataTable_images).live("click",function(e){ - var target = $(e.target); - - if (target.is('input') || target.is('select') || target.is('option')) - return true; - - popDialogLoading(); - var aData = dataTable_images.fnGetData(this); - var id = $(aData[0]).val(); - Sunstone.runAction("Image.showinfo",id); - return false; - }); -} - -// Callback to update an element in the dataTable -function updateImageElement(request, image_json){ - var id = image_json.IMAGE.ID; - var element = imageElementArray(image_json); - updateSingleElement(element,dataTable_images,'#image_'+id); -} - -// Callback to remove an element from the dataTable -function deleteImageElement(req){ - deleteElement(dataTable_images,'#image_'+req.request.data); -} - -// Callback to add an image element -function addImageElement(request, image_json){ - var element = imageElementArray(image_json); - addElement(element,dataTable_images); -} - -// Callback to refresh the list of images -function updateImagesView(request, images_list){ - var image_list_array = []; - - $.each(images_list,function(){ - image_list_array.push(imageElementArray(this)); - }); - - updateView(image_list_array,dataTable_images); - updateDashboard("images",images_list); -} - -// Callback to update the information panel tabs and pop it up -function updateImageInfo(request,img){ - var img_info = img.IMAGE; - var info_tab = { - title: tr("Image information"), - content: - '\ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ -
'+tr("Image")+' "'+img_info.NAME+'" '+ - tr("information")+'
'+tr("ID")+''+img_info.ID+'
'+tr("Name")+''+img_info.NAME+'
'+tr("Owner")+''+img_info.UNAME+'
'+tr("Group")+''+img_info.GNAME+'
'+tr("Type")+''+OpenNebula.Helper.image_type(img_info.TYPE)+'
'+tr("Register time")+''+pretty_time(img_info.REGTIME)+'
'+tr("Public")+''+(parseInt(img_info.PUBLIC) ? tr("yes") : tr("no"))+'
'+tr("Persistent")+''+(parseInt(img_info.PERSISTENT) ? tr("yes") : tr("no"))+'
'+tr("Source")+''+(typeof img_info.SOURCE === "string" ? img_info.SOURCE : "--")+'
'+tr("Path")+''+(typeof img_info.PATH === "string" ? img_info.PATH : "--")+'
'+tr("Filesystem type")+''+(typeof img_info.FSTYPE === "string" ? img_info.FSTYPE : "--")+'
'+tr("Size (Mb)")+''+img_info.SIZE+'
'+tr("State")+''+OpenNebula.Helper.resource_state("image",img_info.STATE)+'
'+tr("Running #VMS")+''+img_info.RUNNING_VMS+'
' - } - - var template_tab = { - title: tr("Image template"), - content: '\ - '+ - prettyPrintJSON(img_info.TEMPLATE)+ - '
'+tr("Image template")+'
' - } - - Sunstone.updateInfoPanelTab("image_info_panel","image_info_tab",info_tab); - Sunstone.updateInfoPanelTab("image_info_panel","image_template_tab",template_tab); - - Sunstone.popUpInfoPanel("image_info_panel"); - -} - -// Prepare the image creation dialog -function setupCreateImageDialog(){ - dialogs_context.append('
'); - $create_image_dialog = $('#create_image_dialog',dialogs_context); - var dialog = $create_image_dialog; - dialog.html(create_image_tmpl); - - var height = Math.floor($(window).height()*0.8); //set height to a percentage of the window - - //Prepare jquery dialog - dialog.dialog({ - autoOpen: false, - modal:true, - width: 520, - height: height - }); - - $('#img_tabs',dialog).tabs(); - $('button',dialog).button(); - $('#img_type option',dialog).first().attr('selected','selected'); - $('#datablock_img',dialog).attr('disabled','disabled'); - - $('select#img_type',dialog).change(function(){ - var value = $(this).val(); - var context = $create_image_dialog; - switch (value){ - case "DATABLOCK": - $('#datablock_img',context).removeAttr("disabled"); - break; - default: - $('#datablock_img',context).attr('disabled','disabled'); - $('#path_img',context).attr('checked','checked'); - $('#img_source,#img_fstype,#img_size',context).parent().hide(); - $('#img_path',context).parent().show(); - } - }); - - $('#img_source,#img_fstype,#img_size',dialog).parent().hide(); - $('#path_img',dialog).attr('checked','checked'); - $('#img_path',dialog).parent().addClass("img_man"); - - $('#img_public',dialog).click(function(){ - $('#img_persistent',$create_image_dialog).removeAttr('checked'); - }); - - $('#img_persistent',dialog).click(function(){ - $('#img_public',$create_image_dialog).removeAttr('checked'); - }); - - - - $('#src_path_select input').click(function(){ - var context = $create_image_dialog; - var value = $(this).val(); - switch (value){ - case "path": - $('#img_source,#img_fstype,#img_size',context).parent().hide(); - $('#img_source,#img_fstype,#img_size',context).parent().removeClass("img_man"); - $('#img_path',context).parent().show(); - $('#img_path',context).parent().addClass("img_man"); - break; - case "source": - $('#img_path,#img_fstype,#img_size',context).parent().hide(); - $('#img_path,#img_fstype,#img_size',context).parent().removeClass("img_man"); - $('#img_source',context).parent().show(); - $('#img_source',context).parent().addClass("img_man"); - break; - case "datablock": - $('#img_source,#img_path',context).parent().hide(); - $('#img_source,#img_path',context).parent().removeClass("img_man"); - $('#img_fstype,#img_size',context).parent().show(); - $('#img_fstype,#img_size',context).parent().addClass("img_man"); - break; - } - }); - - - $('#add_custom_var_image_button', dialog).click( - function(){ - var name = $('#custom_var_image_name',$create_image_dialog).val(); - var value = $('#custom_var_image_value',$create_image_dialog).val(); - if (!name.length || !value.length) { - notifyError(tr("Custom attribute name and value must be filled in")); - return false; - } - option= ''; - $('select#custom_var_image_box',$create_image_dialog).append(option); - return false; - } - ); - - $('#remove_custom_var_image_button', dialog).click( - function(){ - $('select#custom_var_image_box :selected',$create_image_dialog).remove(); - return false; - } - ); - - - $('#create_image_form_easy',dialog).submit(function(){ - var exit = false; - $('.img_man',this).each(function(){ - if (!$('input',this).val().length){ - notifyError(tr("There are mandatory parameters missing")); - exit = true; - return false; - } - }); - if (exit) { return false; } - var img_json = {}; - - var name = $('#img_name',this).val(); - img_json["NAME"] = name; - - var desc = $('#img_desc',this).val(); - if (desc.length){ - img_json["DESCRIPTION"] = desc; - } - - var type = $('#img_type',this).val(); - img_json["TYPE"]= type; - - img_json["PUBLIC"] = $('#img_public:checked',this).length ? "YES" : "NO"; - - img_json["PERSISTENT"] = $('#img_persistent:checked',this).length ? "YES" : "NO"; - - var dev_prefix = $('#img_dev_prefix',this).val(); - if (dev_prefix.length){ - img_json["DEV_PREFIX"] = dev_prefix; - } - - var bus = $('#img_bus',this).val(); - img_json["BUS"] = bus; - - var driver = $('#img_driver',this).val(); - if (driver.length) - img_json["DRIVER"] = driver; - - switch ($('#src_path_select input:checked',this).val()){ - case "path": - path = $('#img_path',this).val(); - img_json["PATH"] = path; - break; - case "source": - source = $('#img_source',this).val(); - img_json["SOURCE"] = source; - break; - case "datablock": - size = $('#img_size',this).val(); - fstype = $('#img_fstype',this).val(); - img_json["SIZE"] = size; - img_json["FSTYPE"] = fstype; - break; - } - - //Time to add custom attributes - $('#custom_var_image_box option',$create_image_dialog).each(function(){ - var attr_name = $(this).attr('name'); - var attr_value = $(this).val(); - img_json[attr_name] = attr_value; - }); - - - var obj = { "image" : img_json }; - Sunstone.runAction("Image.create", obj); - - $create_image_dialog.dialog('close'); - return false; - }); - - $('#create_image_form_manual',dialog).submit(function(){ - var template=$('#template',this).val(); - Sunstone.runAction("Image.create",template); - $create_image_dialog.dialog('close'); - return false; - }); -} - -function popUpCreateImageDialog(){ - $create_image_dialog.dialog('open'); -} - - - -function setupImageTemplateUpdateDialog(){ - - //Append to DOM - dialogs_context.append('
'); - var dialog = $('#image_template_update_dialog',dialogs_context); - - //Put HTML in place - dialog.html(update_image_tmpl); - - //Convert into jQuery - dialog.dialog({ - autoOpen:false, - width:700, - modal:true, - height:480, - resizable:false, - }); - - $('button',dialog).button(); - - $('#image_template_update_select',dialog).change(function(){ - var id = $(this).val(); - if (id && id.length){ - var dialog = $('#image_template_update_dialog'); - $('#image_template_update_textarea',dialog).val(tr("Loading")+ - "..."); - - var img_public = is_public_image(id); - var img_persistent = is_persistent_image(id) - - if (img_public){ - $('#image_template_update_public',dialog).attr('checked','checked') - } else { - $('#image_template_update_public',dialog).removeAttr('checked') - } - - if (img_persistent){ - $('#image_template_update_persistent',dialog).attr('checked','checked') - } else { - $('#image_template_update_persistent',dialog).removeAttr('checked') - } - - Sunstone.runAction("Image.fetch_template",id); - } else { - $('#image_template_update_textarea',dialog).val(""); - }; - }); - - $('#image_template_update_button',dialog).click(function(){ - var dialog = $('#image_template_update_dialog'); - var new_template = $('#image_template_update_textarea',dialog).val(); - var id = $('#image_template_update_select',dialog).val(); - if (!id || !id.length) { - dialog.dialog('close'); - return false; - }; - - var old_public = is_public_image(id) - var old_persistent = is_persistent_image(id); - - var new_public = $('#image_template_update_public:checked',dialog).length; - var new_persistent = $('#image_template_update_persistent:checked',dialog).length; - - if (old_public != new_public){ - if (new_public) Sunstone.runAction("Image.publish",id); - else Sunstone.runAction("Image.unpublish",id); - }; - - if (old_persistent != new_persistent){ - if (new_persistent) Sunstone.runAction("Image.persistent",id); - else Sunstone.runAction("Image.nonpersistent",id); - }; - - Sunstone.runAction("Image.update",id,new_template); - dialog.dialog('close'); - return false; - }); -} - - -function popUpImageTemplateUpdateDialog(){ - var select = makeSelectOptions(dataTable_images, - 1,//id_col - 4,//name_col - [], - [] - ); - var sel_elems = getSelectedNodes(dataTable_images); - - - var dialog = $('#image_template_update_dialog'); - $('#image_template_update_select',dialog).html(select); - $('#image_template_update_textarea',dialog).val(""); - $('#image_template_update_public',dialog).removeAttr('checked') - $('#image_template_update_persistent',dialog).removeAttr('checked') - - if (sel_elems.length >= 1){ //several items in the list are selected - //grep them - var new_select= sel_elems.length > 1? '' : ""; - $('option','').each(function(){ - var val = $(this).val(); - if ($.inArray(val,sel_elems) >= 0){ - new_select+=''; - }; - }); - $('#image_template_update_select',dialog).html(new_select); - if (sel_elems.length == 1) { - $('#image_template_update_select option',dialog).attr('selected','selected'); - $('#image_template_update_select',dialog).trigger("change"); - } - - }; - - dialog.dialog('open'); - return false; - -} - -// Set the autorefresh interval for the datatable -function setImageAutorefresh() { - setInterval(function(){ - var checked = $('input.check_item:checked',dataTable_images); - var filter = $("#datatable_images_filter input", - dataTable_images.parents("#datatable_images_wrapper")).attr('value'); - if (!checked.length && !filter.length){ - Sunstone.runAction("Image.autorefresh"); - } - },INTERVAL+someTime()); -}; - -function is_public_image(id){ - var data = getElementData(id,"#image",dataTable_images)[7]; - return $(data).attr('checked'); -}; - -function is_persistent_image(id){ - var data = getElementData(id,"#image",dataTable_images)[8]; - return $(data).attr('checked'); -}; - -function setupImageActionCheckboxes(){ - $('input.action_cb#cb_public_image',dataTable_images).live("click",function(){ - var $this = $(this) - var id=$this.attr('elem_id'); - if ($this.attr('checked')){ - if (!is_persistent_image(id)) - Sunstone.runAction("Image.publish",id); - else { - notifyError(tr("Image cannot be public and persistent")); - return false; - }; - } else Sunstone.runAction("Image.unpublish",id); - - return true; - }); - - $('input.action_cb#cb_persistent_image',dataTable_images).live("click",function(){ - var $this = $(this) - var id=$this.attr('elem_id'); - if ($this.attr('checked')){ - if (!is_public_image(id)) - Sunstone.runAction("Image.persistent",id); - else { - notifyError(tr("Image cannot be public and persistent")); - return false; - }; - } else Sunstone.runAction("Image.nonpersistent",id); - - return true; - }); - - $('select.action_cb#select_chtype_image', dataTable_images).live("change",function(){ - var $this = $(this); - var value = $this.val(); - var id = $this.attr('elem_id'); - - Sunstone.runAction("Image.chtype", id, value); - }); - -} - -//The DOM is ready at this point -$(document).ready(function(){ - - dataTable_images = $("#datatable_images",main_tabs_context).dataTable({ - "bJQueryUI": true, - "bSortClasses": false, - "bAutoWidth":false, - "sPaginationType": "full_numbers", - "aoColumnDefs": [ - { "bSortable": false, "aTargets": ["check"] }, - { "sWidth": "60px", "aTargets": [0,2,3,8,9,10] }, - { "sWidth": "35px", "aTargets": [1,5,11] }, - { "sWidth": "100px", "aTargets": [6] }, - { "sWidth": "150px", "aTargets": [7] } - ], - "oLanguage": (datatable_lang != "") ? - { - sUrl: "locale/"+lang+"/"+datatable_lang - } : "" - }); - - dataTable_images.fnClearTable(); - addElement([ - spinner, - '','','','','','','','','','',''],dataTable_images); - Sunstone.runAction("Image.list"); - - setupCreateImageDialog(); - setupImageTemplateUpdateDialog(); - setupTips($create_image_dialog); - setupImageActionCheckboxes(); - setImageAutorefresh(); - - initCheckAllBoxes(dataTable_images); - tableCheckboxesListener(dataTable_images); - imageInfoListener(); - - -}) diff --git a/src/cloud/occi/lib/ui/public/js/plugins/network.js b/src/cloud/occi/lib/ui/public/js/plugins/network.js new file mode 100644 index 0000000000..1a759b663f --- /dev/null +++ b/src/cloud/occi/lib/ui/public/js/plugins/network.js @@ -0,0 +1,446 @@ +/* -------------------------------------------------------------------------- */ +/* 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. */ +/* -------------------------------------------------------------------------- */ + +/*Virtual networks tab plugin*/ + +var vnets_tab_content = +'
\ +
\ +
\ +\ + \ + \ + \ + \ + \ + \ + \ + \ + \ +
'+tr("All")+''+tr("ID")+''+tr("Name")+'
\ +
'; + +var create_vn_tmpl = +'
\ +
\ +
\ +
\ + \ +
\ +
\ +
\ +
\ +
\ + \ +
\ + \ +
\ +
\ +
\ +
\ + \ +
\ +
\ +
\ +
\ +
'; + + +var vnet_dashboard = '
\ +one-network\ +

'+tr("In this view you can easily manage OpenNebula Network resources. You can add, remove, publish or unpublish virtual networks.")+'

\ +

'+tr("Compute resources can be attached to these networks at creation time. Virtual machines will be provided with an IP and the correct parameters to ensure connectivity.")+'

\ +

'+tr("There are currently")+' '+tr("networks")+'.

\ +
'; + +var dataTable_vNetworks; +var $create_vn_dialog; + +//Setup actions + +var vnet_actions = { + "Network.create" : { + type: "create", + call: OCCI.Network.create, + callback: addVNetworkElement, + error: onError, + notify: true + }, + + "Network.create_dialog" : { + type: "custom", + call: popUpCreateVnetDialog + }, + + "Network.list" : { + type: "list", + call: OCCI.Network.list, + callback: updateVNetworksView, + error: onError + }, + + "Network.show" : { + type: "single", + call: OCCI.Network.show, + callback: updateVNetworkElement, + error: onError + }, + + "Network.showinfo" : { + type: "single", + call: OCCI.Network.show, + callback: updateVNetworkInfo, + error: onError + + }, + + "Network.refresh" : { + type: "custom", + call: function(){ + waitingNodes(dataTable_vNetworks); + Sunstone.runAction("Network.list"); + } + }, + + "Network.autorefresh" : { + type: "custom", + call: function() { + OCCI.Network.list({timeout: true, success: updateVNetworksView, error: onError}); + } + }, + + "Network.publish" : { + type: "multiple", + call: OCCI.Network.publish, + callback: vnShow, + elements: vnElements, + error: onError, + notify: true + }, + + "Network.unpublish" : { + type: "multiple", + call: OCCI.Network.unpublish, + callback: vnShow, + elements: vnElements, + error: onError, + notify: true + }, + + "Network.delete" : { + type: "multiple", + call: OCCI.Network.delete, + callback: deleteVNetworkElement, + elements: vnElements, + error: onError, + notify: true + }, +}; + + +var vnet_buttons = { + "Network.refresh" : { + type: "image", + text: tr("Refresh list"), + img: "images/Refresh-icon.png" + }, + + "Network.create_dialog" : { + type: "create_dialog", + text: tr("+ New") + }, + + "Network.publish" : { + type: "action", + text: tr("Publish") + }, + + "Network.unpublish" : { + type: "action", + text: tr("Unpublish") + }, + + "Network.delete" : { + type: "action", + text: tr("Delete") + } +} + +var vnet_info_panel = { + "vnet_info_tab" : { + title: tr("Network information"), + content: "" + }, +} + + +var vnet_create_panel = { + "vnet_create_panel" : { + title: tr("Create network"), + content: create_vn_tmpl + }, +} + +var vnets_tab = { + title: tr("Networks"), + content: vnets_tab_content, + buttons: vnet_buttons +} + +Sunstone.addActions(vnet_actions); +Sunstone.addMainTab('vnets_tab',vnets_tab); +Sunstone.addInfoPanel('vnet_info_panel',vnet_info_panel); +Sunstone.addInfoPanel('vnet_create_panel',vnet_create_panel); + + +function vnElements(){ + return getSelectedNodes(dataTable_vNetworks); +} + +function vnShow(req){ + //Sunstone.runAction("Network.show",req.request.data[0]); +} + +//returns an array with the VNET information fetched from the JSON object +function vNetworkElementArray(vn_json){ + var network = vn_json.NETWORK; + + if (network.name){ + id = network.href.split("/"); + id = id[id.length-1]; + name = network.name; + } + else { + id = network.ID; + name = network.NAME; + }; + + return [ + '', + id, + name + ]; +}; + + +//Adds a listener to show the extended info when clicking on a row +function vNetworkInfoListener(){ + + $('#tbodyvnetworks tr',dataTable_vNetworks).live("click", function(e){ + if ($(e.target).is('input')) {return true;} + popDialogLoading(); + var aData = dataTable_vNetworks.fnGetData(this); + var id = $(aData[0]).val(); + Sunstone.runAction("Network.showinfo",id); + return false; + }); +} + +//Callback to update a vnet element after an action on it +function updateVNetworkElement(request, vn_json){ + id = vn_json.NETWORK.ID; + element = vNetworkElementArray(vn_json); + updateSingleElement(element,dataTable_vNetworks,'#vnetwork_'+id); +} + +//Callback to delete a vnet element from the table +function deleteVNetworkElement(req){ + deleteElement(dataTable_vNetworks,'#vnetwork_'+req.request.data); +} + +//Callback to add a new element +function addVNetworkElement(request,vn_json){ + var element = vNetworkElementArray(vn_json); + addElement(element,dataTable_vNetworks); +} + +//updates the list of virtual networks +function updateVNetworksView(request, network_list){ + var network_list_array = []; + + $.each(network_list,function(){ + network_list_array.push(vNetworkElementArray(this)); + }); + + updateView(network_list_array,dataTable_vNetworks); + //dependency with dashboard + //updateDashboard("vnets",network_list); + +} + +//updates the information panel tabs and pops the panel up +function updateVNetworkInfo(request,vn){ + var vn_info = vn.NETWORK; + var info_tab_content = + '\ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ +
'+tr("Virtual Network")+' '+vn_info.ID+' '+ + tr("information")+'
'+tr("ID")+''+vn_info.ID+'
'+tr("Name")+''+vn_info.NAME+'
'+tr("Public")+''+ vn_info.PUBLIC.toLowerCase() +'
\ +
\ +
'; + + var info_tab = { + title: tr("Virtual Network information"), + content: info_tab_content + }; + + Sunstone.updateInfoPanelTab("vnet_info_panel","vnet_info_tab",info_tab); + + Sunstone.popUpInfoPanel("vnet_info_panel"); + $('#dialog .vnet_close_dialog_link').button({ + text:false, + icons: { primary: "ui-icon-closethick" } + }); + +} + +function popUpCreateVnetDialog() { + //$create_vn_dialog.dialog('open'); + //Handle submission of the easy mode + Sunstone.popUpInfoPanel("vnet_create_panel"); + var dialog=$('#dialog'); + $create_vn_dialog = dialog; + + $('#create_vn',dialog).button({ + icons: { + primary: "ui-icon-check" + }, + text: false + }); + $('#reset_vn',dialog).button({ + icons: { + primary: "ui-icon-document" + }, + text: false + }); + $('.vnet_close_dialog_link',dialog).button({ + icons: { + primary: "ui-icon-closethick" + }, + text: false + }); + + $('#create_vn_form_easy',dialog).submit(function(){ + //Fetch values + var name = $('#name',this).val(); + if (!name.length){ + notifyError(tr("Virtual Network name missing!")); + return false; + } + var bridge = $('#bridge',this).val(); + + //TODO: Name and bridge provided?! + + var network_json = null; + var network_addr = $('#net_address',this).val(); + var network_size = $('#net_size',this).val(); + + if (!network_addr.length){ + notifyError(tr("Please provide a network address")); + return false; + }; + + //we form the object for the request + network_json = { + "SIZE" : network_size, + "ADDRESS" : network_addr, + "NAME" : name + }; + + Sunstone.runAction("Network.create",network_json); + popUpVNetDashboard(); + return false; + }); + +} + +function popUpVNetDashboard(){ + var count = dataTable_vNetworks.fnGetNodes().length; + popDialog(vnet_dashboard); + $('#dialog #vnet_dashboard_count').text(count); +} + +function setVNetAutorefresh() { + setInterval(function(){ + var checked = $('input.check_item:checked',dataTable_vNetworks); + var filter = $("#datatable_vnetworks_filter input", + dataTable_vNetworks.parents("#datatable_vnetworks_wrapper")).attr('value'); + if (!checked.length && !filter.length){ + Sunstone.runAction("Network.autorefresh"); + } + },INTERVAL+someTime()); +}; + +//The DOM is ready and the ready() from sunstone.js +//has been executed at this point. +$(document).ready(function(){ + + dataTable_vNetworks = $("#datatable_vnetworks",main_tabs_context).dataTable({ + "bJQueryUI": true, + "bSortClasses": false, + "bAutoWidth":false, + "sPaginationType": "full_numbers", + "aoColumnDefs": [ + { "bSortable": false, "aTargets": ["check"] }, + { "sWidth": "60px", "aTargets": [0] }, + { "sWidth": "35px", "aTargets": [1] }, + ], + "oLanguage": (datatable_lang != "") ? + { + sUrl: "locale/"+lang+"/"+datatable_lang + } : "" + }); + + dataTable_vNetworks.fnClearTable(); + addElement([ + spinner, + '',''],dataTable_vNetworks); + Sunstone.runAction("Network.list"); + + setVNetAutorefresh(); + + initCheckAllBoxes(dataTable_vNetworks); + tableCheckboxesListener(dataTable_vNetworks); + vNetworkInfoListener(); + + $('#li_vnets_tab a').click(function(){ + popUpVNetDashboard(); + //return false; + }); + + $('.vnet_close_dialog_link').live("click",function(){ + popUpVNetDashboard(); + return false; + }); + +}); diff --git a/src/cloud/occi/lib/ui/public/js/plugins/storage.js b/src/cloud/occi/lib/ui/public/js/plugins/storage.js new file mode 100644 index 0000000000..e710d1fd0b --- /dev/null +++ b/src/cloud/occi/lib/ui/public/js/plugins/storage.js @@ -0,0 +1,646 @@ +/* -------------------------------------------------------------------------- */ +/* Copyright 2002-2011, OpenNebula Project Leads (OCCI.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. */ +/* -------------------------------------------------------------------------- */ + +/*Images tab plugin*/ + +var images_tab_content = +'
\ +
\ +
\ +\ + \ + \ + \ + \ + \ + \ + \ + \ + \ +
'+tr("All")+''+tr("ID")+''+tr("Name")+'
\ +
'; + +var create_image_tmpl = +'
\ +
\ +
\ +

'+ + tr("Fields marked with")+' '+ + tr("are mandatory")+'
\ +

\ +
\ + \ + \ +
'+tr("Name that the Image will get. Every image must have a unique name.")+'
\ +
\ +
\ + \ + \ +
'+tr("Human readable description of the image for other users.")+'
\ +
\ +
\ +
\ +
\ + \ + \ +
'+tr("Type of the image, explained in detail in the following section. If omitted, the default value is the one defined in oned.conf (install default is OS).")+'
\ +
\ +
\ + \ + \ +
'+tr("Size of the datablock in MB.")+'
\ +
\ +
\ + \ + \ +
'+tr("Type of file system to be built. This can be any value understood by mkfs unix command.")+'
\ +
\ +
\ + \ +
\ +
\ + \ +
\ +
\ +\ +
\ +
\ + \ +
\ +
'; + +var image_dashboard = '
\ +one-storage\ +

'+tr("The Storage view offers you an overview of your current images. Storage elements are attached to compute resources at creation time. They can also be extracted from running virtual machines by taking an snapshot.")+'

\ +

'+tr("You can add new storages by clicking \"new\". Image files will be uploaded to OpenNebula and set ready to be used.")+'

\ +

'+tr("Additionally, you can run several operations on defined storages, such as defining their persistance. Persistent images can only be used by 1 virtual machine, and the changes made by it have effect on the base image. Non-persistent images are cloned before being used in a Virtual Machine, therefore changes are lost unless a snapshot is taken prior to Virtual Machine shutdown.")+'

\ +

'+tr("There are currently")+' '+tr("images")+'.

\ +
'; + +var dataTable_images; +var $create_image_dialog; + +var image_actions = { + + "Image.create" : { + type: "create", + call: OCCI.Image.create, + callback: addImageElement, + error: onError, + notify:true + }, + + "Image.create_dialog" : { + type: "custom", + call: popUpCreateImageDialog + }, + + "Image.list" : { + type: "list", + call: OCCI.Image.list, + callback: updateImagesView, + error: onError + }, + + "Image.show" : { + type : "single", + call: OCCI.Image.show, + callback: updateImageElement, + error: onError + }, + + "Image.showinfo" : { + type: "single", + call: OCCI.Image.show, + callback: updateImageInfo, + error: onError + }, + + "Image.refresh" : { + type: "custom", + call: function () { + waitingNodes(dataTable_images); + Sunstone.runAction("Image.list"); + }, + }, + + "Image.autorefresh" : { + type: "custom", + call: function() { + OCCI.Image.list({timeout: true, success: updateImagesView, error: onError}); + } + }, + + "Image.persistent" : { + type: "multiple", + call: OCCI.Image.persistent, + callback: function (req) { + //Sunstone.runAction("Image.show",req.request.data[0]); + }, + elements: imageElements, + error: onError, + notify: true + }, + + "Image.nonpersistent" : { + type: "multiple", + call: OCCI.Image.nonpersistent, + callback: function (req) { + //Sunstone.runAction("Image.show",req.request.data[0]); + }, + elements: imageElements, + error: onError, + notify: true + }, + + "Image.publish" : { + type: "multiple", + call: OCCI.Image.publish, + callback: function (req) { + //Sunstone.runAction("Image.show",req.request.data[0]); + }, + elements: imageElements, + error: onError, + notify: true + }, + + "Image.unpublish" : { + type: "multiple", + call: OCCI.Image.unpublish, + callback: function (req) { + //Sunstone.runAction("Image.show",req.request.data[0]); + }, + elements: imageElements, + error: onError, + notify: true + }, + + "Image.delete" : { + type: "multiple", + call: OCCI.Image.delete, + callback: deleteImageElement, + elements: imageElements, + error: onError, + notify: true + }, +} + + +var image_buttons = { + "Image.refresh" : { + type: "image", + text: tr("Refresh list"), + img: "images/Refresh-icon.png" + }, + "Image.create_dialog" : { + type: "create_dialog", + text: tr('+ New') + }, + "Image.update_dialog" : { + type: "action", + text: tr("Update a template"), + alwaysActive: true + }, + "action_list" : { + type: "select", + actions: { + "Image.publish" : { + type: "action", + text: tr("Publish") + }, + "Image.unpublish" : { + type: "action", + text: tr("Unpublish") + }, + "Image.persistent" : { + type: "action", + text: tr("Make persistent") + }, + "Image.nonpersistent" : { + type: "action", + text: tr("Make non persistent") + } + } + }, + "Image.delete" : { + type: "action", + text: tr("Delete") + } +} + +var image_info_panel = { + "image_info_tab" : { + title: tr("Image information"), + content: "" + }, + +}; + +var image_create_panel = { + "image_create_panel" : { + title: tr("Add storage"), + content: create_image_tmpl + }, +}; + +var images_tab = { + title: tr("Storage"), + content: images_tab_content, + buttons: image_buttons +} + +Sunstone.addActions(image_actions); +Sunstone.addMainTab('images_tab',images_tab); +Sunstone.addInfoPanel('image_info_panel',image_info_panel); +Sunstone.addInfoPanel('image_create_panel',image_create_panel); + + +function imageElements() { + return getSelectedNodes(dataTable_images); +} + +// Returns an array containing the values of the image_json and ready +// to be inserted in the dataTable +function imageElementArray(image_json){ + //Changing this? It may affect to the is_public() and is_persistent() functions. + var image = image_json.STORAGE; + var id,name; + + if (image.name){ + id = image.href.split("/"); + id = id[id.length-1]; + name = image.name; + } + else { + id = image.ID; + name = image.NAME; + }; + + return [ + '', + id, + name + ]; +} + +// Set up the listener on the table TDs to show the info panel +function imageInfoListener(){ + $('#tbodyimages tr',dataTable_images).live("click",function(e){ + var target = $(e.target); + + if (target.is('input') || target.is('select') || target.is('option')) + return true; + + popDialogLoading(); + var aData = dataTable_images.fnGetData(this); + var id = $(aData[0]).val(); + Sunstone.runAction("Image.showinfo",id); + return false; + }); +} + +// Callback to update an element in the dataTable +function updateImageElement(request, image_json){ + var id = image_json.STORAGE.ID; + var element = imageElementArray(image_json); + updateSingleElement(element,dataTable_images,'#image_'+id); +} + +// Callback to remove an element from the dataTable +function deleteImageElement(req){ + deleteElement(dataTable_images,'#image_'+req.request.data); +} + +// Callback to add an image element +function addImageElement(request, image_json){ + var element = imageElementArray(image_json); + addElement(element,dataTable_images); +} + +// Callback to refresh the list of images +function updateImagesView(request, images_list){ + var image_list_array = []; + + $.each(images_list,function(){ + image_list_array.push(imageElementArray(this)); + }); + + updateView(image_list_array,dataTable_images); + //updateDashboard("images",images_list); +} + +// Callback to update the information panel tabs and pop it up +function updateImageInfo(request,img){ + var img_info = img.STORAGE; + var info_tab = { + title: tr("Image information"), + content: + '\ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ +
'+tr("Image")+' "'+img_info.NAME+'" '+ + tr("information")+'
'+tr("ID")+''+img_info.ID+'
'+tr("Name")+''+img_info.NAME+'
'+tr("Type")+''+OCCI.Helper.image_type(img_info.TYPE)+'
'+tr("Public")+''+img_info.PUBLIC.toLowerCase()+'
'+tr("Persistent")+''+img_info.PERSISTENT.toLowerCase()+'
'+tr("Filesystem type")+''+(typeof img_info.FSTYPE === "string" ? img_info.FSTYPE : "--")+'
'+tr("Size (Mb)")+''+img_info.SIZE+'
\ +
\ +
' + }; + + Sunstone.updateInfoPanelTab("image_info_panel","image_info_tab",info_tab); + Sunstone.popUpInfoPanel("image_info_panel"); + $('#dialog .image_close_dialog_link').button({ + text:false, + icons: { primary: "ui-icon-closethick" } + }); +} + +function popUpCreateImageDialog(){ + Sunstone.popUpInfoPanel("image_create_panel"); + var dialog = $('#dialog'); + $create_image_dialog = dialog; + + $('#create_image',dialog).button({ + icons: { + primary: "ui-icon-check" + }, + text: false + }); + $('#reset_image',dialog).button({ + icons: { + primary: "ui-icon-document" + }, + text: false + }); + $('.image_close_dialog_link',dialog).button({ + icons: { + primary: "ui-icon-closethick" + }, + text: false + }); + + setupTips(dialog); + + $('#img_fstype',dialog).parents('div.img_param').hide(); + $('#img_size',dialog).parents('div.img_param').hide(); + + $('#img_public',dialog).click(function(){ + $('#img_persistent',$create_image_dialog).removeAttr('checked'); + }); + + $('#img_persistent',dialog).click(function(){ + $('#img_public',$create_image_dialog).removeAttr('checked'); + }); + + $('#img_type',dialog).change(function(){ + if ($(this).val() == "DATABLOCK"){ + $('#img_fstype',$create_image_dialog).parents('div.img_param').show(); + $('#img_size',$create_image_dialog).parents('div.img_param').show(); + $('#upload_div',$create_image_dialog).hide(); + } else { + $('#img_fstype',$create_image_dialog).parents('div.img_param').hide(); + $('#img_size',$create_image_dialog).parents('div.img_param').hide(); + $('#upload_div',$create_image_dialog).show(); + }; + }); + + $('#upload-progress',dialog).progressbar({value:0}); + $('#upload-progress',dialog).css({ + border: "1px solid #AAAAAA", + position: "relative", +// bottom: "29px", + width: "210px", +// left: "133px", + height: "15px", + display: "inline-block", + }); + $('#upload-progress div',dialog).css("border","1px solid #AAAAAA"); + + var img_obj; + + var uploader = new qq.FileUploaderBasic({ + button: $('#file-uploader',$create_image_dialog)[0], + action: 'ui/upload', + multiple: false, + params: {}, + showMessage: function(message){ + notifyMessage(message); + }, + onSubmit: function(id, fileName){ + var xml = json2xml(img_obj,"STORAGE"); + + uploader.setParams({ + occixml : xml, + file: fileName + }); + + $('#upload-progress',dialog).show(); + }, + onProgress: function(id, fileName, loaded, total){ + $('#upload-progress',dialog).progressbar("option","value",Math.floor(loaded*100/total)); + }, + onComplete: function(id, fileName, responseJSON){ + popUpImageDashboard(); + notifyMessage("Image uploaded correctly"); + Sunstone.runAction("Image.list"); + return false; + }, + onCancel: function(id, fileName){ + }, + }); + + var file_input = false; + uploader._button._options.onChange = function(input) { + file_input = input; return false; + }; + + $('#file-uploader input').removeAttr("style"); + + var processCreateImageForm = function(){ + var dialog = $create_image_dialog; + + var img_json = {}; + + var name = $('#img_name',dialog).val(); + if (!name){ + notifyError(tr("You must specify a name")); + return false; + }; + img_json["NAME"] = name; + + + var desc = $('#img_desc',dialog).val(); + if (desc){ + img_json["DESCRIPTION"] = desc; + } + + var type = $('#img_type',dialog).val(); + img_json["TYPE"]= type; + + if (type == "DATABLOCK"){ + var fstype = $('#img_fstype',dialog).val(); + var im_size = $('#img_size',dialog).val(); + if (!fstype || !im_size){ + notifyError(tr("You must specify size and FS type")); + return false; + }; + img_json["FSTYPE"] = fstype; + img_json["SIZE"] = im_size; + } else { + if (!$('#file-uploader input').val()){ + notifyError(tr("You must select a file to upload")); + return false; + }; + } + + + //img_json["PUBLIC"] = $('#img_public:checked',this).length ? "YES" : "NO"; + + //img_json["PERSISTENT"] = $('#img_persistent:checked',this).length ? "YES" : "NO"; + + return img_json; + }; + + $('#create_image_form_easy',dialog).submit(function(){ + var type = $('#img_type',dialog).val(); + img_obj = processCreateImageForm(); + if (!img_obj) return false; + if (type == "DATABLOCK"){ + Sunstone.runAction("Image.create",img_obj); + popUpImageDashboard(); + } else { + uploader._onInputChange(file_input); + }; + return false; + }); +} + +function popUpImageDashboard(){ + var count = dataTable_images.fnGetNodes().length; + popDialog(image_dashboard); + $('#dialog #image_dashboard_count').text(count); +}; + +// Set the autorefresh interval for the datatable +function setImageAutorefresh() { + setInterval(function(){ + var checked = $('input.check_item:checked',dataTable_images); + var filter = $("#datatable_images_filter input", + dataTable_images.parents("#datatable_images_wrapper")).attr('value'); + if (!checked.length && !filter.length){ + Sunstone.runAction("Image.autorefresh"); + } + },INTERVAL+someTime()); +}; + +/* +function is_public_image(id){ + var data = getElementData(id,"#image",dataTable_images)[7]; + return $(data).attr('checked'); +}; + +function is_persistent_image(id){ + var data = getElementData(id,"#image",dataTable_images)[8]; + return $(data).attr('checked'); +}; +*/ + +//The DOM is ready at this point +$(document).ready(function(){ + + dataTable_images = $("#datatable_images",main_tabs_context).dataTable({ + "bJQueryUI": true, + "bSortClasses": false, + "bAutoWidth":false, + "sPaginationType": "full_numbers", + "aoColumnDefs": [ + { "bSortable": false, "aTargets": ["check"] }, + { "sWidth": "60px", "aTargets": [0] }, + { "sWidth": "35px", "aTargets": [1] }, + ], + "oLanguage": (datatable_lang != "") ? + { + sUrl: "locale/"+lang+"/"+datatable_lang + } : "" + }); + + dataTable_images.fnClearTable(); + addElement([ + spinner, + '',''],dataTable_images); + Sunstone.runAction("Image.list"); + + setImageAutorefresh(); + + initCheckAllBoxes(dataTable_images); + tableCheckboxesListener(dataTable_images); + imageInfoListener(); + + $('#li_images_tab a').click(function(){ + popUpImageDashboard(); + //return false; + }); + + $('.image_close_dialog_link').live("click",function(){ + popUpVNetDashboard(); + return false; + }); + +}) diff --git a/src/cloud/occi/lib/ui/public/js/plugins/templates-tab.js b/src/cloud/occi/lib/ui/public/js/plugins/templates-tab.js deleted file mode 100644 index f1d8f97d9c..0000000000 --- a/src/cloud/occi/lib/ui/public/js/plugins/templates-tab.js +++ /dev/null @@ -1,2167 +0,0 @@ -/* -------------------------------------------------------------------------- */ -/* 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. */ -/* -------------------------------------------------------------------------- */ - -/*Templates tab plugin*/ - -var templates_tab_content = -'
\ -
\ -
\ -\ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ -
'+tr("All")+''+tr("ID")+''+tr("Owner")+''+tr("Group")+''+tr("Name")+''+tr("Registration time")+''+tr("Public")+'
\ -
'; - -var create_template_tmpl = '
\ - \ -
\ -
\ -
\ - \ -

'+ - tr("Fields marked with")+''+ - tr("are mandatory")+'
\ - '+tr("Fold / Unfold all sections")+'

\ -
\ -\ - \ -
\ -
\ -

'+tr("Capacity options")+'

\ -
\ -
'+tr("Capacity")+'\ -
\ - \ - \ -
'+tr("Name that the VM will get for description purposes. If NAME is not supplied a name generated by one will be in the form of one-<VID>.")+'
\ -
\ -
\ - \ - \ -
'+tr("Amount of RAM required for the VM, in Megabytes.")+'
\ -
\ -
\ - \ - \ -
'+tr("Percentage of CPU divided by 100 required for the Virtual Machine. Half a processor is written 0.5.")+'
\ -
\ -
\ - \ - \ -
'+tr("Number of virtual cpus. This value is optional, the default hypervisor behavior is used, usually one virtual CPU.")+'
\ -
\ -
\ -
\ - \ -
\ -
\ -

'+tr("Boot/OS options")+'

\ -
\ -
'+tr("OS and Boot options")+'\ -
\ - \ - \ -
'+tr("CPU architecture to virtualization")+'
\ -
\ - \ -
\ - \ - \ -
'+tr("Select boot method")+'
\ -
\ -
\ - \ - \ -
'+tr("Path to the OS kernel to boot the image")+'
\ -
\ -
\ - \ - \ -
'+tr("Path to the initrd image")+'
\ -
\ -
\ - \ - \ -
'+tr("Device to be mounted as root")+'
\ -
\ -
\ - \ - \ -
'+tr("Arguments for the booting kernel")+'
\ -
\ -
\ - \ - \ -
'+tr("Path to the bootloader executable")+'
\ -
\ -
\ - \ - \ -
'+tr("Boot device type")+'
\ -
\ -
\ -
\ -\ -\ - \ -
\ -
\ -

'+tr("Features")+'

\ -
\ -
'+tr("Features")+'\ -
\ - \ - \ -
'+tr("Physical address extension mode allows 32-bit guests to address more than 4 GB of memory")+'
\ -
\ -
\ - \ - \ -
'+tr("Useful for power management, for example, normally required for graceful shutdown to work")+'
\ -
\ -
\ -
\ -\ -\ - \ -
\ -
\ -

'+tr("Add disks/images")+'

\ -
\ -
'+tr("Disks")+'\ -
\ - \ - '+tr("Disk")+'\ - \ - '+tr("Image")+'\ - \ -
\ -
\ -
\ - \ - \ -
'+tr("Name of the image to use")+'
\ - \ -
\ -
\ - \ - \ -
'+tr("Type of disk device to emulate: ide, scsi")+'
\ -
\ -
\ - \ - \ -
'+tr("Device to map image disk. If set, it will overwrite the default device mapping")+'
\ -
\ -
\ - \ - \ -
'+tr("Specific image mapping driver. KVM: raw, qcow2. Xen:tap:aio:, file:. VMware unsupported")+'
\ -
\ -
\ - \ - \ -
'+tr("Disk type")+'
\ -
\ -
\ - \ - \ -
'+tr("Disk file location path or URL")+'
\ -
\ -
\ - \ - \ - \ -
'+tr("Size in MB")+'
\ -
\ -
\ - \ - \ - \ -
'+tr("Filesystem type for the fs images")+'
\ -
\ -
\ - \ - \ -
'+tr("Clone this image")+'
\ -
\ -
\ - \ - \ -
'+tr("Save this image after shutting down the VM")+'
\ -
\ -
\ - \ - \ -
'+tr("Mount image as read-only")+'
\ -
\ -
\ - \ - \ -
\ - \ - \ -
\ -
\ -
\ -
\ -\ - \ -
\ -
\ -

'+tr("Setup Networks")+'

\ -
\ -
'+tr("Network")+'\ -
\ - \ - '+tr("Predefined")+'\ - \ - '+tr("Manual")+'\ - \ - \ -
\ -
\ -
\ - \ - \ -
'+tr("Name of the network to attach this device")+'
\ - \ -
\ -
\ - \ - \ -
'+tr("Request an specific IP from the Network")+'
\ -
\ -
\ - \ - \ -
'+tr("HW address associated with the network interface")+'
\ -
\ -
\ - \ - \ -
'+tr("Name of the bridge the network device is going to be attached to")+'
\ -
\ -
\ - \ - \ -
'+tr("Name for the tun device created for the VM")+'
\ -
\ -
\ - \ - \ -
'+tr("Name of a shell script to be executed after creating the tun device for the VM")+'
\ -
\ -
\ - \ - \ -
'+tr("Hardware that will emulate this network interface. With Xen this is the type attribute of the vif.")+'
\ -
\ -
\ - \ - \ -
\ -
\ -
\ - \ - \ -
'+tr("Permits access to the VM only through the specified ports in the TCP protocol")+'
\ -
\ -
\ - \ - \ -
'+tr("Disallow access to the VM through the specified ports in the TCP protocol")+'
\ -
\ -
\ - \ - \ -
\ -
\ -
\ - \ - \ -
'+tr("Permits access to the VM only through the specified ports in the UDP protocol")+'
\ -
\ -
\ - \ - \ -
'+tr("Disallow access to the VM through the specified ports in the UDP protocol")+'
\ -
\ -
\ - \ - \ -
'+tr("ICMP policy")+'
\ -
\ -
\ -
\ - \ - \ -
\ - \ - \ -
\ -
\ -
\ -\ -\ - \ -
\ -
\ -

'+tr("Add inputs")+'

\ -
\ -
'+tr("Inputs")+'\ -
\ - \ - \ -
\ -
\ -
\ - \ - \ -
\ -
\ -
\ - \ - \ -
\ - \ - \ -
\ -
\ -
\ -\ -\ - \ -
\ -
\ -

'+tr("Add Graphics")+'

\ -
\ -
'+tr("Graphics")+'\ -
\ - \ - \ -
\ -
\ -
\ - \ - \ -
'+tr("IP to listen on")+'
\ -
\ -
\ - \ - \ -
'+tr("Port for the VNC server")+'
\ -
\ -
\ - \ - \ -
'+tr("Password for the VNC server")+'
\ -
\ -
\ - \ - \ -
'+tr("Keyboard configuration locale to use in the VNC display")+'
\ -
\ -
\ -
\ -\ -\ - \ -
\ -
\ -

'+tr("Add context variables")+'

\ -
\ -
'+tr("Context")+'\ -
\ - \ - \ -
'+tr("Name for the context variable")+'
\ -
\ -
\ - \ - \ -
'+tr("Value of the context variable")+'
\ -
\ -
\ - \ - \ -
\ - \ - \ -
\ -
\ -
\ -\ -\ - \ -
\ -
\ -

'+tr("Add placement options")+'

\ -
\ -
'+tr("Placement")+'\ -
\ - \ - \ -
'+tr("Boolean expression that rules out provisioning hosts from list of machines suitable to run this VM")+'
\ -
\ -
\ - \ - \ -
'+tr("This field sets which attribute will be used to sort the suitable hosts for this VM. Basically, it defines which hosts are more suitable than others")+'
\ -
\ -
\ -
\ -\ -\ - \ -
\ -
\ -

'+tr("Add Hypervisor raw options")+'

\ -
\ -
'+tr("Raw")+'\ - \ -
\ - \ - \ - \ -
'+tr("Raw data to be passed directly to the hypervisor")+'
\ -
\ -
\ -
\ -\ -\ - \ -
\ -
\ -

'+tr("Add custom variables")+'

\ -
\ -
'+tr("Custom variables")+'\ -
\ - \ - \ -
'+tr("Name for the custom variable")+'
\ -
\ -
\ - \ - \ -
'+tr("Value of the custom variable")+'
\ -
\ -
\ - \ - \ -
\ - \ - \ -
\ -
\ -
\ - \ -
\ -
\ - \ - \ -
\ -
\ -
\ -
\ -
\ -
\ -

'+tr("Write the Virtual Machine template here")+'

\ -
\ - \ -
\ -
\ -
\ -
\ - \ - \ -
\ -
\ -
\ -
\ -
'; - -var update_template_tmpl = - '
\ -

'+tr("Please, choose and modify the template you want to update")+':

\ -
\ - \ - \ -
\ -
\ - \ - \ -
\ - \ -
\ - \ -
\ -
\ -
\ - \ -
\ -
\ -
'; - -var dataTable_templates; -var $create_template_dialog; - -var template_actions = { - - "Template.create" : { - type: "create", - call: OpenNebula.Template.create, - callback: addTemplateElement, - error: onError, - notify:true - }, - - "Template.create_dialog" : { - type: "custom", - call: popUpCreateTemplateDialog - }, - - "Template.list" : { - type: "list", - call: OpenNebula.Template.list, - callback: updateTemplatesView, - error: onError - }, - - "Template.show" : { - type : "single", - call: OpenNebula.Template.show, - callback: updateTemplateElement, - error: onError - }, - - "Template.showinfo" : { - type: "single", - call: OpenNebula.Template.show, - callback: updateTemplateInfo, - error: onError - }, - - "Template.refresh" : { - type: "custom", - call: function () { - waitingNodes(dataTable_templates); - Sunstone.runAction("Template.list"); - }, - }, - - "Template.autorefresh" : { - type: "custom", - call: function() { - OpenNebula.Template.list({timeout: true, success: updateTemplatesView, error: onError}); - } - }, - - "Template.update_dialog" : { - type: "custom", - call: function() { - popUpTemplateTemplateUpdateDialog(); - } - }, - - "Template.update" : { - type: "single", - call: OpenNebula.Template.update, - callback: function() { - notifyMessage(tr("Template updated correctly")); - }, - error: onError - }, - - "Template.fetch_template" : { - type: "single", - call: OpenNebula.Template.fetch_template, - callback: function (request,response) { - $('#template_template_update_dialog #template_template_update_textarea').val(response.template); - }, - error: onError - }, - - "Template.publish" : { - type: "multiple", - call: OpenNebula.Template.publish, - callback: templateShow, - elements: templateElements, - error: onError, - notify: true - }, - - "Template.unpublish" : { - type: "multiple", - call: OpenNebula.Template.unpublish, - callback: templateShow, - elements: templateElements, - error: onError, - notify: true - }, - - "Template.delete" : { - type: "multiple", - call: OpenNebula.Template.delete, - callback: deleteTemplateElement, - elements: templateElements, - error: onError, - notify: true - }, - - "Template.instantiate" : { - type: "single", - call: OpenNebula.Template.instantiate, - error: onError, - notify: true - }, - - "Template.instantiate_vms" : { - type: "custom", - call: function(){ - nodes = getSelectedNodes(dataTable_templates); - $.each(nodes,function(){ - Sunstone.runAction("Template.instantiate",this,""); - }); - Sunstone.runAction("VM.refresh"); - } - }, - "Template.chown" : { - type: "multiple", - call: OpenNebula.Template.chown, - callback: templateShow, - elements: templateElements, - error:onError, - notify: true - }, - "Template.chgrp" : { - type: "multiple", - call: OpenNebula.Template.chgrp, - callback: templateShow, - elements: templateElements, - error:onError, - notify: true - } -} - -var template_buttons = { - "Template.refresh" : { - type: "image", - text: tr("Refresh list"), - img: "images/Refresh-icon.png" - }, - "Template.create_dialog" : { - type: "create_dialog", - text: tr("+ New") - }, - "Template.update_dialog" : { - type: "action", - text: tr("Update a template"), - alwaysActive: true - }, - "Template.instantiate_vms" : { - type: "action", - text: tr("Instantiate") - }, - "Template.chown" : { - type: "confirm_with_select", - text: tr("Change owner"), - select: users_sel, - tip: tr("Select the new owner")+":", - condition: mustBeAdmin - }, - "Template.chgrp" : { - type: "confirm_with_select", - text: tr("Change group"), - select: groups_sel, - tip: tr("Select the new group")+":", - condition: mustBeAdmin - }, - "action_list" : { - type: "select", - actions: { - "Template.publish" : { - type: "action", - text: tr("Publish") - }, - "Template.unpublish" : { - type: "action", - text: tr("Unpublish") - }, - } - }, - "Template.delete" : { - type: "action", - text: tr("Delete") - } -} - -var template_info_panel = { - "template_info_tab" : { - title: tr("Template information"), - content: "" - } -} - -var templates_tab = { - title: tr("Templates"), - content: templates_tab_content, - buttons: template_buttons -} - -Sunstone.addActions(template_actions); -Sunstone.addMainTab('templates_tab',templates_tab); -Sunstone.addInfoPanel('template_info_panel',template_info_panel); - -//Returns selected elements in the template table -function templateElements(){ - return getSelectedNodes(dataTable_templates); -} - -//Runs a show action on the template with from a prev request -function templateShow(req){ - Sunstone.runAction("Template.show",req.request.data[0]); -} - -// Returns an array containing the values of the template_json and ready -// to be inserted in the dataTable -function templateElementArray(template_json){ - var template = template_json.VMTEMPLATE; - return [ - '', - template.ID, - template.UNAME, - template.GNAME, - template.NAME, - pretty_time(template.REGTIME), - parseInt(template.PUBLIC) ? '' - : '' - ]; -} - -// Set up the listener on the table TDs to show the info panel -function templateInfoListener(){ - $('#tbodytemplates tr',dataTable_templates).live("click",function(e){ - if ($(e.target).is('input')) {return true;} - popDialogLoading(); - var aData = dataTable_templates.fnGetData(this); - var id = $(aData[0]).val(); - Sunstone.runAction("Template.showinfo",id); - return false; - }); -} - -//Updates the select input field with an option for each template -function updateTemplateSelect(){ - var templates_select = - makeSelectOptions(dataTable_templates, - 1,//id_col - 4,//name_col - [],//status_cols - []//bad status values - ); - - //update static selectors: - $('#template_id', $create_vm_dialog).html(templates_select); -} - -// Callback to update an element in the dataTable -function updateTemplateElement(request, template_json){ - var id = template_json.VMTEMPLATE.ID; - var element = templateElementArray(template_json); - updateSingleElement(element,dataTable_templates,'#template_'+id); - updateTemplateSelect(); -} - -// Callback to remove an element from the dataTable -function deleteTemplateElement(req){ - deleteElement(dataTable_templates,'#template_'+req.request.data); - updateTemplateSelect(); -} - -// Callback to add a template element -function addTemplateElement(request, template_json){ - var element = templateElementArray(template_json); - addElement(element,dataTable_templates); - updateTemplateSelect(); -} - -// Callback to refresh the list of templates -function updateTemplatesView(request, templates_list){ - var template_list_array = []; - - $.each(templates_list,function(){ - template_list_array.push(templateElementArray(this)); - }); - - updateView(template_list_array,dataTable_templates); - updateTemplateSelect(); - updateDashboard("templates",templates_list); - -} - -// Callback to update the information panel tabs and pop it up -function updateTemplateInfo(request,template){ - var template_info = template.VMTEMPLATE; - var info_tab = { - title: tr("Information"), - content: - '\ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ -
'+tr("Template")+' \"'+template_info.NAME+'\" '+ - tr("information")+'
'+tr("ID")+''+template_info.ID+'
'+tr("Name")+''+template_info.NAME+'
'+tr("Owner")+''+template_info.UNAME+'
'+tr("Group")+''+template_info.GNAME+'
'+tr("Register time")+''+pretty_time(template_info.REGTIME)+'
'+tr("Public")+''+(parseInt(template_info.PUBLIC) ? tr("yes") : tr("no"))+'
' - }; - var template_tab = { - title: tr("Template"), - content: '\ - '+ - prettyPrintJSON(template_info.TEMPLATE)+ - '
'+tr("Template")+'
' - }; - - - Sunstone.updateInfoPanelTab("template_info_panel","template_info_tab",info_tab); - Sunstone.updateInfoPanelTab("template_info_panel","template_template_tab",template_tab); - - Sunstone.popUpInfoPanel("template_info_panel"); -} - -// Prepare the template creation dialog -function setupCreateTemplateDialog(){ - //Helper functions for the dialog operations - - // Called when changing tabs. Since we use the same form for both - // KVM, XEN and others we need to do some operation to update it - var vmTabChange = function(event,ui){ - // ui.tab // anchor element of the selected (clicked) tab - // ui.panel // element, that contains the selected/clicked tab contents - // ui.index // zero-based index of the selected (clicked) tab - - //disable all items - $(items,dialog).attr('disabled','disabled'); - //hide all mandatory icons - $('.vm_param .man_icon',dialog).css("display","none"); - - //empty selects - $('select#BOOT',section_os_boot).empty(); - $('select#TYPE',section_disks).empty(); - $('select#BUS',section_disks).empty(); - - //hide options about boot method - $('div#kernel_bootloader',section_os_boot).show(); - $('.kernel, .bootloader', section_os_boot).hide(); - $('select#BOOT',section_os_boot).parent().hide(); - //unselect boot method - $('select#boot_method option',section_os_boot).removeAttr('selected'); - - //hide non common sections - $(section_inputs).hide(); - $(section_graphics).hide(); - - switch(ui.index){ - case 0: - enable_kvm(); - break; - case 1: - enable_xen(); - break; - case 2: - enable_vmware(); - case 3: - break; - } - //hide_disabled(); - //show_enabled(); - } - - //~ var hide_disabled = function(context) { - //~ var $disabled; - //~ if (!context) { - //~ $disabled = $('.vm_param input:disabled,.vm_param select:disabled'); - //~ } else { - //~ $disabled = $('.vm_param input:disabled,.vm_param select:disabled',context); - //~ } - //~ - //~ $disabled.each(function(){ - //~ $(this).parent('.vm_param').hide(); - //~ }); - //~ } - //~ - //~ var show_enabled = function(context){ - //~ var $enabled; - //~ if (!context) { - //~ $enabled = $('.vm_param input:enabled,.vm_param select:enabled'); - //~ } else { - //~ $enabled = $('.vm_param input:enabled,.vm_param select:enabled',context); - //~ } - //~ - //~ $enabled.parent('.vm_param').show(); - //~ } - - //Using kvm wizard. - var enable_kvm = function(){ - man_class="kvm"; - opt_class="kvm_opt"; - $(kvm_items,dialog).removeAttr('disabled'); - $('.kvm .man_icon',dialog).css("display","inline-block"); - - //KVM particularities: - // * Add custom disk types - // * Add custom boot options - // * Add custom bus options - // * Show boot options - // * Set the raw type to kvm - // * Show the inputs and graphics section - - var type_opts = - '\ - \ - \ - \ - \ - \ - '; - - $('select#TYPE',section_disks).html(type_opts); - - var boot_opts = - '\ - \ - \ - '; - - $('select#BOOT',section_os_boot).html(boot_opts); - $('select#BOOT',section_os_boot).parent().show(); - $('select#boot_method option#no_boot',section_os_boot).html(tr("Driver default")); - - var bus_opts = - '\ - \ - '; - - $('select#BUS',section_disks).html(bus_opts); - - $('input#TYPE', section_raw).val("kvm"); - - $(section_inputs).show(); - $(section_graphics).show(); - }; - - // Using XEN wizard. - var enable_xen = function(){ - man_class="xen"; - opt_class="xen_opt"; - $(xen_items,dialog).removeAttr('disabled'); - $('.xen .man_icon',dialog).css("display","inline-block"); - - // XEN particularities: - // * Add custom disk types - // * Remove driver default boot method - // * Add custom bus types - // * Set the raw section to XEN - // * Show the graphics section - - var type_opts = - '\ - \ - \ - \ - \ - '; - - $('select#TYPE',section_disks).html(type_opts); - - $('select#boot_method option#no_boot',section_os_boot).html(tr("Please choose")); - - var bus_opts = - '\ - '; - - $('select#BUS',section_disks).html(bus_opts); - - $('input#TYPE', section_raw).val("xen"); - $(section_graphics).show(); - }; - - //VMWare wizard - var enable_vmware = function() { - man_class="vmware"; - opt_class="vmware_opt"; - $(vmware_items,dialog).removeAttr('disabled'); - $('.vmware .man_icon',dialog).css("display","inline-block"); - - //VMWARE particularities - // * Add custom disk types - // * Hide boot method field - // * Add custom bus types - // * Set the raw type to vmware - - var type_opts = - '\ - \ - '; - - $('select#TYPE',section_disks).html(type_opts); - - $('div#kernel_bootloader',section_os_boot).hide(); - - var bus_opts = - '\ - '; - - $('select#BUS',section_disks).html(bus_opts); - $('input#TYPE', section_raw).val("vmware"); - }; - - //This function checks that all mandatory items within a section - //have some value. Returns true if so, false if not. - var mandatory_filter = function(context){ - var man_items = "."+man_class; - - //find enabled mandatory items in this context - man_items = $(man_items+' input:visible, '+man_items+' select:visible',context); - var r = true; - - //we fail it the item is enabled and has no value - $.each(man_items,function(){ - var item = $(this); - if (item.parents(".vm_param").attr('disabled') || - !(item.val().length)) { - r = false; - return false; - }; - }); - return r; - }; - - //Adds an option element to a multiple select box. Before doing so, - //it checks that the desired filter is passed - var box_add_element = function(context,box_tag,filter){ - var value=""; - var params= $('.vm_param',context); - var inputs= $('input:enabled',params); - var selects = $('select:enabled',params); - var fields = $.merge(inputs,selects); - - //are fields passing the filter? - var result = filter(); - if (!result) { - notifyError(tr("There are mandatory parameters missing in this section")); - return false; - } - - value={}; - - //With each enabled field we form a JSON object - var id = null; - $.each(fields,function(){ - var field = $(this); - if (!(field.parents(".vm_param").attr('disabled')) && - field.val().length){ - //Pick up parent's ID if we do not have one - id = field.attr('id').length ? field.attr('id') : field.parent().attr('id'); - value[id] = field.val(); - }; - }); - var value_string = JSON.stringify(value); - var option= - ''; - $('select'+box_tag,context).append(option); - return false; - }; - - //Removes selected elements from a multiple select box - var box_remove_element = function(section_tag,box_tag){ - var context = $(section_tag,dialog); - $('select'+box_tag+' :selected',context).remove(); - return false; - }; - - //Given the JSON of a VM template (or of a section of it), it crawls - //the fields of certain section (context) and add their name and - //values to the template JSON. - var addSectionJSON = function(template_json,context){ - var params= $('.vm_param',context); - var inputs= $('input:enabled',params); - var selects = $('select:enabled',params); - var fields = $.merge(inputs,selects); - - fields.each(function(){ - var field=$(this); - if (!(field.parents(".vm_param").attr('disabled'))){ //if ! disabled - if (field.val().length){ //if has a length - template_json[field.attr('id')]=field.val(); - }; - }; - }); - }; - - // Given a section (context) and a tag for - // a multiple select in that section, it adds the - // JSON values to an array parsed as objects. - // Returns the array - var addBoxJSON = function(context,box_tag){ - var array = []; - $('select'+box_tag+' option',context).each(function(){ - array.push( JSON.parse($(this).val()) ); - }); - return array; - } - - //Given an object, removes those elements which are empty - //Used to clean up a template JSON before submitting - //it to opennebula.js - var removeEmptyObjects = function(obj){ - for (elem in obj){ - var remove = false; - var value = obj[elem]; - if (value instanceof Array) - { - if (value.length == 0) - remove = true; - } - else if (value instanceof Object) - { - var obj_length = 0; - for (e in value) - obj_length += 1; - if (obj_length == 0) - remove = true; - } - else - { - value = String(value); - if (value.length == 0) - remove = true; - } - if (remove) - delete obj[elem]; - } - return obj; - } - - //Toggles the icon when a section is folded/unfolded - var iconToggle = function(){ - $('.icon_left',$create_template_dialog).click(function(e){ - if ($('span',e.currentTarget).hasClass("ui-icon-plus")){ - $('span',e.currentTarget).removeClass("ui-icon-plus"); - $('span',e.currentTarget).addClass("ui-icon-minus"); - } else { - $('span',e.currentTarget).removeClass("ui-icon-minus"); - $('span',e.currentTarget).addClass("ui-icon-plus"); - }; - }); - }; - - //Fold/unfold all sections button - var foldUnfoldToggle = function() { - $('#fold_unfold_vm_params',$create_template_dialog).toggle( - function(){ - $('.vm_section fieldset',$create_template_dialog).show(); - $('.icon_left span',$create_template_dialog).removeClass("ui-icon-plus"); - $('.icon_left span',$create_template_dialog).addClass("ui-icon-minus"); - return false; - }, - function(){ - $('.vm_section fieldset',$create_template_dialog).hide(); - //Show capacity opts - $('.vm_section fieldset',$create_template_dialog).first().show(); - $('.icon_left span',$create_template_dialog).removeClass("ui-icon-minus"); - $('.icon_left span',$create_template_dialog).addClass("ui-icon-plus"); - return false; - }); - }; - - // Set ups the capacity section - var capacity_setup = function(){ - //Actually there is nothing to set up, but it used to be - //possible to hide it like others - /* - $('fieldset',section_capacity).hide(); - $('#add_capacity',section_capacity).click(function(){ - $('fieldset',section_capacity).toggle(); - return false; - }); - */ - - } - - //Sets up the OS_BOOT section - var os_boot_setup = function(){ - $('fieldset',section_os_boot).hide(); - $('.bootloader, .kernel',section_os_boot).hide(); - - $('#add_os_boot_opts',section_os_boot).click(function(){ - $('fieldset',section_os_boot).toggle(); - return false; - }); - - //Depending on the boot method we enable/disable some options - $('#boot_method',section_os_boot).change(function(){ - select = $(this).val(); - switch (select) - { - case "kernel": - $('.bootloader',section_os_boot).hide(); - $('.bootloader',section_os_boot).attr('disabled','disabled'); - $('.kernel',section_os_boot).show(); - $('.kernel',section_os_boot).removeAttr('disabled'); - break; - case "bootloader": - $('.kernel',section_os_boot).hide(); - $('.kernel',section_os_boot).attr('disabled','disabled'); - $('.bootloader',section_os_boot).show(); - $('.bootloader',section_os_boot).removeAttr('disabled'); - break; - default: - $('.kernel, .bootloader',section_os_boot).hide(); - $('.kernel, .bootloader',section_os_boot).attr('disabled','disabled'); - $('.kernel input, .bootloader input',section_os_boot).val(""); - }; - }); - }; - - // Sets up the features section - var features_setup = function(){ - $('fieldset',section_features).hide(); - - $('#add_features',section_features).click(function(){ - $('fieldset',section_features).toggle(); - return false; - }); - }; - - // Sets up the disk section - var disks_setup = function(){ - - $('fieldset',section_disks).hide(); - $('.vm_param', section_disks).hide(); - //$('#image_vs_disk',section_disks).show(); - - $('#add_disks', section_disks).click(function(){ - $('fieldset',section_disks).toggle(); - return false; - }); - - //Auto-set IMAGE_UNAME hidden field value - $('#IMAGE', section_disks).change(function(){ - var uname = getValue($(this).val(),4,2,dataTable_images); - $('input#IMAGE_UNAME',section_disks).val(uname); - }); - - //Depending on adding a disk or a image we need to show/hide - //different options and make then mandatory or not - $('#image_vs_disk input',section_disks).click(function(){ - //$('fieldset',section_disks).show(); - $('.vm_param', section_disks).show(); - var select = $('#image_vs_disk :checked',section_disks).val(); - switch (select) - { - case "disk": - $('.add_image',section_disks).hide(); - $('.add_image',section_disks).attr('disabled','disabled'); - $('.add_disk',section_disks).show(); - $('.add_disk',section_disks).removeAttr('disabled'); - $('#TARGET',section_disks).parent().removeClass(opt_class); - $('#TARGET',section_disks).parent().addClass(man_class); - break; - case "image": - $('.add_disk',section_disks).hide(); - $('.add_disk',section_disks).attr('disabled','disabled'); - $('.add_image',section_disks).show(); - $('.add_image',section_disks).removeAttr('disabled'); - $('#TARGET',section_disks).parent().removeClass(man_class); - $('#TARGET',section_disks).parent().addClass(opt_class); - break; - } - $('#SIZE',section_disks).parent().hide(); - $('#SIZE',section_disks).parent().attr('disabled','disabled'); - $('#FORMAT',section_disks).parent().hide(); - $('#SIZE',section_disks).parent().attr('disabled','disabled'); - $('#TYPE :selected',section_disks).removeAttr('selected'); - //hide_disabled(section_disks); - }); - - //Depending on the type of disk we need to show/hide - //different options and make then mandatory or not - $('select#TYPE',section_disks).change(function(){ - var select = $(this).val(); - switch (select) { - //size,format,target - case "swap": - //size mandatory - $('#SIZE',section_disks).parent().show(); - $('#SIZE',section_disks).parent().removeAttr('disabled'); - $('#SIZE',section_disks).parent().removeClass(opt_class); - $('#SIZE',section_disks).parent().addClass(man_class); - - //target optional - $('#TARGET',section_disks).parent().removeClass(man_class); - $('#TARGET',section_disks).parent().addClass(opt_class); - - //format hidden - $('#FORMAT',section_disks).parent().hide(); - $('#FORMAT',section_disks).parent().attr('disabled','disabled'); - - //source hidden - $('#SOURCE',section_disks).parent().hide(); - $('#SOURCE',section_disks).parent(). - attr('disabled','disabled'); - break; - case "fs": - //size mandatory - $('#SIZE',section_disks).parent().show(); - $('#SIZE',section_disks).parent().removeAttr('disabled'); - $('#SIZE',section_disks).parent().removeClass(opt_class); - $('#SIZE',section_disks).parent().addClass(man_class); - - //target mandatory - $('#TARGET',section_disks).parent().removeClass(opt_class); - $('#TARGET',section_disks).parent().addClass(man_class); - - //format mandatory - $('#FORMAT',section_disks).parent().show(); - $('#FORMAT',section_disks).parent().removeAttr('disabled'); - $('#FORMAT',section_disks).parent().removeClass(opt_class); - $('#FORMAT',section_disks).parent().addClass(man_class); - - //source hidden - $('#SOURCE',section_disks).parent().hide(); - $('#SOURCE',section_disks).parent(). - attr('disabled','disabled'); - break; - case "block": - //size shown and optional - $('#SIZE',section_disks).parent().show(); - $('#SIZE',section_disks).parent().removeAttr('disabled'); - $('#SIZE',section_disks).parent().removeClass(man_class); - $('#SIZE',section_disks).parent().addClass(opt_class); - - //target mandatory - $('#TARGET',section_disks).parent().removeClass(opt_class); - $('#TARGET',section_disks).parent().addClass(man_class); - - //format hidden - $('#FORMAT',section_disks).parent().hide(); - $('#FORMAT',section_disks).parent().attr('disabled','disabled'); - - //source hidden - $('#SOURCE',section_disks).parent().hide(); - $('#SOURCE',section_disks).parent(). - attr('disabled','disabled'); - break; - case "floppy": - case "disk": - case "cdrom": - default: - //size hidden - $('#SIZE',section_disks).parent().hide(); - $('#SIZE',section_disks).parent().attr('disabled','disabled'); - - //target mandatory - $('#TARGET',section_disks).parent().removeClass(opt_class); - $('#TARGET',section_disks).parent().addClass(man_class); - - //format optional - $('#FORMAT',section_disks).parent().hide(); - $('#FORMAT',section_disks).parent().attr('disabled','disabled'); - - //source shown - $('#SOURCE',section_disks).parent().show(); - $('#SOURCE',section_disks).parent(). - removeAttr('disabled'); - } - //hide_disabled(section_disks); - }); - - //Our filter for the disks section fields is the standard - //mandatory filter applied for this section - var diskFilter = function(){ - return mandatory_filter(section_disks); - }; - - $('#add_disk_button',section_disks).click(function(){ - box_add_element(section_disks,'#disks_box',diskFilter); - return false; - }); - $('#remove_disk_button',section_disks).click(function(){ - box_remove_element(section_disks,'#disks_box'); - return false; - }); - }; - - // Sets up the network section - var networks_setup = function(){ - - $('.vm_param',section_networks).hide(); - $('.firewall_select',section_networks).hide(); - $('fieldset',section_networks).hide(); - - $('#add_networks',section_networks).click(function(){ - $('fieldset',section_networks).toggle(); - return false; - }); - - //Auto-set IMAGE_UNAME hidden field value - $('#NETWORK', section_networks).change(function(){ - var uname = getValue($(this).val(),4,2,dataTable_vNetworks); - $('input#NETWORK_UNAME',section_networks).val(uname); - }); - - //Depending on adding predefined network or not we show/hide - //some fields - $('#network_vs_niccfg input',section_networks).click(function(){ - - //firewall - $('.firewall',section_networks).hide(); - $('.firewall',section_networks).attr('disabled','disabled'); - $('.firewall_select',section_networks).show(); - $('.firewall_select select option',section_networks).removeAttr('selected'); - - select = $('#network_vs_niccfg :checked',section_networks).val(); - switch (select) { - case "network": - $('.niccfg',section_networks).hide(); - $('.niccfg',section_networks).attr('disabled','disabled'); - $('.network',section_networks).show(); - $('.network',section_networks).removeAttr('disabled'); - break; - case "niccfg": - $('.network',section_networks).hide(); - $('.network',section_networks).attr('disabled','disabled'); - $('.niccfg',section_networks).show(); - $('.niccfg',section_networks).removeAttr('disabled'); - break; - } - //hide_disabled(section_networks); - }); - - $('#black_white_tcp',section_networks).change(function(){ - switch ($(this).val()) { - case "whitelist": - $('#BLACK_PORTS_TCP',section_networks).parent().attr('disabled','disabled'); - $('#BLACK_PORTS_TCP',section_networks).parent().hide(); - $('#WHITE_PORTS_TCP',section_networks).parent().removeAttr('disabled'); - $('#WHITE_PORTS_TCP',section_networks).parent().show(); - break; - case "blacklist": - $('#WHITE_PORTS_TCP',section_networks).parent().attr('disabled','disabled'); - $('#WHITE_PORTS_TCP',section_networks).parent().hide(); - $('#BLACK_PORTS_TCP',section_networks).parent().removeAttr('disabled'); - $('#BLACK_PORTS_TCP',section_networks).parent().show(); - break; - default: - $('#WHITE_PORTS_TCP',section_networks).parent().attr('disabled','disabled'); - $('#WHITE_PORTS_TCP',section_networks).parent().hide(); - $('#BLACK_PORTS_TCP',section_networks).parent().attr('disabled','disabled'); - $('#BLACK_PORTS_TCP',section_networks).parent().hide(); - }; - }); - - $('#black_white_udp',section_networks).change(function(){ - switch ($(this).val()) { - case "whitelist": - $('#BLACK_PORTS_UDP',section_networks).parent().attr('disabled','disabled'); - $('#BLACK_PORTS_UDP',section_networks).parent().hide(); - $('#WHITE_PORTS_UDP',section_networks).parent().removeAttr('disabled'); - $('#WHITE_PORTS_UDP',section_networks).parent().show(); - break; - case "blacklist": - $('#WHITE_PORTS_UDP',section_networks).parent().attr('disabled','disabled'); - $('#WHITE_PORTS_UDP',section_networks).parent().hide(); - $('#BLACK_PORTS_UDP',section_networks).parent().removeAttr('disabled'); - $('#BLACK_PORTS_UDP',section_networks).parent().show(); - break; - default: - $('#WHITE_PORTS_UDP',section_networks).parent().attr('disabled','disabled'); - $('#WHITE_PORTS_UDP',section_networks).parent().hide(); - $('#BLACK_PORTS_UDP',section_networks).parent().attr('disabled','disabled'); - $('#BLACK_PORTS_UDP',section_networks).parent().hide(); - }; - }); - - //The filter to add a new network checks that we have selected a - //network, or that the ip or mac are set - //TODO: Improve this check - var nicFilter = function(){ - return mandatory_filter(section_networks); - }; - - $('#add_nic_button',section_networks).click(function(){ - box_add_element(section_networks,'#nics_box',nicFilter); - return false; - }); - $('#remove_nic_button',section_networks).click(function(){ - box_remove_element(section_networks,'#nics_box'); - return false; - }); - - }; - - //Sets up the input section - basicly enabling adding and removing from box - var inputs_setup = function() { - $('fieldset',section_inputs).hide(); - - $('#add_inputs',section_inputs).click(function(){ - $('fieldset',section_inputs).toggle(); - return false; - }); - - $('#add_input_button',section_inputs).click(function(){ - //no filter - box_add_element(section_inputs,'#inputs_box',function(){return true}); - return false; - }); - $('#remove_input_button',section_inputs).click(function(){ - box_remove_element(section_inputs,'#inputs_box'); - return false; - }); - }; - - //Set up the graphics section - var graphics_setup = function(){ - $('fieldset',section_graphics).hide(); - $('.vm_param',section_graphics).hide(); - $('select#TYPE',section_graphics).parent().show(); - - $('#add_graphics',section_graphics).click(function(){ - $('fieldset',section_graphics).toggle(); - return false; - }); - - //Chrome workaround - $('select#TYPE',section_graphics).change(function(){ - $(this).trigger("click"); - }); - $('select#TYPE',section_graphics).click(function(){ - g_type = $(this).val(); - switch (g_type) { - case "vnc": - $('#LISTEN',section_graphics).parent().show(); - $('#PORT',section_graphics).parent().show(); - $('#PASSWD',section_graphics).parent().show(); - $('#KEYMAP',section_graphics).parent().show(); - $('#PORT',section_graphics).parent().removeAttr('disabled'); - $('#PASSWD',section_graphics).parent().removeAttr('disabled'); - $('#KEYMAP',section_graphics).parent().removeAttr('disabled'); - break; - case "sdl": - $('#LISTEN',section_graphics).parent().show(); - $('#PORT',section_graphics).parent().hide(); - $('#PASSWD',section_graphics).parent().hide(); - $('#KEYMAP',section_graphics).parent().hide(); - $('#PORT',section_graphics).parent().attr('disabled','disabled'); - $('#PASSWD',section_graphics).parent().attr('disabled','disabled'); - $('#KEYMAP',section_graphics).parent().attr('disabled','disabled'); - break; - default: - $('#LISTEN',section_graphics).parent().hide(); - $('#PORT',section_graphics).parent().hide(); - $('#PASSWD',section_graphics).parent().hide(); - $('#KEYMAP',section_graphics).parent().hide(); - } - }); - - }; - - //Set up the context section - TODO: Apply improvements here... - var context_setup = function(){ - $('fieldset',section_context).hide(); - - $('#add_context',section_context).click(function(){ - $('fieldset',section_context).toggle(); - return false; - }); - - $('#add_context_button', section_context).click(function(){ - var name = $('#var_name',section_context).val(); - var value = $('#var_value',section_context).val(); - if (!name.length || !value.length) { - notifyError(tr("Context variable name and value must be filled in")); - return false; - } - option= ''; - $('select#context_box',section_context).append(option); - return false; - }); - - $('#remove_context_button', section_context).click(function(){ - box_remove_element(section_context,'#context_box'); - return false; - }); - }; - - // Set up the placement section - var placement_setup = function(){ - $('fieldset',section_placement).hide(); - - $('#add_placement',section_placement).click(function(){ - $('fieldset',section_placement).toggle(); - return false; - }); - - }; - - // Set up the raw section - var raw_setup = function(){ - $('fieldset',section_raw).hide(); - - $('#add_raw',section_raw).click(function(){ - $('fieldset',section_raw).toggle(); - return false; - }); - }; - - //set up the custom variables section - var custom_variables_setup = function(){ - $('fieldset',section_custom_var).hide(); - - $('#add_custom_var',section_custom_var).click(function(){ - $('fieldset',section_custom_var).toggle(); - return false; - }); - - $('#add_custom_var_button', section_custom_var).click( - function(){ - var name = $('#custom_var_name',section_custom_var).val(); - var value = $('#custom_var_value',section_custom_var).val(); - if (!name.length || !value.length) { - notifyError(tr("Custom variable name and value must be filled in")); - return false; - } - option= ''; - $('select#custom_var_box',section_custom_var).append(option); - return false; - }); - - $('#remove_custom_var_button', section_custom_var).click( - function(){ - box_remove_element(section_custom_var,'#custom_var_box'); - return false; - }); - } - - //***CREATE VM DIALOG MAIN BODY*** - - dialogs_context.append('
'); - $create_template_dialog = $('#create_template_dialog',dialogs_context) - var dialog = $create_template_dialog; - - //Insert HTML in place - dialog.html(create_template_tmpl); - - //Enable tabs - $('#template_create_tabs',dialog).tabs({ - select:vmTabChange - }); - - //Prepare jquery dialog - var height = Math.floor($(window).height()*0.8); //set height to a percentage of the window - dialog.dialog({ - autoOpen: false, - modal: true, - width: 600, - height: height - }); - - // Enhace buttons - $('button',dialog).button(); - - // Re-Setup tips - setupTips(dialog); - - //Enable different icon for folded/unfolded categories - iconToggle(); //toogle +/- buttons - - //Sections, used to stay within their scope - var section_capacity = $('div#capacity',dialog); - var section_os_boot = $('div#os_boot_opts',dialog); - var section_features = $('div#features',dialog); - var section_disks = $('div#disks',dialog); - var section_networks = $('div#networks',dialog); - var section_inputs = $('div#inputs',dialog); - var section_graphics = $('div#graphics',dialog); - var section_context = $('div#context',dialog); - var section_placement = $('div#placement',dialog); - var section_raw = $('div#raw',dialog); - var section_custom_var = $('div#custom_var',dialog); - - //Different selector for items of kvm and xen (mandatory and optional) - var items = '.vm_param input,.vm_param select'; - var kvm_man_items = '.kvm input,.kvm select'; - var kvm_opt_items = '.kvm_opt input, .kvm_opt select'; - var kvm_items = kvm_man_items +','+kvm_opt_items; - var xen_man_items = '.xen input,.xen select'; - var xen_opt_items = '.xen_opt input, .xen_opt select'; - var xen_items = xen_man_items +','+ xen_opt_items; - var vmware_man_items = '.vmware input,.vmware select'; - var vmware_opt_items = '.vmware_opt input, .vmware_opt select'; - var vmware_items = vmware_man_items +','+ vmware_opt_items; - - //Starting template type, optional items class and mandatory items class - var templ_type = "kvm"; - var opt_class=".kvm_opt"; - var man_class=".kvm"; - - vmTabChange(0,{index : 0}); //enable kvm - - foldUnfoldToggle(); - - //initialise all sections - capacity_setup(); - os_boot_setup(); - features_setup(); - disks_setup(); - networks_setup(); - inputs_setup(); - graphics_setup(); - context_setup(); - placement_setup(); - raw_setup(); - custom_variables_setup(); - - //Process form - $('button#create_template_form_easy',dialog).click(function(){ - //validate form - - var vm_json = {}; - var name,value,boot_method; - - //process capacity options - var scope = section_capacity; - - if (!mandatory_filter(scope)){ - notifyError(tr("There are mandatory fields missing in the capacity section")); - return false; - }; - addSectionJSON(vm_json,scope); - - //process os_boot_opts - scope= section_os_boot; - switch (templ_type){ - case "xen": - boot_method = $('#boot_method option:selected',scope).val(); - if (!boot_method.length){ - notifyError(tr("Xen templates must specify a boot method")); - return false;} - }; - - if (!mandatory_filter(scope)){ - notifyError(tr("There are mandatory fields missing in the OS Boot options section")); - return false; - }; - vm_json["OS"] = {}; - addSectionJSON(vm_json["OS"],scope); - - //Fetch pae and acpi options - scope = section_features; - vm_json["FEATURES"] = {}; - addSectionJSON(vm_json["FEATURES"],scope); - - //process disks -> fetch from box - scope = section_disks; - vm_json["DISK"] = addBoxJSON(scope,'#disks_box'); - - //process nics -> fetch from box - scope = section_networks; - vm_json["NIC"] = addBoxJSON(scope,'#nics_box'); - - //process inputs -> fetch from box - scope = section_inputs; - vm_json["INPUT"] = addBoxJSON(scope,'#inputs_box'); - - //process graphics -> fetch fields with value - scope = section_graphics; - vm_json["GRAPHICS"] = {}; - addSectionJSON(vm_json["GRAPHICS"],scope); - - //context - scope = section_context; - vm_json["CONTEXT"] = {}; - $('#context_box option',scope).each(function(){ - name = $(this).attr('name'); - value = $(this).val(); - vm_json["CONTEXT"][name]=value; - }); - - //placement -> fetch with value, escape double quotes - scope = section_placement; - var requirements = $('input#REQUIREMENTS',scope).val(); - requirements = escapeDoubleQuotes(requirements); - $('input#REQUIREMENTS',scope).val(requirements); - var rank = $('input#RANK',scope).val(); - rank = escapeDoubleQuotes(rank); - $('input#RANK',scope).val(rank); - addSectionJSON(vm_json,scope); - - //raw -> if value set type to driver and fetch - scope = section_raw; - vm_json["RAW"] = {}; - addSectionJSON(vm_json["RAW"],scope); - - //custom vars - scope = section_custom_var; - $('#custom_var_box option',scope).each(function(){ - name = $(this).attr('name'); - value = $(this).val(); - vm_json[name]=value; - }); - - // remove empty elements - vm_json = removeEmptyObjects(vm_json); - - //wrap it in the "vmtemplate" object - vm_json = {vmtemplate: vm_json}; - - - Sunstone.runAction("Template.create",vm_json); - - $create_template_dialog.dialog('close'); - return false; - }); - - //Handle manual forms - $('button#create_template_form_manual',$create_template_dialog).click(function(){ - var template = $('textarea#textarea_vm_template',$create_template_dialog).val(); - - //wrap it in the "vm" object - template = {"vmtemplate": {"template_raw": template}}; - - Sunstone.runAction("Template.create",template); - $create_template_dialog.dialog('close'); - return false; - }); - - //Reset form - empty boxes - $('button#reset_vm_form',dialog).click(function(){ - $('select#disks_box option',section_disks).remove(); - $('select#nics_box option',section_networks).remove(); - $('select#inputs_box option',section_inputs).remove(); - $('select#custom_var_box option',section_custom_var).remove(); - return true; - }); -} - -function popUpCreateTemplateDialog(){ - //Repopulate images select - var im_sel = makeSelectOptions(dataTable_images, - 4, //id col - trick -> reference by name! - 4, //name col - [10,10,10], - ["DISABLED","LOCKED","ERROR"] - ); - $('div#disks select#IMAGE',$create_template_dialog).html(im_sel); - //Repopulate network select - var vn_sel = makeSelectOptions(dataTable_vNetworks, - 4, //id col - trick -> reference by name! - 4, - [], - [] - ); - $('div#networks select#NETWORK',$create_template_dialog).html(vn_sel); - - $create_template_dialog.dialog('open'); -}; - -function setupTemplateTemplateUpdateDialog(){ - //Append to DOM - dialogs_context.append('
'); - var dialog = $('#template_template_update_dialog',dialogs_context); - - //Put HTML in place - dialog.html(update_template_tmpl); - - //Convert into jQuery - dialog.dialog({ - autoOpen:false, - width:700, - modal:true, - height:480, - resizable:false, - }); - - $('button',dialog).button(); - - $('#template_template_update_select',dialog).change(function(){ - var id = $(this).val(); - if (id && id.length){ - var dialog = $('#template_template_update_dialog'); - $('#template_template_update_textarea',dialog).val(tr("Loading")+"..."); - - var templ_public = is_public_template(id); - - if (templ_public){ - $('#template_template_update_public',dialog).attr('checked','checked') - } else { - $('#template_template_update_public',dialog).removeAttr('checked') - } - - Sunstone.runAction("Template.fetch_template",id); - } else { - $('#template_template_update_textarea',dialog).val(""); - }; - }); - - $('#template_template_update_button',dialog).click(function(){ - var dialog = $('#template_template_update_dialog'); - var new_template = $('#template_template_update_textarea',dialog).val(); - var id = $('#template_template_update_select',dialog).val(); - if (!id || !id.length) { - dialog.dialog('close'); - return false; - }; - - var old_public = is_public_template(id); - - var new_public = $('#template_template_update_public:checked',dialog).length; - - if (old_public != new_public){ - if (new_public) Sunstone.runAction("Template.publish",id); - else Sunstone.runAction("Template.unpublish",id); - }; - - Sunstone.runAction("Template.update",id,new_template); - dialog.dialog('close'); - return false; - }); -}; - -function popUpTemplateTemplateUpdateDialog(){ - var select = makeSelectOptions(dataTable_templates, - 1,//id_col - 4,//name_col - [], - [] - ); - var sel_elems = getSelectedNodes(dataTable_templates); - - - var dialog = $('#template_template_update_dialog'); - $('#template_template_update_select',dialog).html(select); - $('#template_template_update_textarea',dialog).val(""); - $('#template_template_update_public',dialog).removeAttr('checked') - - if (sel_elems.length >= 1){ //several items in the list are selected - //grep them - var new_select= sel_elems.length > 1? '' : ""; - $('option','').each(function(){ - var val = $(this).val(); - if ($.inArray(val,sel_elems) >= 0){ - new_select+=''; - }; - }); - $('#template_template_update_select',dialog).html(new_select); - if (sel_elems.length == 1) { - $('#template_template_update_select option',dialog).attr('selected','selected'); - $('#template_template_update_select',dialog).trigger("change"); - }; - - }; - - dialog.dialog('open'); - return false; - -}; - -// Set the autorefresh interval for the datatable -function setTemplateAutorefresh() { - setInterval(function(){ - var checked = $('input.check_item:checked',dataTable_templates); - var filter = $("#datatable_templates_filter input", - dataTable_templates.parents('#datatable_templates_wrapper')).attr('value'); - if (!checked.length && !filter.length){ - Sunstone.runAction("Template.autorefresh"); - } - },INTERVAL+someTime()); -} - -function is_public_template(id){ - var data = getElementData(id,"#template",dataTable_templates)[6]; - return $(data).attr('checked'); -}; - -function setupTemplateActionCheckboxes(){ - $('input.action_cb#cb_public_template',dataTable_templates).live("click",function(){ - var $this = $(this) - var id=$this.attr('elem_id'); - if ($this.attr('checked')) - Sunstone.runAction("Template.publish",id); - else Sunstone.runAction("Template.unpublish",id); - - return true; - }); -} - -//The DOM is ready at this point -$(document).ready(function(){ - - dataTable_templates = $("#datatable_templates",main_tabs_context).dataTable({ - "bJQueryUI": true, - "bSortClasses": false, - "bAutoWidth":false, - "sPaginationType": "full_numbers", - "aoColumnDefs": [ - { "bSortable": false, "aTargets": ["check"] }, - { "sWidth": "60px", "aTargets": [0,6] }, - { "sWidth": "35px", "aTargets": [1] }, - { "sWidth": "150px", "aTargets": [5] }, - { "sWidth": "100px", "aTargets": [2,3] } - ], - "oLanguage": (datatable_lang != "") ? - { - sUrl: "locale/"+lang+"/"+datatable_lang - } : "" - }); - - dataTable_templates.fnClearTable(); - addElement([ - spinner, - '','','','','',''],dataTable_templates); - Sunstone.runAction("Template.list"); - - setupCreateTemplateDialog(); - setupTemplateTemplateUpdateDialog(); - setupTemplateActionCheckboxes(); - setTemplateAutorefresh(); - - initCheckAllBoxes(dataTable_templates); - tableCheckboxesListener(dataTable_templates); - templateInfoListener(); -}) diff --git a/src/cloud/occi/lib/ui/public/js/plugins/users-tab.js b/src/cloud/occi/lib/ui/public/js/plugins/users-tab.js deleted file mode 100644 index 5ce9543a75..0000000000 --- a/src/cloud/occi/lib/ui/public/js/plugins/users-tab.js +++ /dev/null @@ -1,482 +0,0 @@ -/* -------------------------------------------------------------------------- */ -/* 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. */ -/* -------------------------------------------------------------------------- */ - -/*Users tab plugin*/ -var dataTable_users; -var users_select=""; -var $create_user_dialog; -var $update_pw_dialog; - -var users_tab_content = -'
\ -
\ -
\ -\ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ -
'+tr("All")+''+tr("ID")+''+tr("Name")+''+tr("Group")+''+tr("Authentication driver")+'
\ -
'; - -var create_user_tmpl = -'
\ -
\ -
\ - \ -
\ - \ - \ - \ - \ -
\ -
\ -
\ -
\ - \ - \ -
\ -
\ -
'; - -var update_pw_tmpl = '
\ -
\ -
\ -
'+tr("This will change the password for the selected users")+':
\ - \ - \ -
\ -
\ -
\ -
\ - \ - \ -
\ -
\ -
'; - - -var user_actions = { - "User.create" : { - type: "create", - call: OpenNebula.User.create, - callback: addUserElement, - error: onError, - notify: true - }, - - "User.create_dialog" : { - type: "custom", - call: popUpCreateUserDialog - }, - - "User.list" : { - type: "list", - call: OpenNebula.User.list, - callback: updateUsersView, - error: onError - }, - - "User.refresh" : { - type: "custom", - call: function () { - waitingNodes(dataTable_users); - Sunstone.runAction("User.list"); - }, - }, - - "User.autorefresh" : { - type: "custom", - call: function(){ - OpenNebula.User.list({ - timeout: true, - success: updateUsersView, - error: onError - }); - } - }, - - "User.update_password" : { - type: "custom", - call: popUpUpdatePasswordDialog - }, - - "User.passwd" : { - type: "multiple", - call: OpenNebula.User.passwd, - //nocallback - elements: userElements, - error: onError - }, - "User.chgrp" : { - type: "multiple", - call: OpenNebula.User.chgrp, - callback : function(req){ - Sunstone.runAction("User.show",req.request.data[0]); - }, - elements : userElements, - error: onError, - notify: true - }, - - "User.chauth" : { - type: "multiple", - call: OpenNebula.User.chauth, - callback : function(req){ - Sunstone.runAction("User.show",req.request.data[0]); - }, - elements: userElements, - error: onError, - notify: true - }, - - // "User.addgroup" : { - // type: "multiple", - // call: OpenNebula.User.addgroup, - // callback : function(req){ - // Sunstone.runAction("User.show",req.request.data[0]); - // }, - // elements : function() {return getSelectedNodes(dataTable_users);}, - // error: onError, - // notify: true - // }, - - // "User.delgroup" : { - // type: "multiple", - // call: OpenNebula.User.delgroup, - // callback : function(req){ - // Sunstone.runAction("User.show",req.request.data[0]); - // }, - // elements : function() {return getSelectedNodes(dataTable_users);}, - // error: onError, - // notify: true - // }, - - "User.show" : { - type: "single", - call: OpenNebula.User.show, - callback: updateUserElement, - error: onError - }, - - "User.delete" : { - type: "multiple", - call: OpenNebula.User.delete, - callback: deleteUserElement, - elements: userElements, - error: onError, - notify: true - }, - - "User.fetch_template" : { - type: "single", - call: OpenNebula.User.fetch_template, - callback: function (request,response) { - $('#template_update_dialog #template_update_textarea').val(response.template); - }, - error: onError - }, - - "User.update_dialog" : { - type: "custom", - call: function() { - popUpTemplateUpdateDialog("User", - makeSelectOptions(dataTable_users, - 1,//id_col - 2,//name_col - [], - [] - ), - getSelectedNodes(dataTable_users)); - } - }, - - "User.update" : { - type: "single", - call: OpenNebula.User.update, - callback: function() { - notifyMessage(tr("Template updated correctly")); - }, - error: onError - } - -} - -var user_buttons = { - "User.refresh" : { - type: "image", - text: tr("Refresh list"), - img: "images/Refresh-icon.png" - }, - "User.create_dialog" : { - type: "create_dialog", - text: tr("+ New") - }, - "User.update_dialog" : { - type: "action", - text: tr("Update a template"), - alwaysActive: true - }, - "User.update_password" : { - type : "action", - text : tr("Change password"), - }, - "User.chgrp" : { - type: "confirm_with_select", - text: tr("Change group"), - select: groups_sel, - tip: tr("This will change the main group of the selected users. Select the new group")+":" - }, - "User.chauth" : { - type: "confirm_with_select", - text: tr("Change authentication"), - select: function() { - return '\ - \ - \ - \ - \ - ' - }, - tip: tr("Please choose the new type of authentication for the selected users")+":" - }, - // "User.addgroup" : { - // type: "confirm_with_select", - // text: "Add to group", - // select: function(){ return groups_select; }, - // tip: "Select the new group to add users:", - // condition: True - // }, - // "User.delgroup" : { - // type: "confirm_with_select", - // text: "Delete from group", - // select: function(){ return groups_select; }, - // tip: "Select the group from which to delete users:", - // condition: True - // }, - "User.delete" : { - type: "action", - text: "Delete" - } -} - -var users_tab = { - title: tr("Users"), - content: users_tab_content, - buttons: user_buttons -} - -Sunstone.addActions(user_actions); -Sunstone.addMainTab('users_tab',users_tab); - -function userElements(){ - return getSelectedNodes(dataTable_users); -} - -// Returns an array with the values from the user_json ready to be -// added to the dataTable -function userElementArray(user_json){ - var user = user_json.USER; - - return [ - '', - user.ID, - user.NAME, - user.GNAME, - user.AUTH_DRIVER - ] -} - - -function updateUserSelect(){ - users_select = makeSelectOptions(dataTable_users, - 1,//id_col - 2,//name_col - [],//status_cols - []//bad status values - ); -} - -// Callback to refresh a single element from the dataTable -function updateUserElement(request, user_json){ - var id = user_json.USER.ID; - var element = userElementArray(user_json); - updateSingleElement(element,dataTable_users,'#user_'+id); -} - -// Callback to delete a single element from the dataTable -function deleteUserElement(req){ - deleteElement(dataTable_users,'#user_'+req.request.data); - updateUserSelect(); -} - -// Callback to add a single user element -function addUserElement(request,user_json){ - var element = userElementArray(user_json); - addElement(element,dataTable_users); - updateUserSelect(); -} - -// Callback to update the list of users -function updateUsersView(request,users_list){ - var user_list_array = []; - - $.each(users_list,function(){ - user_list_array.push(userElementArray(this)); - }); - updateView(user_list_array,dataTable_users); - updateDashboard("users",users_list); - updateUserSelect(); -} - -// Prepare the user creation dialog -function setupCreateUserDialog(){ - dialogs_context.append('
'); - $create_user_dialog = $('#create_user_dialog',dialogs_context); - var dialog = $create_user_dialog; - dialog.html(create_user_tmpl); - - //Prepare jquery dialog - dialog.dialog({ - autoOpen: false, - modal:true, - width: 400 - }); - - $('button',dialog).button(); - - $('#create_user_form',dialog).submit(function(){ - var user_name=$('#username',this).val(); - var user_password=$('#pass',this).val(); - var driver = $('#driver', this).val(); - - if (!user_name.length || !user_password.length){ - notifyError(tr("User name and password must be filled in")); - return false; - } - - var user_json = { "user" : - { "name" : user_name, - "password" : user_password, - "auth_driver" : driver - } - }; - Sunstone.runAction("User.create",user_json); - $create_user_dialog.dialog('close'); - return false; - }); -} - -function setupUpdatePasswordDialog(){ - dialogs_context.append('
'); - $update_pw_dialog = $('#update_user_pw_dialog',dialogs_context); - var dialog = $update_pw_dialog; - dialog.html(update_pw_tmpl); - - //Prepare jquery dialog - dialog.dialog({ - autoOpen: false, - modal:true, - width: 400 - }); - - $('button',dialog).button(); - - $('#update_user_pw_form',dialog).submit(function(){ - var pw=$('#new_password',this).val(); - - if (!pw.length){ - notifyError(tr("Fill in a new password")); - return false; - } - - Sunstone.runAction("User.passwd",getSelectedNodes(dataTable_users),pw); - $update_pw_dialog.dialog('close'); - return false; - }); -}; - -function popUpCreateUserDialog(){ - $create_user_dialog.dialog('open'); -} - - -function popUpUpdatePasswordDialog(){ - $update_pw_dialog.dialog('open'); -} - - - -// Prepare the autorefresh of the list -function setUserAutorefresh(){ - setInterval(function(){ - var checked = $('input.check_item:checked',dataTable_users); - var filter = $("#datatable_users_filter input", - dataTable_users.parents("#datatable_users_wrapper")).attr('value'); - if (!checked.length && !filter.length){ - Sunstone.runAction("User.autorefresh"); - } - },INTERVAL+someTime()); -} - -$(document).ready(function(){ - //if we are not oneadmin, our tab will not even be in the DOM. - dataTable_users = $("#datatable_users",main_tabs_context).dataTable({ - "bJQueryUI": true, - "bSortClasses": false, - "sPaginationType": "full_numbers", - "bAutoWidth":false, - "aoColumnDefs": [ - { "bSortable": false, "aTargets": ["check"] }, - { "sWidth": "60px", "aTargets": [0] }, - { "sWidth": "35px", "aTargets": [1] }, - { "sWidth": "150px", "aTargets": [4] } - ], - "oLanguage": (datatable_lang != "") ? - { - sUrl: "locale/"+lang+"/"+datatable_lang - } : "" - }); - dataTable_users.fnClearTable(); - addElement([ - spinner, - '','','',''],dataTable_users); - - Sunstone.runAction("User.list"); - - setupCreateUserDialog(); - setupUpdatePasswordDialog(); - setUserAutorefresh(); - - initCheckAllBoxes(dataTable_users); - tableCheckboxesListener(dataTable_users); - //shortenedInfoFields('#datatable_users'); - -}) diff --git a/src/cloud/occi/lib/ui/public/js/plugins/vnets-tab.js b/src/cloud/occi/lib/ui/public/js/plugins/vnets-tab.js deleted file mode 100644 index 284dcce0b1..0000000000 --- a/src/cloud/occi/lib/ui/public/js/plugins/vnets-tab.js +++ /dev/null @@ -1,1050 +0,0 @@ -/* -------------------------------------------------------------------------- */ -/* 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. */ -/* -------------------------------------------------------------------------- */ - -/*Virtual networks tab plugin*/ - -var vnets_tab_content = -'
\ -
\ -
\ -\ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ -
'+tr("All")+''+tr("ID")+''+tr("Owner")+''+tr("Group")+''+tr("Name")+''+tr("Type")+''+tr("Bridge")+''+tr("Public")+''+tr("Total Leases")+'
\ -
'; - -var create_vn_tmpl = -'
\ - \ -
\ -
\ -
\ - \ -
\ -
\ -
\ - \ -
\ -
\ -
\ - \ - '+tr("Fixed network")+'
\ - '+tr("Ranged network")+'
\ -
\ -
\ -
\ -
\ -
\ - \ -
\ - \ - \ -
\ - \ - \ - \ -
\ -
\ -
\ -
\ -
\ - \ -
\ - \ -
\ - \ -
\ - \ -
\ - \ - \ -
\ -
\ -
\ -
\ - \ -
\ -
\ - \ -
\ - \ -
\ - \ - \ -
\ - \ - \ -
\ -
\ -
\ -
\ - \ - \ -
\ -
\ -
\ -
\ -
\ -
\ -

'+tr("Write the Virtual Network template here")+'

\ -
\ - \ -
\ -
\ -
\ -
\ - \ - \ -
\ -
\ -
\ -
\ -
'; - -var update_vnet_tmpl = - '
\ -

'+tr("Please, choose and modify the virtual network you want to update")+':

\ -
\ - \ - \ -
\ -
\ - \ - \ -
\ - \ -
\ - \ -
\ -
\ -
\ - \ -
\ -
\ -
'; - -var dataTable_vNetworks; -var $create_vn_dialog; -var $lease_vn_dialog; - -//Setup actions - -var vnet_actions = { - "Network.create" : { - type: "create", - call: OpenNebula.Network.create, - callback: addVNetworkElement, - error: onError, - notify: true - }, - - "Network.create_dialog" : { - type: "custom", - call: popUpCreateVnetDialog - }, - - "Network.list" : { - type: "list", - call: OpenNebula.Network.list, - callback: updateVNetworksView, - error: onError - }, - - "Network.show" : { - type: "single", - call: OpenNebula.Network.show, - callback: updateVNetworkElement, - error: onError - }, - - "Network.showinfo" : { - type: "single", - call: OpenNebula.Network.show, - callback: updateVNetworkInfo, - error: onError - - }, - - "Network.refresh" : { - type: "custom", - call: function(){ - waitingNodes(dataTable_vNetworks); - Sunstone.runAction("Network.list"); - } - }, - - "Network.autorefresh" : { - type: "custom", - call: function() { - OpenNebula.Network.list({timeout: true, success: updateVNetworksView, error: onError}); - } - }, - - "Network.publish" : { - type: "multiple", - call: OpenNebula.Network.publish, - callback: vnShow, - elements: vnElements, - error: onError, - notify: true - }, - - "Network.unpublish" : { - type: "multiple", - call: OpenNebula.Network.unpublish, - callback: vnShow, - elements: vnElements, - error: onError, - notify: true - }, - - "Network.delete" : { - type: "multiple", - call: OpenNebula.Network.delete, - callback: deleteVNetworkElement, - elements: vnElements, - error: onError, - notify: true - }, - - "Network.addleases" : { - type: "single", - call: OpenNebula.Network.addleases, - callback: vnShow, - error: onError, - notify: false, - }, - - "Network.rmleases" : { - type: "single", - call: OpenNebula.Network.rmleases, - callback: vnShow, - error: onError, - notify: false, - }, - - "Network.hold" : { - type: "single", - call: OpenNebula.Network.hold, - callback: vnShow, - error: onError, - notify: false, - }, - - "Network.release" : { - type: "single", - call: OpenNebula.Network.release, - callback: vnShow, - error: onError, - notify: false, - }, - - "Network.chown" : { - type: "multiple", - call: OpenNebula.Network.chown, - callback: vnShow, - elements: vnElements, - error:onError, - notify: true - }, - - "Network.chgrp" : { - type: "multiple", - call: OpenNebula.Network.chgrp, - callback: vnShow, - elements: vnElements, - error:onError, - notify: true - }, - - "Network.fetch_template" : { - type: "single", - call: OpenNebula.Network.fetch_template, - callback: function (request,response) { - $('#vnet_template_update_dialog #vnet_template_update_textarea').val(response.template); - }, - error: onError - }, - - "Network.update_dialog" : { - type: "custom", - call: function() { - popUpVNetTemplateUpdateDialog(); - } - }, - - "Network.update" : { - type: "single", - call: OpenNebula.Network.update, - callback: function() { - notifyMessage("Template updated correctly"); - }, - error: onError - }, - -}; - - -var vnet_buttons = { - "Network.refresh" : { - type: "image", - text: tr("Refresh list"), - img: "images/Refresh-icon.png" - }, - - "Network.create_dialog" : { - type: "create_dialog", - text: tr("+ New") - }, - - "Network.update_dialog" : { - type: "action", - text: tr("Update a template"), - alwaysActive: true - }, - - "Network.publish" : { - type: "action", - text: tr("Publish") - }, - - "Network.unpublish" : { - type: "action", - text: tr("Unpublish") - }, - - "Network.chown" : { - type: "confirm_with_select", - text: tr("Change owner"), - select: users_sel, - tip: tr("Select the new owner")+":", - condition: mustBeAdmin - }, - - "Network.chgrp" : { - type: "confirm_with_select", - text: "Change group", - select: groups_sel, - tip: tr("Select the new group")+":", - condition: mustBeAdmin, - }, - - "Network.delete" : { - type: "action", - text: tr("Delete") - } -} - -var vnet_info_panel = { - "vnet_info_tab" : { - title: tr("Virtual network information"), - content: "" - }, - "vnet_leases_tab" : { - title: tr("Lease management"), - content: "" - }, -} - -var vnets_tab = { - title: tr("Virtual Networks"), - content: vnets_tab_content, - buttons: vnet_buttons -} - -Sunstone.addActions(vnet_actions); -Sunstone.addMainTab('vnets_tab',vnets_tab); -Sunstone.addInfoPanel('vnet_info_panel',vnet_info_panel); - - -function vnElements(){ - return getSelectedNodes(dataTable_vNetworks); -} - -function vnShow(req){ - Sunstone.runAction("Network.show",req.request.data[0]); -} - -//returns an array with the VNET information fetched from the JSON object -function vNetworkElementArray(vn_json){ - var network = vn_json.VNET; - - return [ - '', - network.ID, - network.UNAME, - network.GNAME, - network.NAME, - parseInt(network.TYPE) ? "FIXED" : "RANGED", - network.BRIDGE, - parseInt(network.PUBLIC) ? '' - : '', - network.TOTAL_LEASES ]; -} - - -//Adds a listener to show the extended info when clicking on a row -function vNetworkInfoListener(){ - - $('#tbodyvnetworks tr',dataTable_vNetworks).live("click", function(e){ - if ($(e.target).is('input')) {return true;} - popDialogLoading(); - var aData = dataTable_vNetworks.fnGetData(this); - var id = $(aData[0]).val(); - Sunstone.runAction("Network.showinfo",id); - return false; - }); -} - -//Callback to update a vnet element after an action on it -function updateVNetworkElement(request, vn_json){ - id = vn_json.VNET.ID; - element = vNetworkElementArray(vn_json); - updateSingleElement(element,dataTable_vNetworks,'#vnetwork_'+id); - - //we update this too, even if it's not shown. - $('#leases_form').replaceWith(printLeases(vn_json.VNET)); -} - -//Callback to delete a vnet element from the table -function deleteVNetworkElement(req){ - deleteElement(dataTable_vNetworks,'#vnetwork_'+req.request.data); -} - -//Callback to add a new element -function addVNetworkElement(request,vn_json){ - var element = vNetworkElementArray(vn_json); - addElement(element,dataTable_vNetworks); - //we update this too, even if it's not shown. - $('#leases_form').replaceWith(printLeases(vn_json.VNET)); -} - -//updates the list of virtual networks -function updateVNetworksView(request, network_list){ - var network_list_array = []; - - $.each(network_list,function(){ - network_list_array.push(vNetworkElementArray(this)); - }); - - updateView(network_list_array,dataTable_vNetworks); - //dependency with dashboard - updateDashboard("vnets",network_list); - -} - -//updates the information panel tabs and pops the panel up -function updateVNetworkInfo(request,vn){ - var vn_info = vn.VNET; - var info_tab_content = - '\ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ -
'+tr("Virtual Network")+' '+vn_info.ID+' '+ - tr("information")+'
'+tr("ID")+''+vn_info.ID+'
'+tr("Name")+''+vn_info.NAME+'
'+tr("Owner")+''+vn_info.UNAME+'
'+tr("Group")+''+vn_info.GNAME+'
'+tr("Public")+''+(parseInt(vn_info.PUBLIC) ? "yes" : "no" )+'
'+tr("Physical device")+''+ (typeof(vn_info.PHYDEV) == "object" ? "--": vn_info.PHYDEV) +'
'+tr("VNET ID")+''+ (typeof(vn_info.VLAN_ID) == "object" ? "--": vn_info.VLAN_ID) +'
'; - - info_tab_content += '\ - \ - '+ - prettyPrintJSON(vn_info.TEMPLATE)+ - '
'+tr("Virtual Network template (attributes)")+'
'; - - - var leases_tab_content = printLeases(vn_info); - - var info_tab = { - title: tr("Virtual Network information"), - content: info_tab_content - }; - - var leases_tab = { - title: "Lease management", - content: leases_tab_content - }; - - Sunstone.updateInfoPanelTab("vnet_info_panel","vnet_info_tab",info_tab); - Sunstone.updateInfoPanelTab("vnet_info_panel","vnet_leases_tab",leases_tab); - - Sunstone.popUpInfoPanel("vnet_info_panel"); - -} - -function printLeases(vn_info){ - var html ='
\ - \ - \ - '; - - if (vn_info.TYPE == "0"){ - html += '\ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - '; - } else { - html += ''; - }; - - var leases = vn_info.LEASES.LEASE; - - if (!leases) //empty - { - html+='\ - '; - return html; - } - else if (leases.constructor != Array) //>1 lease - { - leases = [leases]; - }; - - var lease; - var state=null; - - for (var i=0; i'; - }; - - html += '
'+tr("Leases information")+'
'+tr("IP Start")+''+vn_info.RANGE.IP_START+'
'+tr("IP End")+''+vn_info.RANGE.IP_END+'
'+tr("Network mask")+''+( vn_info.TEMPLATE.NETWORK_MASK ? vn_info.TEMPLATE.NETWORK_MASK : "--" )+'
\ - \ - \ -
\ - \ - \ -
\ - '+tr("No leases to show")+'\ - \ -
'; - html+=''; - - html += '\ - '+lease.MAC+'   '; - - switch (state){ - case 0: - html += ''+tr("hold")+' | '+tr("delete")+''; - break; - case 1: - html += tr("Used by VM")+' '+lease.VID; - break; - case 2: - html += ''+tr("release")+''; - break; - }; - html += '
'; - - return html; -} - -//Prepares the vnet creation dialog -function setupCreateVNetDialog() { - dialogs_context.append('
'); - $create_vn_dialog = $('#create_vn_dialog',dialogs_context) - var dialog = $create_vn_dialog; - dialog.html(create_vn_tmpl); - - var height = Math.floor($(window).height()*0.8); //set height to a percentage of the window - - //Prepare the jquery-ui dialog. Set style options here. - dialog.dialog({ - autoOpen: false, - modal: true, - width: 475, - height: height - }); - - //Make the tabs look nice for the creation mode - $('#vn_tabs',dialog).tabs(); - $('div#ranged',dialog).hide(); - $('#fixed_check',dialog).click(function(){ - $('div#fixed',$create_vn_dialog).show(); - $('div#ranged',$create_vn_dialog).hide(); - }); - $('#ranged_check',dialog).click(function(){ - $('div#fixed',$create_vn_dialog).hide(); - $('div#ranged',$create_vn_dialog).show(); - }); - $('button',dialog).button(); - - - //When we hit the add lease button... - $('#add_lease',dialog).click(function(){ - var create_form = $('#create_vn_form_easy',$create_vn_dialog); //this is our scope - - //Fetch the interesting values - var lease_ip = $('#leaseip',create_form).val(); - var lease_mac = $('#leasemac',create_form).val(); - - //We don't add anything to the list if there is nothing to add - if (lease_ip == null) { - notifyError(tr("Please provide a lease IP")); - return false; - }; - - var lease = ""; //contains the HTML to be included in the select box - if (lease_mac == "") { - lease=''; - } else { - lease=''; - }; - - //We append the HTML into the select box. - $('select#leases',$create_vn_dialog).append(lease); - return false; - }); - - $('#remove_lease', dialog).click(function(){ - $('select#leases :selected',$create_vn_dialog).remove(); - return false; - }); - - $('#custom_pool', dialog).change(function(){ - if ($(this).is(':checked')){ - $('#ip_start', $create_vn_dialog).removeAttr('disabled'); - $('#ip_end', $create_vn_dialog).removeAttr('disabled'); - } - else { - $('#ip_start', $create_vn_dialog).attr('disabled','disabled'); - $('#ip_end', $create_vn_dialog).attr('disabled','disabled'); - }; - }); - - - $('#add_custom_var_vnet_button', dialog).click( - function(){ - var name = $('#custom_var_vnet_name',$create_vn_dialog).val(); - var value = $('#custom_var_vnet_value',$create_vn_dialog).val(); - if (!name.length || !value.length) { - notifyError("Custom attribute name and value must be filled in"); - return false; - } - option= ''; - $('select#custom_var_vnet_box',$create_vn_dialog).append(option); - return false; - } - ); - - $('#remove_custom_var_vnet_button', dialog).click( - function(){ - $('select#custom_var_vnet_box :selected',$create_vn_dialog).remove(); - return false; - } - ); - - - //Handle submission of the easy mode - $('#create_vn_form_easy',dialog).submit(function(){ - //Fetch values - var name = $('#name',this).val(); - if (!name.length){ - notifyError(tr("Virtual Network name missing!")); - return false; - } - var bridge = $('#bridge',this).val(); - var type = $('input:checked',this).val(); - - //TODO: Name and bridge provided?! - - var network_json = null; - if (type == "fixed") { - var leases = $('#leases option', this); - var leases_obj=[]; - - //for each specified lease we prepare the JSON object - $.each(leases,function(){ - leases_obj.push({"ip": $(this).val() }); - }); - - //and construct the final data for the request - network_json = { - "vnet" : { - "type" : "FIXED", - "leases" : leases_obj, - "bridge" : bridge, - "name" : name }}; - } - else { //type ranged - - var network_addr = $('#net_address',this).val(); - var network_mask = $('#net_mask',this).val(); - var custom = $('#custom_pool',this).is(':checked'); - var ip_start = $('#ip_start',this).val(); - var ip_end = $('#ip_end',this).val(); - - if (!network_addr.length){ - notifyError(tr("Please provide a network address")); - return false; - }; - - //we form the object for the request - network_json = { - "vnet" : { - "type" : "RANGED", - "bridge" : bridge, - "network_mask" : network_mask, - "network_address" : network_addr, - "name" : name } - }; - - if (custom){ - if (ip_start.length) - network_json["vnet"]["ip_start"] = ip_start; - if (ip_end.length) - network_json["vnet"]["ip_start"] = ip_end; - }; - }; - - //Time to add custom attributes - $('#custom_var_vnet_box option',$create_vn_dialog).each(function(){ - var attr_name = $(this).attr('name'); - var attr_value = $(this).val(); - network_json["vnet"][attr_name] = attr_value; - }); - - //Create the VNetwork. - - Sunstone.runAction("Network.create",network_json); - $create_vn_dialog.dialog('close'); - return false; - }); - - $('#create_vn_form_manual',dialog).submit(function(){ - var template=$('#template',this).val(); - var vnet_json = {vnet: {vnet_raw: template}}; - Sunstone.runAction("Network.create",vnet_json); - $create_vn_dialog.dialog('close'); - return false; - }); -} - -function popUpCreateVnetDialog() { - $create_vn_dialog.dialog('open'); -} - - -function setupVNetTemplateUpdateDialog(){ - //Append to DOM - dialogs_context.append('
'); - var dialog = $('#vnet_template_update_dialog',dialogs_context); - - //Put HTML in place - dialog.html(update_vnet_tmpl); - - //Convert into jQuery - dialog.dialog({ - autoOpen:false, - width:700, - modal:true, - height:480, - resizable:false, - }); - - $('button',dialog).button(); - - $('#vnet_template_update_select',dialog).change(function(){ - var id = $(this).val(); - if (id && id.length){ - var dialog = $('#vnet_template_update_dialog'); - $('#vnet_template_update_textarea',dialog).val(tr("Loading")+"..."); - - var vnet_public = is_public_vnet(id); - - if (vnet_public){ - $('#vnet_template_update_public',dialog).attr('checked','checked') - } else { - $('#vnet_template_update_public',dialog).removeAttr('checked') - } - - Sunstone.runAction("Network.fetch_template",id); - } else { - $('#vnet_template_update_textarea',dialog).val(""); - }; - }); - - $('#vnet_template_update_button',dialog).click(function(){ - var dialog = $('#vnet_template_update_dialog'); - var new_template = $('#vnet_template_update_textarea',dialog).val(); - var id = $('#vnet_template_update_select',dialog).val(); - if (!id || !id.length) { - dialog.dialog('close'); - return false; - }; - - var old_public = is_public_vnet(id); - - var new_public = $('#vnet_template_update_public:checked',dialog).length; - - if (old_public != new_public){ - if (new_public) Sunstone.runAction("Network.publish",id); - else Sunstone.runAction("Network.unpublish",id); - }; - - Sunstone.runAction("Network.update",id,new_template); - dialog.dialog('close'); - return false; - }); -}; - -function popUpVNetTemplateUpdateDialog(){ - var select = makeSelectOptions(dataTable_vNetworks, - 1,//id_col - 4,//name_col - [], - [] - ); - var sel_elems = getSelectedNodes(dataTable_vNetworks); - - - var dialog = $('#vnet_template_update_dialog'); - $('#vnet_template_update_select',dialog).html(select); - $('#vnet_template_update_textarea',dialog).val(""); - $('#vnet_template_update_public',dialog).removeAttr('checked') - - if (sel_elems.length >= 1){ //several items in the list are selected - //grep them - var new_select= sel_elems.length > 1? '' : ""; - $('option','').each(function(){ - var val = $(this).val(); - if ($.inArray(val,sel_elems) >= 0){ - new_select+=''; - }; - }); - $('#vnet_template_update_select',dialog).html(new_select); - if (sel_elems.length == 1) { - $('#vnet_template_update_select option',dialog).attr('selected','selected'); - $('#vnet_template_update_select',dialog).trigger("change"); - } - - }; - - dialog.dialog('open'); - return false; - -} - -function setupLeasesOps(){ - $('button#panel_add_lease_button').live("click",function(){ - var lease = $(this).prev().val(); - //var mac = $(this).previous().val(); - var id = $(this).parents('form').attr('vnid'); - if (lease.length){ - var obj = {ip: lease}; - Sunstone.runAction('Network.addleases',id,obj); - } - return false; - }); - - $('button#panel_hold_lease_button').live("click",function(){ - var lease = $(this).prev().val(); - //var mac = $(this).previous().val(); - var id = $(this).parents('form').attr('vnid'); - if (lease.length){ - var obj = {ip: lease}; - Sunstone.runAction('Network.hold',id,obj); - } - return false; - }); - - $('form#leases_form a.delete_lease').live("click",function(){ - var lease = $(this).parents('tr').attr('ip'); - var id = $(this).parents('form').attr('vnid'); - var obj = { ip: lease}; - Sunstone.runAction('Network.rmleases',id,obj); - //Set spinner - $(this).parents('tr').html(''+spinner+''); - return false; - }); - - $('a.hold_lease').live("click",function(){ - var lease = $(this).parents('tr').attr('ip'); - var id = $(this).parents('form').attr('vnid'); - var obj = { ip: lease}; - Sunstone.runAction('Network.hold',id,obj); - //Set spinner - $(this).parents('tr').html(''+spinner+''); - return false; - }); - - $('a.release_lease').live("click",function(){ - var lease = $(this).parents('tr').attr('ip'); - var id = $(this).parents('form').attr('vnid'); - var obj = { ip: lease}; - Sunstone.runAction('Network.release',id,obj); - //Set spinner - $(this).parents('tr').html(''+spinner+''); - return false; - }); -} - -function setVNetAutorefresh() { - setInterval(function(){ - var checked = $('input.check_item:checked',dataTable_vNetworks); - var filter = $("#datatable_vnetworks_filter input", - dataTable_vNetworks.parents("#datatable_vnetworks_wrapper")).attr('value'); - if (!checked.length && !filter.length){ - Sunstone.runAction("Network.autorefresh"); - } - },INTERVAL+someTime()); -}; - -function is_public_vnet(id) { - var data = getElementData(id,"#vnetwork",dataTable_vNetworks)[7]; - return $(data).is(":checked"); -}; - -function setupVNetActionCheckboxes(){ - $('input.action_cb#cb_public_vnet',dataTable_vNetworks).live("click",function(){ - var $this = $(this) - var id=$this.attr('elem_id'); - if ($this.attr('checked')) - Sunstone.runAction("Network.publish",id); - else Sunstone.runAction("Network.unpublish",id); - - return true; - }); -} - -//The DOM is ready and the ready() from sunstone.js -//has been executed at this point. -$(document).ready(function(){ - - dataTable_vNetworks = $("#datatable_vnetworks",main_tabs_context).dataTable({ - "bJQueryUI": true, - "bSortClasses": false, - "bAutoWidth":false, - "sPaginationType": "full_numbers", - "aoColumnDefs": [ - { "bSortable": false, "aTargets": ["check"] }, - { "sWidth": "60px", "aTargets": [0,5,6,7,8] }, - { "sWidth": "35px", "aTargets": [1] }, - { "sWidth": "100px", "aTargets": [2,3] } - ], - "oLanguage": (datatable_lang != "") ? - { - sUrl: "locale/"+lang+"/"+datatable_lang - } : "" - }); - - dataTable_vNetworks.fnClearTable(); - addElement([ - spinner, - '','','','','','','',''],dataTable_vNetworks); - Sunstone.runAction("Network.list"); - - setupCreateVNetDialog(); - setupVNetTemplateUpdateDialog(); - setupLeasesOps(); - setupVNetActionCheckboxes(); - setVNetAutorefresh(); - - initCheckAllBoxes(dataTable_vNetworks); - tableCheckboxesListener(dataTable_vNetworks); - vNetworkInfoListener(); -}); diff --git a/src/cloud/occi/lib/ui/public/js/sunstone-util.js b/src/cloud/occi/lib/ui/public/js/sunstone-util.js index e3fd24b939..99feaa75ff 100644 --- a/src/cloud/occi/lib/ui/public/js/sunstone-util.js +++ b/src/cloud/occi/lib/ui/public/js/sunstone-util.js @@ -498,9 +498,11 @@ function getSelectedNodes(dataTable){ function makeSelectOptions(dataTable, id_col,name_col, status_cols, - bad_status_values){ + bad_status_values,no_empty_opt){ var nodes = dataTable.fnGetData(); - var select = ''; + var select = ""; + if (!no_empty_opt) + select = ''; var array; for (var j=0; j>>32-c},rotr:function(a,c){return a<<32-c|a>>>c},endian:function(a){if(a.constructor==Number)return l.rotl(a,8)&16711935|l.rotl(a,24)&4278255360;for(var c=0;c0;a--)c.push(Math.floor(Math.random()*256));return c},bytesToWords:function(a){for(var c=[],b=0,d=0;b>>5]|=a[b]<<24- +d%32;return c},wordsToBytes:function(a){for(var c=[],b=0;b>>5]>>>24-b%32&255);return c},bytesToHex:function(a){for(var c=[],b=0;b>>4).toString(16));c.push((a[b]&15).toString(16))}return c.join("")},hexToBytes:function(a){for(var c=[],b=0;b>>6*(3-e)&63)):c.push("=");return c.join("")},base64ToBytes:function(a){if(typeof atob=="function")return m.stringToBytes(atob(a));a=a.replace(/[^A-Z0-9+\/]/ig,"");for(var c=[],b=0,d=0;b>> +6-d*2);return c}};k=k.charenc={};k.UTF8={stringToBytes:function(a){return m.stringToBytes(unescape(encodeURIComponent(a)))},bytesToString:function(a){return decodeURIComponent(escape(m.bytesToString(a)))}};var m=k.Binary={stringToBytes:function(a){for(var c=[],b=0;b>5]|=128<<24-g%32;e[(g+64>>>9<<4)+15]=g;for(g=0;g>>31}p=(n<<5|n>>>27)+o+(d[f]>>>0)+(f<20?(h&i|~h&j)+1518500249:f<40?(h^i^j)+1859775393:f<60?(h&i|h&j|i&j)-1894007588:(h^i^j)-899497514);o=j;j=i;i=h<<30|h>>>2;h=n;n=p}n+=q;h+=r;i+=s;j+=t;o+=u}return[n,h,i,j,o]};b._blocksize=16;b._digestsize=20})(); diff --git a/src/cloud/occi/lib/ui/public/vendor/crypto-js/NEW-BSD-LICENSE.txt b/src/cloud/occi/lib/ui/public/vendor/crypto-js/NEW-BSD-LICENSE.txt new file mode 100644 index 0000000000..f783af78b8 --- /dev/null +++ b/src/cloud/occi/lib/ui/public/vendor/crypto-js/NEW-BSD-LICENSE.txt @@ -0,0 +1,9 @@ +© 2009–2011 by Jeff Mott. All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, this list of conditions, and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright notice, this list of conditions, and the following disclaimer in the documentation or other materials provided with the distribution. + * Neither the name Crypto-JS nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS," AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. \ No newline at end of file diff --git a/src/cloud/occi/lib/ui/public/vendor/crypto-js/NOTICE b/src/cloud/occi/lib/ui/public/vendor/crypto-js/NOTICE new file mode 100644 index 0000000000..5edf404cbd --- /dev/null +++ b/src/cloud/occi/lib/ui/public/vendor/crypto-js/NOTICE @@ -0,0 +1,6 @@ +THIRD-PARTY SOFTWARE + + * Author: Jeff Mott (http://code.google.com/u/Jeff.Mott.OR/) + * Info: http://code.google.com/p/crypto-js/ + * Copyright: Copyright 2009-2012 by Jeff Mott,all rights reserved. + * License: New BSD License. See NEW-BSD-LICENSE.txt diff --git a/src/cloud/occi/lib/ui/public/vendor/fileuploader/NOTICE b/src/cloud/occi/lib/ui/public/vendor/fileuploader/NOTICE new file mode 100644 index 0000000000..d229b7a22b --- /dev/null +++ b/src/cloud/occi/lib/ui/public/vendor/fileuploader/NOTICE @@ -0,0 +1,6 @@ +THIRD-PARTY SOFTWARE + + * Author: Andrew Valums (http://github.com/valums) + * Info: https://github.com/valums/file-uploader + * Copyright: Copyright 2010 Andrew Valums. + * License: GNU GPL 2 or later (http://www.gnu.org/licenses/gpl-2.0.html) and GNU LGPL 2 or later (http://www.gnu.org/licenses/lgpl-2.1.html) diff --git a/src/cloud/occi/lib/ui/public/vendor/fileuploader/fileuploader.js b/src/cloud/occi/lib/ui/public/vendor/fileuploader/fileuploader.js new file mode 100644 index 0000000000..b4eac37e48 --- /dev/null +++ b/src/cloud/occi/lib/ui/public/vendor/fileuploader/fileuploader.js @@ -0,0 +1,1247 @@ +/** + * http://github.com/valums/file-uploader + * + * Multiple file upload component with progress-bar, drag-and-drop. + * © 2010 Andrew Valums ( andrew(at)valums.com ) + * + * Licensed under GNU GPL 2 or later and GNU LGPL 2 or later, see license.txt. + */ + +// +// Helper functions +// + +var qq = qq || {}; + +/** + * Adds all missing properties from second obj to first obj + */ +qq.extend = function(first, second){ + for (var prop in second){ + first[prop] = second[prop]; + } +}; + +/** + * Searches for a given element in the array, returns -1 if it is not present. + * @param {Number} [from] The index at which to begin the search + */ +qq.indexOf = function(arr, elt, from){ + if (arr.indexOf) return arr.indexOf(elt, from); + + from = from || 0; + var len = arr.length; + + if (from < 0) from += len; + + for (; from < len; from++){ + if (from in arr && arr[from] === elt){ + return from; + } + } + return -1; +}; + +qq.getUniqueId = (function(){ + var id = 0; + return function(){ return id++; }; +})(); + +// +// Events + +qq.attach = function(element, type, fn){ + if (element.addEventListener){ + element.addEventListener(type, fn, false); + } else if (element.attachEvent){ + element.attachEvent('on' + type, fn); + } +}; +qq.detach = function(element, type, fn){ + if (element.removeEventListener){ + element.removeEventListener(type, fn, false); + } else if (element.attachEvent){ + element.detachEvent('on' + type, fn); + } +}; + +qq.preventDefault = function(e){ + if (e.preventDefault){ + e.preventDefault(); + } else{ + e.returnValue = false; + } +}; + +// +// Node manipulations + +/** + * Insert node a before node b. + */ +qq.insertBefore = function(a, b){ + b.parentNode.insertBefore(a, b); +}; +qq.remove = function(element){ + element.parentNode.removeChild(element); +}; + +qq.contains = function(parent, descendant){ + // compareposition returns false in this case + if (parent == descendant) return true; + + if (parent.contains){ + return parent.contains(descendant); + } else { + return !!(descendant.compareDocumentPosition(parent) & 8); + } +}; + +/** + * Creates and returns element from html string + * Uses innerHTML to create an element + */ +qq.toElement = (function(){ + var div = document.createElement('div'); + return function(html){ + div.innerHTML = html; + var element = div.firstChild; + div.removeChild(element); + return element; + }; +})(); + +// +// Node properties and attributes + +/** + * Sets styles for an element. + * Fixes opacity in IE6-8. + */ +qq.css = function(element, styles){ + if (styles.opacity != null){ + if (typeof element.style.opacity != 'string' && typeof(element.filters) != 'undefined'){ + styles.filter = 'alpha(opacity=' + Math.round(100 * styles.opacity) + ')'; + } + } + qq.extend(element.style, styles); +}; +qq.hasClass = function(element, name){ + var re = new RegExp('(^| )' + name + '( |$)'); + return re.test(element.className); +}; +qq.addClass = function(element, name){ + if (!qq.hasClass(element, name)){ + element.className += ' ' + name; + } +}; +qq.removeClass = function(element, name){ + var re = new RegExp('(^| )' + name + '( |$)'); + element.className = element.className.replace(re, ' ').replace(/^\s+|\s+$/g, ""); +}; +qq.setText = function(element, text){ + element.innerText = text; + element.textContent = text; +}; + +// +// Selecting elements + +qq.children = function(element){ + var children = [], + child = element.firstChild; + + while (child){ + if (child.nodeType == 1){ + children.push(child); + } + child = child.nextSibling; + } + + return children; +}; + +qq.getByClass = function(element, className){ + if (element.querySelectorAll){ + return element.querySelectorAll('.' + className); + } + + var result = []; + var candidates = element.getElementsByTagName("*"); + var len = candidates.length; + + for (var i = 0; i < len; i++){ + if (qq.hasClass(candidates[i], className)){ + result.push(candidates[i]); + } + } + return result; +}; + +/** + * obj2url() takes a json-object as argument and generates + * a querystring. pretty much like jQuery.param() + * + * how to use: + * + * `qq.obj2url({a:'b',c:'d'},'http://any.url/upload?otherParam=value');` + * + * will result in: + * + * `http://any.url/upload?otherParam=value&a=b&c=d` + * + * @param Object JSON-Object + * @param String current querystring-part + * @return String encoded querystring + */ +qq.obj2url = function(obj, temp, prefixDone){ + var uristrings = [], + prefix = '&', + add = function(nextObj, i){ + var nextTemp = temp + ? (/\[\]$/.test(temp)) // prevent double-encoding + ? temp + : temp+'['+i+']' + : i; + if ((nextTemp != 'undefined') && (i != 'undefined')) { + uristrings.push( + (typeof nextObj === 'object') + ? qq.obj2url(nextObj, nextTemp, true) + : (Object.prototype.toString.call(nextObj) === '[object Function]') + ? encodeURIComponent(nextTemp) + '=' + encodeURIComponent(nextObj()) + : encodeURIComponent(nextTemp) + '=' + encodeURIComponent(nextObj) + ); + } + }; + + if (!prefixDone && temp) { + prefix = (/\?/.test(temp)) ? (/\?$/.test(temp)) ? '' : '&' : '?'; + uristrings.push(temp); + uristrings.push(qq.obj2url(obj)); + } else if ((Object.prototype.toString.call(obj) === '[object Array]') && (typeof obj != 'undefined') ) { + // we wont use a for-in-loop on an array (performance) + for (var i = 0, len = obj.length; i < len; ++i){ + add(obj[i], i); + } + } else if ((typeof obj != 'undefined') && (obj !== null) && (typeof obj === "object")){ + // for anything else but a scalar, we will use for-in-loop + for (var i in obj){ + add(obj[i], i); + } + } else { + uristrings.push(encodeURIComponent(temp) + '=' + encodeURIComponent(obj)); + } + + return uristrings.join(prefix) + .replace(/^&/, '') + .replace(/%20/g, '+'); +}; + +// +// +// Uploader Classes +// +// + +var qq = qq || {}; + +/** + * Creates upload button, validates upload, but doesn't create file list or dd. + */ +qq.FileUploaderBasic = function(o){ + this._options = { + // set to true to see the server response + debug: false, + action: '/server/upload', + params: {}, + button: null, + multiple: true, + maxConnections: 3, + // validation + allowedExtensions: [], + sizeLimit: 0, + minSizeLimit: 0, + // events + // return false to cancel submit + onSubmit: function(id, fileName){}, + onProgress: function(id, fileName, loaded, total){}, + onComplete: function(id, fileName, responseJSON){}, + onCancel: function(id, fileName){}, + // messages + messages: { + typeError: "{file} has invalid extension. Only {extensions} are allowed.", + sizeError: "{file} is too large, maximum file size is {sizeLimit}.", + minSizeError: "{file} is too small, minimum file size is {minSizeLimit}.", + emptyError: "{file} is empty, please select files again without it.", + onLeave: "The files are being uploaded, if you leave now the upload will be cancelled." + }, + showMessage: function(message){ + alert(message); + } + }; + qq.extend(this._options, o); + + // number of files being uploaded + this._filesInProgress = 0; + this._handler = this._createUploadHandler(); + + if (this._options.button){ + this._button = this._createUploadButton(this._options.button); + } + + this._preventLeaveInProgress(); +}; + +qq.FileUploaderBasic.prototype = { + setParams: function(params){ + this._options.params = params; + }, + getInProgress: function(){ + return this._filesInProgress; + }, + _createUploadButton: function(element){ + var self = this; + + return new qq.UploadButton({ + element: element, + multiple: this._options.multiple && qq.UploadHandlerXhr.isSupported(), + onChange: function(input){ + self._onInputChange(input); + } + }); + }, + _createUploadHandler: function(){ + var self = this, + handlerClass; + + if(qq.UploadHandlerXhr.isSupported()){ + handlerClass = 'UploadHandlerXhr'; + } else { + handlerClass = 'UploadHandlerForm'; + } + + var handler = new qq[handlerClass]({ + debug: this._options.debug, + action: this._options.action, + maxConnections: this._options.maxConnections, + onProgress: function(id, fileName, loaded, total){ + self._onProgress(id, fileName, loaded, total); + self._options.onProgress(id, fileName, loaded, total); + }, + onComplete: function(id, fileName, result){ + self._onComplete(id, fileName, result); + self._options.onComplete(id, fileName, result); + }, + onCancel: function(id, fileName){ + self._onCancel(id, fileName); + self._options.onCancel(id, fileName); + } + }); + + return handler; + }, + _preventLeaveInProgress: function(){ + var self = this; + + qq.attach(window, 'beforeunload', function(e){ + if (!self._filesInProgress){return;} + + var e = e || window.event; + // for ie, ff + e.returnValue = self._options.messages.onLeave; + // for webkit + return self._options.messages.onLeave; + }); + }, + _onSubmit: function(id, fileName){ + this._filesInProgress++; + }, + _onProgress: function(id, fileName, loaded, total){ + }, + _onComplete: function(id, fileName, result){ + this._filesInProgress--; + if (result.error){ + this._options.showMessage(result.error); + } + }, + _onCancel: function(id, fileName){ + this._filesInProgress--; + }, + _onInputChange: function(input){ + if (this._handler instanceof qq.UploadHandlerXhr){ + this._uploadFileList(input.files); + } else { + if (this._validateFile(input)){ + this._uploadFile(input); + } + } + this._button.reset(); + }, + _uploadFileList: function(files){ + for (var i=0; i this._options.sizeLimit){ + this._error('sizeError', name); + return false; + + } else if (size && size < this._options.minSizeLimit){ + this._error('minSizeError', name); + return false; + } + + return true; + }, + _error: function(code, fileName){ + var message = this._options.messages[code]; + function r(name, replacement){ message = message.replace(name, replacement); } + + r('{file}', this._formatFileName(fileName)); + r('{extensions}', this._options.allowedExtensions.join(', ')); + r('{sizeLimit}', this._formatSize(this._options.sizeLimit)); + r('{minSizeLimit}', this._formatSize(this._options.minSizeLimit)); + + this._options.showMessage(message); + }, + _formatFileName: function(name){ + if (name.length > 33){ + name = name.slice(0, 19) + '...' + name.slice(-13); + } + return name; + }, + _isAllowedExtension: function(fileName){ + var ext = (-1 !== fileName.indexOf('.')) ? fileName.replace(/.*[.]/, '').toLowerCase() : ''; + var allowed = this._options.allowedExtensions; + + if (!allowed.length){return true;} + + for (var i=0; i 99); + + return Math.max(bytes, 0.1).toFixed(1) + ['kB', 'MB', 'GB', 'TB', 'PB', 'EB'][i]; + } +}; + + +/** + * Class that creates upload widget with drag-and-drop and file list + * @inherits qq.FileUploaderBasic + */ +qq.FileUploader = function(o){ + // call parent constructor + qq.FileUploaderBasic.apply(this, arguments); + + // additional options + qq.extend(this._options, { + element: null, + // if set, will be used instead of qq-upload-list in template + listElement: null, + + template: '
' + + '
Drop files here to upload
' + + '
Upload a file
' + + '
    ' + + '
    ', + + // template for one item in file list + fileTemplate: '
  • ' + + '' + + '' + + '' + + 'Cancel' + + 'Failed' + + '
  • ', + + classes: { + // used to get elements from templates + button: 'qq-upload-button', + drop: 'qq-upload-drop-area', + dropActive: 'qq-upload-drop-area-active', + list: 'qq-upload-list', + + file: 'qq-upload-file', + spinner: 'qq-upload-spinner', + size: 'qq-upload-size', + cancel: 'qq-upload-cancel', + + // added to list item when upload completes + // used in css to hide progress spinner + success: 'qq-upload-success', + fail: 'qq-upload-fail' + } + }); + // overwrite options with user supplied + qq.extend(this._options, o); + + this._element = this._options.element; + this._element.innerHTML = this._options.template; + this._listElement = this._options.listElement || this._find(this._element, 'list'); + + this._classes = this._options.classes; + + this._button = this._createUploadButton(this._find(this._element, 'button')); + + this._bindCancelEvent(); + this._setupDragDrop(); +}; + +// inherit from Basic Uploader +qq.extend(qq.FileUploader.prototype, qq.FileUploaderBasic.prototype); + +qq.extend(qq.FileUploader.prototype, { + /** + * Gets one of the elements listed in this._options.classes + **/ + _find: function(parent, type){ + var element = qq.getByClass(parent, this._options.classes[type])[0]; + if (!element){ + throw new Error('element not found ' + type); + } + + return element; + }, + _setupDragDrop: function(){ + var self = this, + dropArea = this._find(this._element, 'drop'); + + var dz = new qq.UploadDropZone({ + element: dropArea, + onEnter: function(e){ + qq.addClass(dropArea, self._classes.dropActive); + e.stopPropagation(); + }, + onLeave: function(e){ + e.stopPropagation(); + }, + onLeaveNotDescendants: function(e){ + qq.removeClass(dropArea, self._classes.dropActive); + }, + onDrop: function(e){ + dropArea.style.display = 'none'; + qq.removeClass(dropArea, self._classes.dropActive); + self._uploadFileList(e.dataTransfer.files); + } + }); + + dropArea.style.display = 'none'; + + qq.attach(document, 'dragenter', function(e){ + if (!dz._isValidFileDrag(e)) return; + + dropArea.style.display = 'block'; + }); + qq.attach(document, 'dragleave', function(e){ + if (!dz._isValidFileDrag(e)) return; + + var relatedTarget = document.elementFromPoint(e.clientX, e.clientY); + // only fire when leaving document out + if ( ! relatedTarget || relatedTarget.nodeName == "HTML"){ + dropArea.style.display = 'none'; + } + }); + }, + _onSubmit: function(id, fileName){ + qq.FileUploaderBasic.prototype._onSubmit.apply(this, arguments); + this._addToList(id, fileName); + }, + _onProgress: function(id, fileName, loaded, total){ + qq.FileUploaderBasic.prototype._onProgress.apply(this, arguments); + + var item = this._getItemByFileId(id); + var size = this._find(item, 'size'); + size.style.display = 'inline'; + + var text; + if (loaded != total){ + text = Math.round(loaded / total * 100) + '% from ' + this._formatSize(total); + } else { + text = this._formatSize(total); + } + + qq.setText(size, text); + }, + _onComplete: function(id, fileName, result){ + qq.FileUploaderBasic.prototype._onComplete.apply(this, arguments); + + // mark completed + var item = this._getItemByFileId(id); + qq.remove(this._find(item, 'cancel')); + qq.remove(this._find(item, 'spinner')); + + if (result.success){ + qq.addClass(item, this._classes.success); + } else { + qq.addClass(item, this._classes.fail); + } + }, + _addToList: function(id, fileName){ + var item = qq.toElement(this._options.fileTemplate); + item.qqFileId = id; + + var fileElement = this._find(item, 'file'); + qq.setText(fileElement, this._formatFileName(fileName)); + this._find(item, 'size').style.display = 'none'; + + this._listElement.appendChild(item); + }, + _getItemByFileId: function(id){ + var item = this._listElement.firstChild; + + // there can't be txt nodes in dynamically created list + // and we can use nextSibling + while (item){ + if (item.qqFileId == id) return item; + item = item.nextSibling; + } + }, + /** + * delegate click event for cancel link + **/ + _bindCancelEvent: function(){ + var self = this, + list = this._listElement; + + qq.attach(list, 'click', function(e){ + e = e || window.event; + var target = e.target || e.srcElement; + + if (qq.hasClass(target, self._classes.cancel)){ + qq.preventDefault(e); + + var item = target.parentNode; + self._handler.cancel(item.qqFileId); + qq.remove(item); + } + }); + } +}); + +qq.UploadDropZone = function(o){ + this._options = { + element: null, + onEnter: function(e){}, + onLeave: function(e){}, + // is not fired when leaving element by hovering descendants + onLeaveNotDescendants: function(e){}, + onDrop: function(e){} + }; + qq.extend(this._options, o); + + this._element = this._options.element; + + this._disableDropOutside(); + this._attachEvents(); +}; + +qq.UploadDropZone.prototype = { + _disableDropOutside: function(e){ + // run only once for all instances + if (!qq.UploadDropZone.dropOutsideDisabled ){ + + qq.attach(document, 'dragover', function(e){ + if (e.dataTransfer){ + e.dataTransfer.dropEffect = 'none'; + e.preventDefault(); + } + }); + + qq.UploadDropZone.dropOutsideDisabled = true; + } + }, + _attachEvents: function(){ + var self = this; + + qq.attach(self._element, 'dragover', function(e){ + if (!self._isValidFileDrag(e)) return; + + var effect = e.dataTransfer.effectAllowed; + if (effect == 'move' || effect == 'linkMove'){ + e.dataTransfer.dropEffect = 'move'; // for FF (only move allowed) + } else { + e.dataTransfer.dropEffect = 'copy'; // for Chrome + } + + e.stopPropagation(); + e.preventDefault(); + }); + + qq.attach(self._element, 'dragenter', function(e){ + if (!self._isValidFileDrag(e)) return; + + self._options.onEnter(e); + }); + + qq.attach(self._element, 'dragleave', function(e){ + if (!self._isValidFileDrag(e)) return; + + self._options.onLeave(e); + + var relatedTarget = document.elementFromPoint(e.clientX, e.clientY); + // do not fire when moving a mouse over a descendant + if (qq.contains(this, relatedTarget)) return; + + self._options.onLeaveNotDescendants(e); + }); + + qq.attach(self._element, 'drop', function(e){ + if (!self._isValidFileDrag(e)) return; + + e.preventDefault(); + self._options.onDrop(e); + }); + }, + _isValidFileDrag: function(e){ + var dt = e.dataTransfer, + // do not check dt.types.contains in webkit, because it crashes safari 4 + isWebkit = navigator.userAgent.indexOf("AppleWebKit") > -1; + + // dt.effectAllowed is none in Safari 5 + // dt.types.contains check is for firefox + return dt && dt.effectAllowed != 'none' && + (dt.files || (!isWebkit && dt.types.contains && dt.types.contains('Files'))); + + } +}; + +qq.UploadButton = function(o){ + this._options = { + element: null, + // if set to true adds multiple attribute to file input + multiple: false, + // name attribute of file input + name: 'file', + onChange: function(input){}, + hoverClass: 'qq-upload-button-hover', + focusClass: 'qq-upload-button-focus' + }; + + qq.extend(this._options, o); + + this._element = this._options.element; + + // make button suitable container for input + qq.css(this._element, { + position: 'relative', + overflow: 'hidden', + // Make sure browse button is in the right side + // in Internet Explorer + direction: 'ltr' + }); + + this._input = this._createInput(); +}; + +qq.UploadButton.prototype = { + /* returns file input element */ + getInput: function(){ + return this._input; + }, + /* cleans/recreates the file input */ + reset: function(){ + if (this._input.parentNode){ + qq.remove(this._input); + } + + qq.removeClass(this._element, this._options.focusClass); + this._input = this._createInput(); + }, + _createInput: function(){ + var input = document.createElement("input"); + + if (this._options.multiple){ + input.setAttribute("multiple", "multiple"); + } + + input.setAttribute("type", "file"); + input.setAttribute("name", this._options.name); + + qq.css(input, { + position: 'absolute', + // in Opera only 'browse' button + // is clickable and it is located at + // the right side of the input + right: 0, + top: 0, + fontFamily: 'Arial', + // 4 persons reported this, the max values that worked for them were 243, 236, 236, 118 + fontSize: '118px', + margin: 0, + padding: 0, + cursor: 'pointer', + opacity: 0 + }); + + this._element.appendChild(input); + + var self = this; + qq.attach(input, 'change', function(){ + self._options.onChange(input); + }); + + qq.attach(input, 'mouseover', function(){ + qq.addClass(self._element, self._options.hoverClass); + }); + qq.attach(input, 'mouseout', function(){ + qq.removeClass(self._element, self._options.hoverClass); + }); + qq.attach(input, 'focus', function(){ + qq.addClass(self._element, self._options.focusClass); + }); + qq.attach(input, 'blur', function(){ + qq.removeClass(self._element, self._options.focusClass); + }); + + // IE and Opera, unfortunately have 2 tab stops on file input + // which is unacceptable in our case, disable keyboard access + if (window.attachEvent){ + // it is IE or Opera + input.setAttribute('tabIndex', "-1"); + } + + return input; + } +}; + +/** + * Class for uploading files, uploading itself is handled by child classes + */ +qq.UploadHandlerAbstract = function(o){ + this._options = { + debug: false, + action: '/upload.php', + // maximum number of concurrent uploads + maxConnections: 999, + onProgress: function(id, fileName, loaded, total){}, + onComplete: function(id, fileName, response){}, + onCancel: function(id, fileName){} + }; + qq.extend(this._options, o); + + this._queue = []; + // params for files in queue + this._params = []; +}; +qq.UploadHandlerAbstract.prototype = { + log: function(str){ + if (this._options.debug && window.console) console.log('[uploader] ' + str); + }, + /** + * Adds file or file input to the queue + * @returns id + **/ + add: function(file){}, + /** + * Sends the file identified by id and additional query params to the server + */ + upload: function(id, params){ + var len = this._queue.push(id); + + var copy = {}; + qq.extend(copy, params); + this._params[id] = copy; + + // if too many active uploads, wait... + if (len <= this._options.maxConnections){ + this._upload(id, this._params[id]); + } + }, + /** + * Cancels file upload by id + */ + cancel: function(id){ + this._cancel(id); + this._dequeue(id); + }, + /** + * Cancells all uploads + */ + cancelAll: function(){ + for (var i=0; i= max && i < max){ + var nextId = this._queue[max-1]; + this._upload(nextId, this._params[nextId]); + } + } +}; + +/** + * Class for uploading files using form and iframe + * @inherits qq.UploadHandlerAbstract + */ +qq.UploadHandlerForm = function(o){ + qq.UploadHandlerAbstract.apply(this, arguments); + + this._inputs = {}; +}; +// @inherits qq.UploadHandlerAbstract +qq.extend(qq.UploadHandlerForm.prototype, qq.UploadHandlerAbstract.prototype); + +qq.extend(qq.UploadHandlerForm.prototype, { + add: function(fileInput){ + fileInput.setAttribute('name', 'qqfile'); + var id = 'qq-upload-handler-iframe' + qq.getUniqueId(); + + this._inputs[id] = fileInput; + + // remove file input from DOM + if (fileInput.parentNode){ + qq.remove(fileInput); + } + + return id; + }, + getName: function(id){ + // get input value and remove path to normalize + return this._inputs[id].value.replace(/.*(\/|\\)/, ""); + }, + _cancel: function(id){ + this._options.onCancel(id, this.getName(id)); + + delete this._inputs[id]; + + var iframe = document.getElementById(id); + if (iframe){ + // to cancel request set src to something else + // we use src="javascript:false;" because it doesn't + // trigger ie6 prompt on https + iframe.setAttribute('src', 'javascript:false;'); + + qq.remove(iframe); + } + }, + _upload: function(id, params){ + var input = this._inputs[id]; + + if (!input){ + throw new Error('file with passed id was not added, or already uploaded or cancelled'); + } + + var fileName = this.getName(id); + + var iframe = this._createIframe(id); + var form = this._createForm(iframe, params); + form.appendChild(input); + + var self = this; + this._attachLoadEvent(iframe, function(){ + self.log('iframe loaded'); + + var response = self._getIframeContentJSON(iframe); + + self._options.onComplete(id, fileName, response); + self._dequeue(id); + + delete self._inputs[id]; + // timeout added to fix busy state in FF3.6 + setTimeout(function(){ + qq.remove(iframe); + }, 1); + }); + + form.submit(); + qq.remove(form); + + return id; + }, + _attachLoadEvent: function(iframe, callback){ + qq.attach(iframe, 'load', function(){ + // when we remove iframe from dom + // the request stops, but in IE load + // event fires + if (!iframe.parentNode){ + return; + } + + // fixing Opera 10.53 + if (iframe.contentDocument && + iframe.contentDocument.body && + iframe.contentDocument.body.innerHTML == "false"){ + // In Opera event is fired second time + // when body.innerHTML changed from false + // to server response approx. after 1 sec + // when we upload file with iframe + return; + } + + callback(); + }); + }, + /** + * Returns json object received by iframe from server. + */ + _getIframeContentJSON: function(iframe){ + // iframe.contentWindow.document - for IE<7 + var doc = iframe.contentDocument ? iframe.contentDocument: iframe.contentWindow.document, + response; + + this.log("converting iframe's innerHTML to JSON"); + this.log("innerHTML = " + doc.body.innerHTML); + + try { + response = eval("(" + doc.body.innerHTML + ")"); + } catch(err){ + response = {}; + } + + return response; + }, + /** + * Creates iframe with unique name + */ + _createIframe: function(id){ + // We can't use following code as the name attribute + // won't be properly registered in IE6, and new window + // on form submit will open + // var iframe = document.createElement('iframe'); + // iframe.setAttribute('name', id); + + var iframe = qq.toElement('