// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you 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.
(function($, cloudStack) {
cloudStack.uiCustom.accountsWizard = function(args, isLdap) {
return function(listViewArgs) {
var context = listViewArgs.context;
var ldapStatus = isLdap;
var accountsWizard = function(data) {
var $wizard = $('#template').find('div.accounts-wizard').clone();
var $form = $wizard.find('form');
var close = function() {
$wizard.dialog('destroy');
$wizard.remove();
$('div.overlay').fadeOut(function() {
$('div.overlay').remove();
});
};
var completeAction = function() {
var data = cloudStack.serializeForm($form);
var groupname = $.trim(data.ldapGroupName);
if (groupname) {
args.action({
context: context,
data: data,
isLdap: isLdap,
groupname: groupname,
response: {
error: function(message) {
if (message) {
cloudStack.dialog.notice({
message: message
});
}
}
}
});
} else {
var username = data.username;
var bulkAdd = (username instanceof Array);
if (bulkAdd) {
for (var i = 0; i < username.length; i++) {
args.action({
context: context,
data: data,
isLdap: isLdap,
username: username[i],
response: {
error: function(message) {
if (message) {
cloudStack.dialog.notice({
message: message
});
}
}
}
});
}
} else {
args.action({
context: context,
data: data,
isLdap: isLdap,
username: username,
response: {
error: function(message) {
if (message) {
cloudStack.dialog.notice({
message: message
});
}
}
}
});
}
}
};
$wizard.click(function(event) {
var $target = $(event.target);
if ($target.closest('button.next').size()) {
$form.validate();
if ($form.valid()) {
completeAction();
$(window).trigger('cloudStack.fullRefresh');
close();
return true;
}
}
if ($target.closest('button.cancel').size()) {
close();
return false;
}
});
if (ldapStatus) {
var $table = $wizard.find('.ldap-account-choice tbody');
$("#label_ldap_group_name").live("keypress", function(event) {
if ($table.find("#tr-groupname-message").length === 0) {
$("
").appendTo($table).append("
All The users from the given group name will be imported
");
}
$table.find("tr").hide();
$table.find("#tr-groupname-message").show();
});
$("#label_ldap_group_name").live("blur", function(event) {
if (!$(this).val()) {
$table.find("tr").show();
$table.find("#tr-groupname-message").hide();
}
});
$.ajax({
url: createURL("listLdapUsers&listtype=new"),
dataType: "json",
async: false,
success: function(json) {
if (json.ldapuserresponse.count > 0) {
$(json.ldapuserresponse.LdapUser).each(function() {
var result = $("
");
result.append("
");
result.append("
" + this.firstname + " " + this.lastname + "
");
result.append("
" + this.username + "
");
result.append("
" + this.email + "
");
$table.append(result);
});
} else {
var result = $("