You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by se...@apache.org on 2013/07/18 18:35:10 UTC
[35/39] Format JS
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/ad69bc8d/ui/scripts/cloud.core.callbacks.js
----------------------------------------------------------------------
diff --git a/ui/scripts/cloud.core.callbacks.js b/ui/scripts/cloud.core.callbacks.js
index 6eb7644..a32d068 100644
--- a/ui/scripts/cloud.core.callbacks.js
+++ b/ui/scripts/cloud.core.callbacks.js
@@ -14,8 +14,14 @@
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
-$.urlParam = function(name){ var results = new RegExp('[\\?&]' + name + '=([^&#]*)').exec(window.location.href); if (!results) { return 0; } return results[1] || 0;}
-
+$.urlParam = function(name) {
+ var results = new RegExp('[\\?&]' + name + '=([^&#]*)').exec(window.location.href);
+ if (!results) {
+ return 0;
+ }
+ return results[1] || 0;
+}
+
/*
This file is meant to help with implementing single signon integration. If you are using the
cloud.com default UI, there is no need to touch this file.
@@ -23,17 +29,18 @@ cloud.com default UI, there is no need to touch this file.
/*
This callback function is called when either the session has timed out for the user,
-the session ID has been changed (i.e. another user logging into the UI via a different tab),
+the session ID has been changed (i.e. another user logging into the UI via a different tab),
or it's the first time the user has come to this page.
*/
+
function onLogoutCallback() {
- g_loginResponse = null; //clear single signon variable g_loginResponse
-
-
- return true; // return true means the login page will show
- /*
+ g_loginResponse = null; //clear single signon variable g_loginResponse
+
+
+ return true; // return true means the login page will show
+ /*
window.location.replace("http://www.google.com"); //redirect to a different location
- return false; //return false means it will stay in the location window.location.replace() sets it to (i.e. "http://www.google.com")
+ return false; //return false means it will stay in the location window.location.replace() sets it to (i.e. "http://www.google.com")
*/
}
@@ -50,29 +57,27 @@ Below is a sample login attempt
*/
var clientApiUrl = "/client/api";
-var clientConsoleUrl = "/client/console";
+var clientConsoleUrl = "/client/console";
$(document).ready(function() {
-
- var url = $.urlParam("loginUrl");
- if (url != undefined && url != null && url.length > 0) {
- url = unescape(clientApiUrl+"?"+url);
- $.ajax({
- url: url,
- dataType: "json",
- async: false,
- success: function(json) {
- g_loginResponse = json.loginresponse;
- },
- error: function() {
- onLogoutCallback();
- // This means the login failed. You should redirect to your login page.
- },
- beforeSend: function(XMLHttpRequest) {
- return true;
- }
- });
- }
-});
-
+ var url = $.urlParam("loginUrl");
+ if (url != undefined && url != null && url.length > 0) {
+ url = unescape(clientApiUrl + "?" + url);
+ $.ajax({
+ url: url,
+ dataType: "json",
+ async: false,
+ success: function(json) {
+ g_loginResponse = json.loginresponse;
+ },
+ error: function() {
+ onLogoutCallback();
+ // This means the login failed. You should redirect to your login page.
+ },
+ beforeSend: function(XMLHttpRequest) {
+ return true;
+ }
+ });
+ }
+});
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/ad69bc8d/ui/scripts/cloudStack.js
----------------------------------------------------------------------
diff --git a/ui/scripts/cloudStack.js b/ui/scripts/cloudStack.js
index c0ff7f2..df6fea6 100644
--- a/ui/scripts/cloudStack.js
+++ b/ui/scripts/cloudStack.js
@@ -15,480 +15,518 @@
// specific language governing permissions and limitations
// under the License.
(function(cloudStack, $) {
- $.extend(cloudStack, {
- home: 'dashboard',
-
- sectionPreFilter: function(args) {
- var sections = [];
-
- if(isAdmin()) {
- sections = ["dashboard", "instances", "storage", "network", "templates", "accounts", "domains", "events", "system", "global-settings", "configuration", "projects", "regions", "affinityGroups"];
- }
- else if(isDomainAdmin()) {
- sections = ["dashboard", "instances", "storage", "network", "templates", "accounts", "domains", "events", "projects", "regions", "affinityGroups"];
- }
- else if (g_userProjectsEnabled) {
- sections = ["dashboard", "instances", "storage", "network", "templates", "accounts", "events", "projects", "regions", "affinityGroups"];
- }
- else { //normal user
- sections = ["dashboard", "instances", "storage", "network", "templates", "accounts", "events", "regions", "affinityGroups"];
- }
-
- if (cloudStack.plugins.length) {
- sections.push('plugins');
- }
-
- return sections;
- },
- sections: {
- /**
- * Dashboard
- */
- dashboard: {},
- instances: {},
- affinityGroups: {},
- storage: {},
- network: {},
- templates: {},
- events: {},
- projects: {},
- accounts: {},
-
- domains: {}, //domain-admin and root-admin only
-
- regions: {}, //root-admin only
- system: {}, //root-admin only
- 'global-settings': {}, //root-admin only
- configuration: {}, //root-admin only
- plugins: {}
- }
- });
-
- $(window).bind('cloudStack.pluginReady', function() {
- // Get language
- g_lang = $.cookie('lang') ? $.cookie('lang') : 'en';
-
- /**
- * Generic error handling
- */
-
- $.ajaxSetup({
- url: clientApiUrl,
- async: true,
- dataType: 'json',
- cache: false,
- error: function(data) {
- var clickAction = false;
- if (isValidJsonString(data.responseText)) {
- var json = JSON.parse(data.responseText);
- if (json != null) {
- var property;
- for(property in json) {}
- var errorObj = json[property];
- if(errorObj.errorcode == 401 && errorObj.errortext == "unable to verify user credentials and/or request signature") {
- clickAction = function() {
- $('#user-options a').eq(0).trigger('click');
- };
+ $.extend(cloudStack, {
+ home: 'dashboard',
+
+ sectionPreFilter: function(args) {
+ var sections = [];
+
+ if (isAdmin()) {
+ sections = ["dashboard", "instances", "storage", "network", "templates", "accounts", "domains", "events", "system", "global-settings", "configuration", "projects", "regions", "affinityGroups"];
+ } else if (isDomainAdmin()) {
+ sections = ["dashboard", "instances", "storage", "network", "templates", "accounts", "domains", "events", "projects", "regions", "affinityGroups"];
+ } else if (g_userProjectsEnabled) {
+ sections = ["dashboard", "instances", "storage", "network", "templates", "accounts", "events", "projects", "regions", "affinityGroups"];
+ } else { //normal user
+ sections = ["dashboard", "instances", "storage", "network", "templates", "accounts", "events", "regions", "affinityGroups"];
}
- }
- }
- cloudStack.dialog.notice({ message: parseXMLHttpResponse(data), clickAction: clickAction });
- },
- beforeSend: function(XMLHttpRequest) {
- if (g_mySession == $.cookie("JSESSIONID")) {
- return true;
- }
- else {
- var clickAction = function() {
- $('#user-options a').eq(0).trigger('click');
- };
- cloudStack.dialog.notice({ message: _l('label.session.expired'), clickAction: clickAction });
- return false;
+
+ if (cloudStack.plugins.length) {
+ sections.push('plugins');
+ }
+
+ return sections;
+ },
+ sections: {
+ /**
+ * Dashboard
+ */
+ dashboard: {},
+ instances: {},
+ affinityGroups: {},
+ storage: {},
+ network: {},
+ templates: {},
+ events: {},
+ projects: {},
+ accounts: {},
+
+ domains: {}, //domain-admin and root-admin only
+
+ regions: {}, //root-admin only
+ system: {}, //root-admin only
+ 'global-settings': {}, //root-admin only
+ configuration: {}, //root-admin only
+ plugins: {}
}
- }
});
- var $container = $('#cloudStack3-container');
+ $(window).bind('cloudStack.pluginReady', function() {
+ // Get language
+ g_lang = $.cookie('lang') ? $.cookie('lang') : 'en';
+
+ /**
+ * Generic error handling
+ */
+
+ $.ajaxSetup({
+ url: clientApiUrl,
+ async: true,
+ dataType: 'json',
+ cache: false,
+ error: function(data) {
+ var clickAction = false;
+ if (isValidJsonString(data.responseText)) {
+ var json = JSON.parse(data.responseText);
+ if (json != null) {
+ var property;
+ for (property in json) {}
+ var errorObj = json[property];
+ if (errorObj.errorcode == 401 && errorObj.errortext == "unable to verify user credentials and/or request signature") {
+ clickAction = function() {
+ $('#user-options a').eq(0).trigger('click');
+ };
+ }
+ }
+ }
+ cloudStack.dialog.notice({
+ message: parseXMLHttpResponse(data),
+ clickAction: clickAction
+ });
+ },
+ beforeSend: function(XMLHttpRequest) {
+ if (g_mySession == $.cookie("JSESSIONID")) {
+ return true;
+ } else {
+ var clickAction = function() {
+ $('#user-options a').eq(0).trigger('click');
+ };
+ cloudStack.dialog.notice({
+ message: _l('label.session.expired'),
+ clickAction: clickAction
+ });
+ return false;
+ }
+ }
+ });
- var loginArgs = {
- $container: $container,
+ var $container = $('#cloudStack3-container');
- // Use this for checking the session, to bypass login screen
- bypassLoginCheck: function(args) { //determine to show or bypass login screen
- if (g_loginResponse == null) { //show login screen
- /*
+ var loginArgs = {
+ $container: $container,
+
+ // Use this for checking the session, to bypass login screen
+ bypassLoginCheck: function(args) { //determine to show or bypass login screen
+ if (g_loginResponse == null) { //show login screen
+ /*
but if this is a 2nd browser window (of the same domain), login screen still won't show because $.cookie('sessionKey') is valid for 2nd browser window (of the same domain) as well.
i.e. calling listCapabilities API with g_sessionKey from $.cookie('sessionKey') will succeed,
then userValid will be set to true, then an user object (instead of "false") will be returned, then login screen will be bypassed.
*/
- g_mySession = $.cookie('JSESSIONID');
- g_sessionKey = $.cookie('sessionKey');
- g_role = $.cookie('role');
- g_username = $.cookie('username');
- g_userid = $.cookie('userid');
- g_account = $.cookie('account');
- g_domainid = $.cookie('domainid');
- g_userfullname = $.cookie('userfullname');
- g_timezone = $.cookie('timezone');
- if($.cookie('timezoneoffset') != null)
- g_timezoneoffset = isNaN($.cookie('timezoneoffset'))? null: parseFloat($.cookie('timezoneoffset'));
- else
- g_timezoneoffset = null;
- }
- else { //single-sign-on (bypass login screen)
- g_mySession = $.cookie('JSESSIONID');
- g_sessionKey = encodeURIComponent(g_loginResponse.sessionkey);
- g_role = g_loginResponse.type;
- g_username = g_loginResponse.username;
- g_userid = g_loginResponse.userid;
- g_account = g_loginResponse.account;
- g_domainid = g_loginResponse.domainid;
- g_userfullname = g_loginResponse.firstname + ' ' + g_loginResponse.lastname;
- g_timezone = g_loginResponse.timezone;
- if(g_loginResponse.timezoneoffset != null)
- g_timezoneoffset = isNaN(g_loginResponse.timezoneoffset)? null: parseFloat(g_loginResponse.timezoneoffset);
- else
- g_timezoneoffset = null;
- }
-
- var userValid = false;
- $.ajax({
- url: createURL("listCapabilities"),
- dataType: "json",
- async: false,
- success: function(json) {
- g_capabilities = json.listcapabilitiesresponse.capability;
- $.cookie('capabilities', g_capabilities, { expires: 1});
-
- g_supportELB = json.listcapabilitiesresponse.capability.supportELB.toString(); //convert boolean to string if it's boolean
- $.cookie('supportELB', g_supportELB, { expires: 1});
-
- if (json.listcapabilitiesresponse.capability.userpublictemplateenabled != null) {
- g_userPublicTemplateEnabled = json.listcapabilitiesresponse.capability.userpublictemplateenabled.toString(); //convert boolean to string if it's boolean
- $.cookie('userpublictemplateenabled', g_userPublicTemplateEnabled, { expires: 1});
- }
-
- g_userProjectsEnabled = json.listcapabilitiesresponse.capability.allowusercreateprojects;
- $.cookie('userProjectsEnabled', g_userProjectsEnabled, { expires: 1 });
-
- g_cloudstackversion = json.listcapabilitiesresponse.capability.cloudstackversion;
-
- if(json.listcapabilitiesresponse.capability.apilimitinterval != null && json.listcapabilitiesresponse.capability.apilimitmax != null) {
- var intervalLimit = ((json.listcapabilitiesresponse.capability.apilimitinterval * 1000) / json.listcapabilitiesresponse.capability.apilimitmax ) * 3; //multiply 3 to be on safe side
- //intervalLimit = 9999; //this line is for testing only, comment it before check in
- if(intervalLimit > g_queryAsyncJobResultInterval)
- g_queryAsyncJobResultInterval = intervalLimit;
- }
-
- userValid = true;
- },
- error: function(xmlHTTP) { //override default error handling, do nothing instead of showing error "unable to verify user credentials" on login screen
- },
- beforeSend : function(XMLHttpResponse) {
- return true;
- }
- });
-
- if (userValid && isAdmin()) {
- $.ajax({
- url: createURL("listImageStores"),
- data: {
- provider: 'Swift'
- },
- async: false,
- success: function(json) {
- var items = json.listimagestoreresponse.imagestore;
- if(items != null && items.length > 0)
- havingSwift = true;
- }
- });
- if (havingSwift == false) {
- $.ajax({
- url: createURL("listImageStores"),
- data: {
- provider: 'S3'
- },
- async: false,
- success: function(json) {
- var items = json.listimagestoreresponse.imagestore;
- if (items != null && items.length > 0) {
- havingS3 = true;
+ g_mySession = $.cookie('JSESSIONID');
+ g_sessionKey = $.cookie('sessionKey');
+ g_role = $.cookie('role');
+ g_username = $.cookie('username');
+ g_userid = $.cookie('userid');
+ g_account = $.cookie('account');
+ g_domainid = $.cookie('domainid');
+ g_userfullname = $.cookie('userfullname');
+ g_timezone = $.cookie('timezone');
+ if ($.cookie('timezoneoffset') != null)
+ g_timezoneoffset = isNaN($.cookie('timezoneoffset')) ? null : parseFloat($.cookie('timezoneoffset'));
+ else
+ g_timezoneoffset = null;
+ } else { //single-sign-on (bypass login screen)
+ g_mySession = $.cookie('JSESSIONID');
+ g_sessionKey = encodeURIComponent(g_loginResponse.sessionkey);
+ g_role = g_loginResponse.type;
+ g_username = g_loginResponse.username;
+ g_userid = g_loginResponse.userid;
+ g_account = g_loginResponse.account;
+ g_domainid = g_loginResponse.domainid;
+ g_userfullname = g_loginResponse.firstname + ' ' + g_loginResponse.lastname;
+ g_timezone = g_loginResponse.timezone;
+ if (g_loginResponse.timezoneoffset != null)
+ g_timezoneoffset = isNaN(g_loginResponse.timezoneoffset) ? null : parseFloat(g_loginResponse.timezoneoffset);
+ else
+ g_timezoneoffset = null;
}
- }
- });
- }
- } else {
- havingSwift = false;
- havingS3 = false;
- }
- return userValid ? {
- user: {
- userid: g_userid,
- username: g_username,
- account: g_account,
- name: g_userfullname,
- role: g_role,
- domainid: g_domainid
- }
- } : false;
-
- return testAddUser;
- },
-
- // Actual login process, via form
- loginAction: function(args) {
- var array1 = [];
- array1.push("&username=" + encodeURIComponent(args.data.username));
-
- var password;
- if (md5HashedLogin)
- password = $.md5(args.data.password);
- else
- password = todb(args.data.password);
- array1.push("&password=" + password);
-
- var domain;
- if(args.data.domain != null && args.data.domain.length > 0) {
- if (args.data.domain.charAt(0) != "/")
- domain = "/" + args.data.domain;
- else
- domain = args.data.domain;
- array1.push("&domain=" + encodeURIComponent(domain));
- }
- else {
- array1.push("&domain=" + encodeURIComponent("/"));
- }
+ var userValid = false;
+ $.ajax({
+ url: createURL("listCapabilities"),
+ dataType: "json",
+ async: false,
+ success: function(json) {
+ g_capabilities = json.listcapabilitiesresponse.capability;
+ $.cookie('capabilities', g_capabilities, {
+ expires: 1
+ });
+
+ g_supportELB = json.listcapabilitiesresponse.capability.supportELB.toString(); //convert boolean to string if it's boolean
+ $.cookie('supportELB', g_supportELB, {
+ expires: 1
+ });
+
+ if (json.listcapabilitiesresponse.capability.userpublictemplateenabled != null) {
+ g_userPublicTemplateEnabled = json.listcapabilitiesresponse.capability.userpublictemplateenabled.toString(); //convert boolean to string if it's boolean
+ $.cookie('userpublictemplateenabled', g_userPublicTemplateEnabled, {
+ expires: 1
+ });
+ }
+
+ g_userProjectsEnabled = json.listcapabilitiesresponse.capability.allowusercreateprojects;
+ $.cookie('userProjectsEnabled', g_userProjectsEnabled, {
+ expires: 1
+ });
+
+ g_cloudstackversion = json.listcapabilitiesresponse.capability.cloudstackversion;
+
+ if (json.listcapabilitiesresponse.capability.apilimitinterval != null && json.listcapabilitiesresponse.capability.apilimitmax != null) {
+ var intervalLimit = ((json.listcapabilitiesresponse.capability.apilimitinterval * 1000) / json.listcapabilitiesresponse.capability.apilimitmax) * 3; //multiply 3 to be on safe side
+ //intervalLimit = 9999; //this line is for testing only, comment it before check in
+ if (intervalLimit > g_queryAsyncJobResultInterval)
+ g_queryAsyncJobResultInterval = intervalLimit;
+ }
+
+ userValid = true;
+ },
+ error: function(xmlHTTP) { //override default error handling, do nothing instead of showing error "unable to verify user credentials" on login screen
+ },
+ beforeSend: function(XMLHttpResponse) {
+ return true;
+ }
+ });
- var loginCmdText = array1.join("");
-
- $.ajax({
- type: "POST",
- data: "command=login" + loginCmdText + "&response=json",
- dataType: "json",
- async: false,
- success: function(json) {
- var loginresponse = json.loginresponse;
-
- g_mySession = $.cookie('JSESSIONID');
- g_sessionKey = encodeURIComponent(loginresponse.sessionkey);
- g_role = loginresponse.type;
- g_username = loginresponse.username;
- g_userid = loginresponse.userid;
- g_account = loginresponse.account;
- g_domainid = loginresponse.domainid;
- g_timezone = loginresponse.timezone;
- g_timezoneoffset = loginresponse.timezoneoffset;
- g_userfullname = loginresponse.firstname + ' ' + loginresponse.lastname;
-
- $.cookie('sessionKey', g_sessionKey, { expires: 1});
- $.cookie('username', g_username, { expires: 1});
- $.cookie('account', g_account, { expires: 1});
- $.cookie('domainid', g_domainid, { expires: 1});
- $.cookie('role', g_role, { expires: 1});
- $.cookie('timezoneoffset', g_timezoneoffset, { expires: 1});
- $.cookie('timezone', g_timezone, { expires: 1});
- $.cookie('userfullname', g_userfullname, { expires: 1 });
- $.cookie('userid', g_userid, { expires: 1 });
-
- $.ajax({
- url: createURL("listCapabilities"),
- dataType: "json",
- async: false,
- success: function(json) {
- g_capabilities = json.listcapabilitiesresponse.capability;
- $.cookie('capabilities', g_capabilities, { expires: 1});
-
- g_supportELB = json.listcapabilitiesresponse.capability.supportELB.toString(); //convert boolean to string if it's boolean
- $.cookie('supportELB', g_supportELB, { expires: 1});
-
- if (json.listcapabilitiesresponse.capability.userpublictemplateenabled != null) {
- g_userPublicTemplateEnabled = json.listcapabilitiesresponse.capability.userpublictemplateenabled.toString(); //convert boolean to string if it's boolean
- $.cookie('userpublictemplateenabled', g_userPublicTemplateEnabled, { expires: 1});
+ if (userValid && isAdmin()) {
+ $.ajax({
+ url: createURL("listImageStores"),
+ data: {
+ provider: 'Swift'
+ },
+ async: false,
+ success: function(json) {
+ var items = json.listimagestoreresponse.imagestore;
+ if (items != null && items.length > 0)
+ havingSwift = true;
+ }
+ });
+ if (havingSwift == false) {
+ $.ajax({
+ url: createURL("listImageStores"),
+ data: {
+ provider: 'S3'
+ },
+ async: false,
+ success: function(json) {
+ var items = json.listimagestoreresponse.imagestore;
+ if (items != null && items.length > 0) {
+ havingS3 = true;
+ }
+ }
+ });
+ }
+ } else {
+ havingSwift = false;
+ havingS3 = false;
}
- g_userProjectsEnabled = json.listcapabilitiesresponse.capability.allowusercreateprojects;
- $.cookie('userProjectsEnabled', g_userProjectsEnabled, { expires: 1 });
+ return userValid ? {
+ user: {
+ userid: g_userid,
+ username: g_username,
+ account: g_account,
+ name: g_userfullname,
+ role: g_role,
+ domainid: g_domainid
+ }
+ } : false;
- g_cloudstackversion = json.listcapabilitiesresponse.capability.cloudstackversion;
+ return testAddUser;
+ },
- if(json.listcapabilitiesresponse.capability.apilimitinterval != null && json.listcapabilitiesresponse.capability.apilimitmax != null) {
- var intervalLimit = ((json.listcapabilitiesresponse.capability.apilimitinterval * 1000) / json.listcapabilitiesresponse.capability.apilimitmax ) * 3; //multiply 3 to be on safe side
- //intervalLimit = 8888; //this line is for testing only, comment it before check in
- if(intervalLimit > g_queryAsyncJobResultInterval)
- g_queryAsyncJobResultInterval = intervalLimit;
+ // Actual login process, via form
+ loginAction: function(args) {
+ var array1 = [];
+ array1.push("&username=" + encodeURIComponent(args.data.username));
+
+ var password;
+ if (md5HashedLogin)
+ password = $.md5(args.data.password);
+ else
+ password = todb(args.data.password);
+ array1.push("&password=" + password);
+
+ var domain;
+ if (args.data.domain != null && args.data.domain.length > 0) {
+ if (args.data.domain.charAt(0) != "/")
+ domain = "/" + args.data.domain;
+ else
+ domain = args.data.domain;
+ array1.push("&domain=" + encodeURIComponent(domain));
+ } else {
+ array1.push("&domain=" + encodeURIComponent("/"));
}
- args.response.success({
- data: {
- user: $.extend(true, {}, loginresponse, {
- name: loginresponse.firstname + ' ' + loginresponse.lastname,
- role: loginresponse.type == 1 ? 'admin' : 'user',
- type: loginresponse.type
- })
- }
- });
- },
- error: function(xmlHTTP) {
- args.response.error();
- }
- });
+ var loginCmdText = array1.join("");
- if (isAdmin()) {
- $.ajax({
- url: createURL("listImageStores"),
- data:{
- provider: 'Swift'
- },
- async: false,
- success: function(json) {
- var items = json.listimagestoreresponse.imagestore;
- if(items != null && items.length > 0)
- havingSwift = true;
- }
- });
- if (havingSwift = false) {
$.ajax({
- url: createURL("listImageStores"),
- data: {
- provider: 'S3'
- },
- async: false,
- success: function(json) {
- var items = json.listimagestoreresponse.imagestore;
- if (items != null && items.length > 0) {
- havingS3 = true;
+ type: "POST",
+ data: "command=login" + loginCmdText + "&response=json",
+ dataType: "json",
+ async: false,
+ success: function(json) {
+ var loginresponse = json.loginresponse;
+
+ g_mySession = $.cookie('JSESSIONID');
+ g_sessionKey = encodeURIComponent(loginresponse.sessionkey);
+ g_role = loginresponse.type;
+ g_username = loginresponse.username;
+ g_userid = loginresponse.userid;
+ g_account = loginresponse.account;
+ g_domainid = loginresponse.domainid;
+ g_timezone = loginresponse.timezone;
+ g_timezoneoffset = loginresponse.timezoneoffset;
+ g_userfullname = loginresponse.firstname + ' ' + loginresponse.lastname;
+
+ $.cookie('sessionKey', g_sessionKey, {
+ expires: 1
+ });
+ $.cookie('username', g_username, {
+ expires: 1
+ });
+ $.cookie('account', g_account, {
+ expires: 1
+ });
+ $.cookie('domainid', g_domainid, {
+ expires: 1
+ });
+ $.cookie('role', g_role, {
+ expires: 1
+ });
+ $.cookie('timezoneoffset', g_timezoneoffset, {
+ expires: 1
+ });
+ $.cookie('timezone', g_timezone, {
+ expires: 1
+ });
+ $.cookie('userfullname', g_userfullname, {
+ expires: 1
+ });
+ $.cookie('userid', g_userid, {
+ expires: 1
+ });
+
+ $.ajax({
+ url: createURL("listCapabilities"),
+ dataType: "json",
+ async: false,
+ success: function(json) {
+ g_capabilities = json.listcapabilitiesresponse.capability;
+ $.cookie('capabilities', g_capabilities, {
+ expires: 1
+ });
+
+ g_supportELB = json.listcapabilitiesresponse.capability.supportELB.toString(); //convert boolean to string if it's boolean
+ $.cookie('supportELB', g_supportELB, {
+ expires: 1
+ });
+
+ if (json.listcapabilitiesresponse.capability.userpublictemplateenabled != null) {
+ g_userPublicTemplateEnabled = json.listcapabilitiesresponse.capability.userpublictemplateenabled.toString(); //convert boolean to string if it's boolean
+ $.cookie('userpublictemplateenabled', g_userPublicTemplateEnabled, {
+ expires: 1
+ });
+ }
+
+ g_userProjectsEnabled = json.listcapabilitiesresponse.capability.allowusercreateprojects;
+ $.cookie('userProjectsEnabled', g_userProjectsEnabled, {
+ expires: 1
+ });
+
+ g_cloudstackversion = json.listcapabilitiesresponse.capability.cloudstackversion;
+
+ if (json.listcapabilitiesresponse.capability.apilimitinterval != null && json.listcapabilitiesresponse.capability.apilimitmax != null) {
+ var intervalLimit = ((json.listcapabilitiesresponse.capability.apilimitinterval * 1000) / json.listcapabilitiesresponse.capability.apilimitmax) * 3; //multiply 3 to be on safe side
+ //intervalLimit = 8888; //this line is for testing only, comment it before check in
+ if (intervalLimit > g_queryAsyncJobResultInterval)
+ g_queryAsyncJobResultInterval = intervalLimit;
+ }
+
+ args.response.success({
+ data: {
+ user: $.extend(true, {}, loginresponse, {
+ name: loginresponse.firstname + ' ' + loginresponse.lastname,
+ role: loginresponse.type == 1 ? 'admin' : 'user',
+ type: loginresponse.type
+ })
+ }
+ });
+ },
+ error: function(xmlHTTP) {
+ args.response.error();
+ }
+ });
+
+ if (isAdmin()) {
+ $.ajax({
+ url: createURL("listImageStores"),
+ data: {
+ provider: 'Swift'
+ },
+ async: false,
+ success: function(json) {
+ var items = json.listimagestoreresponse.imagestore;
+ if (items != null && items.length > 0)
+ havingSwift = true;
+ }
+ });
+ if (havingSwift = false) {
+ $.ajax({
+ url: createURL("listImageStores"),
+ data: {
+ provider: 'S3'
+ },
+ async: false,
+ success: function(json) {
+ var items = json.listimagestoreresponse.imagestore;
+ if (items != null && items.length > 0) {
+ havingS3 = true;
+ }
+ }
+ });
+ }
+ } else {
+ havingSwift = false;
+ havingS3 = false;
+ }
+
+ // Get project configuration
+ // TEMPORARY -- replace w/ output of capability response, etc., once implemented
+ window.g_projectsInviteRequired = false;
+ },
+ error: function(XMLHttpRequest) {
+ var errorMsg = parseXMLHttpResponse(XMLHttpRequest);
+ if (errorMsg.length == 0 && XMLHttpRequest.status == 0)
+ errorMsg = dictionary['error.unable.to.reach.management.server'];
+ else
+ errorMsg = _l('error.invalid.username.password'); //override error message
+ args.response.error(errorMsg);
+ },
+ beforeSend: function(XMLHttpResponse) {
+ return true;
}
- }
});
- }
- } else {
- havingSwift = false;
- havingS3 = false;
- }
+ },
- // Get project configuration
- // TEMPORARY -- replace w/ output of capability response, etc., once implemented
- window.g_projectsInviteRequired = false;
- },
- error: function(XMLHttpRequest) {
- var errorMsg = parseXMLHttpResponse(XMLHttpRequest);
- if(errorMsg.length == 0 && XMLHttpRequest.status == 0)
- errorMsg = dictionary['error.unable.to.reach.management.server'];
- else
- errorMsg = _l('error.invalid.username.password'); //override error message
- args.response.error(errorMsg);
- },
- beforeSend : function(XMLHttpResponse) {
- return true;
- }
- });
- },
-
- logoutAction: function(args) {
- $.ajax({
- url: createURL('logout'),
- async: false,
- success: function() {
- g_mySession = null;
- g_sessionKey = null;
- g_username = null;
- g_account = null;
- g_domainid = null;
- g_timezoneoffset = null;
- g_timezone = null;
- g_supportELB = null;
- g_loginCmdText = null;
-
- $.cookie('JSESSIONID', null);
- $.cookie('sessionKey', null);
- $.cookie('username', null);
- $.cookie('account', null);
- $.cookie('domainid', null);
- $.cookie('role', null);
- $.cookie('networktype', null);
- $.cookie('timezoneoffset', null);
- $.cookie('timezone', null);
- $.cookie('supportELB', null);
-
- if(onLogoutCallback()) { //onLogoutCallback() will set g_loginResponse(single-sign-on variable) to null, then bypassLoginCheck() will show login screen.
- document.location.reload(); //when onLogoutCallback() returns true, reload the current document.
- }
- },
- error: function() {
- if(onLogoutCallback()) { //onLogoutCallback() will set g_loginResponse(single-sign-on variable) to null, then bypassLoginCheck() will show login screen.
- document.location.reload(); //when onLogoutCallback() returns true, reload the current document.
- }
- },
- beforeSend : function(XMLHttpResponse) {
- return true;
- }
- });
- },
+ logoutAction: function(args) {
+ $.ajax({
+ url: createURL('logout'),
+ async: false,
+ success: function() {
+ g_mySession = null;
+ g_sessionKey = null;
+ g_username = null;
+ g_account = null;
+ g_domainid = null;
+ g_timezoneoffset = null;
+ g_timezone = null;
+ g_supportELB = null;
+ g_loginCmdText = null;
+
+ $.cookie('JSESSIONID', null);
+ $.cookie('sessionKey', null);
+ $.cookie('username', null);
+ $.cookie('account', null);
+ $.cookie('domainid', null);
+ $.cookie('role', null);
+ $.cookie('networktype', null);
+ $.cookie('timezoneoffset', null);
+ $.cookie('timezone', null);
+ $.cookie('supportELB', null);
+
+ if (onLogoutCallback()) { //onLogoutCallback() will set g_loginResponse(single-sign-on variable) to null, then bypassLoginCheck() will show login screen.
+ document.location.reload(); //when onLogoutCallback() returns true, reload the current document.
+ }
+ },
+ error: function() {
+ if (onLogoutCallback()) { //onLogoutCallback() will set g_loginResponse(single-sign-on variable) to null, then bypassLoginCheck() will show login screen.
+ document.location.reload(); //when onLogoutCallback() returns true, reload the current document.
+ }
+ },
+ beforeSend: function(XMLHttpResponse) {
+ return true;
+ }
+ });
+ },
- // Show cloudStack main UI widget
- complete: function(args) {
- var context = {
- users: [args.user]
- };
- var cloudStackArgs = $.extend(cloudStack, {
- context: context
- });
+ // Show cloudStack main UI widget
+ complete: function(args) {
+ var context = {
+ users: [args.user]
+ };
+ var cloudStackArgs = $.extend(cloudStack, {
+ context: context
+ });
- // Check to invoke install wizard
- cloudStack.installWizard.check({
- context: context,
- response: {
- success: function(args) {
- if (args.doInstall && isAdmin()) {
- var initInstallWizard = function() {
- cloudStack.uiCustom.installWizard({
- $container: $container,
+ // Check to invoke install wizard
+ cloudStack.installWizard.check({
context: context,
- complete: function() {
- // Show cloudStack main UI
- $container.cloudStack($.extend(cloudStackArgs, { hasLogo: false }));
+ response: {
+ success: function(args) {
+ if (args.doInstall && isAdmin()) {
+ var initInstallWizard = function() {
+ cloudStack.uiCustom.installWizard({
+ $container: $container,
+ context: context,
+ complete: function() {
+ // Show cloudStack main UI
+ $container.cloudStack($.extend(cloudStackArgs, {
+ hasLogo: false
+ }));
+ }
+ });
+ };
+
+ initInstallWizard();
+ } else {
+ // Show cloudStack main UI
+ $container.cloudStack($.extend(cloudStackArgs, {
+ hasLogo: false
+ }));
+ }
+ }
}
- });
- };
-
- initInstallWizard();
- } else {
- // Show cloudStack main UI
- $container.cloudStack($.extend(cloudStackArgs, { hasLogo: false }));
- }
- }
- }
- });
+ });
- // Logout action
- $('#user-options a').live('click', function() {
- loginArgs.logoutAction({
- context: cloudStack.context
- });
- });
+ // Logout action
+ $('#user-options a').live('click', function() {
+ loginArgs.logoutAction({
+ context: cloudStack.context
+ });
+ });
- window._reloadUI = function() {
- $('#container').html('');
- $('#container').cloudStack(window.cloudStack);
+ window._reloadUI = function() {
+ $('#container').html('');
+ $('#container').cloudStack(window.cloudStack);
+ };
+ }
};
- }
- };
- if ($.urlParam('loginUrl') != 0) {
- // SSO
- loginArgs.hideLoginScreen = true;
- }
+ if ($.urlParam('loginUrl') != 0) {
+ // SSO
+ loginArgs.hideLoginScreen = true;
+ }
- cloudStack.uiCustom.login(loginArgs);
+ cloudStack.uiCustom.login(loginArgs);
- // Localization
- if (!$.isFunction(cloudStack.localizationFn)) { // i.e., localize is overridden by a plugin/module
- cloudStack.localizationFn = function(str) {
- return dictionary[str];
- };
- }
+ // Localization
+ if (!$.isFunction(cloudStack.localizationFn)) { // i.e., localize is overridden by a plugin/module
+ cloudStack.localizationFn = function(str) {
+ return dictionary[str];
+ };
+ }
- document.title = _l('label.app.name');
- });
+ document.title = _l('label.app.name');
+ });
})(cloudStack, jQuery);