// 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) { /** * Instance wizard */ cloudStack.instanceWizard = function(args) { return function(listViewArgs) { var context = listViewArgs.context; var instanceWizard = function(data) { var $wizard = $('#template').find('div.instance-wizard').clone(); var $progress = $wizard.find('div.progress ul li'); var $steps = $wizard.find('div.steps').children().hide(); var $diagramParts = $wizard.find('div.diagram').children().hide(); var $form = $wizard.find('form'); $form.validate(); // Close instance wizard var close = function() { $wizard.dialog('destroy'); $('div.overlay').fadeOut(function() { $('div.overlay').remove(); }); }; // Save instance and close wizard var completeAction = function() { var data = cloudStack.serializeForm($form); var $wizardLoading = $('
').addClass('loading-overlay').appendTo($wizard).css('z-index', '10000'); args.action({ // Populate data data: data, response: { success: function(args) { var $loading = $('.list-view').listView('prependItem', { data: [ { name: data.displayname ? data.displayname : _l('label.new.vm'), zonename: $wizard.find('select[name=zoneid] option').filter(function() { return $(this).val() == data.zoneid; }).html(), state: 'Creating' } ], actionFilter: function(args) { return []; } }); listViewArgs.complete({ _custom: args._custom, messageArgs: cloudStack.serializeForm($form), $item: $loading }); close(); }, error: function(message) { $wizard.remove(); $('div.overlay').remove(); if (message) { cloudStack.dialog.notice({ message: message }); } } } }); }; var makeSelects = function(name, data, fields, options) { var $selects = $('
'); options = options ? options : {}; $(data).each(function() { var id = this[fields.id]; var $select = $('
') .addClass('select') .append( $('') .attr({ type: (function(type) { return type ? type : 'radio'; })(options ? options.type : null), name: name, 'wizard-field': options['wizard-field'] }) .val(id) .click(function() { var $radio = $(this).closest('.select').find('input[type=radio]'); if ($radio.is(':checked') && !$(this).is(':checked')) { if (!$radio.closest('.select').index()) { return false; } else { $radio .closest('.select') .siblings().filter(':first') .find('input[type=radio]').click(); } } return true; }) ) .append( $('
').addClass('select-desc') .append($('
').addClass('name').html(this[fields.name])) .append($('
').addClass('desc').html(this[fields.desc])) ); $selects.append($select); if (options.secondary) { var $secondary = $('
').addClass('secondary-input').append( $('') .attr({ type: options.secondary.type, name: options.secondary.name }) .val(id) .click(function() { var $checkbox = $(this).closest('.select').find('input[type=checkbox]'); if (!$checkbox.is(':checked')) { $checkbox.attr('checked', true); } }) .after( $('
').addClass('name').html(options.secondary.desc) ) ).appendTo($select); } }); cloudStack.evenOdd($selects, 'div.select', { even: function($elem) { $elem.addClass('even'); }, odd: function($elem) { $elem.addClass('odd'); } }); return $selects.children(); }; var dataProvider = function(step, providerArgs, callback) { // Call appropriate data provider args.steps[step - 1]($.extend(providerArgs, { currentData: cloudStack.serializeForm($form) })); }; var dataGenerators = { setup: function($step, formData) { var originalValues = function(formData) { $step.find('select').val( formData.zoneid ); $step.find('input[type=radio]').filter(function() { return $(this).val() == formData['select-template']; }).click(); }; return { response: { success: function(args) { // Zones $(args.data.zones).each(function() { $step.find('.select-zone select').append( $('