// 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, _l) { var replaceListViewItem = function($detailView, newData, options) { var $row = $detailView ? $detailView.data('list-view-row') : options.$row; if (!$row) return; var $listView = $row.closest('.list-view'); if (!$listView.parents('html').size()) return; var $newRow; var jsonObj = $row.data('json-obj'); if ($listView.length > 0) { //$listView.length is 0 after calling $(window).trigger('cloudStack.fullRefresh') $listView.listView('replaceItem', { $row: $row, data: $.extend(jsonObj, newData), after: function($newRow) { if ($detailView) { $detailView.data('list-view-row', $newRow); } setTimeout(function() { $('.data-table').dataTable('selectRow', $newRow.index()); }, 100); } }); } // Refresh detail view context if ($detailView) { var detailViewArgs = $detailView.data('view-args'); var listViewArgs = $listView.data('view-args'); var contextID = listViewArgs.sections && listViewArgs.sections[detailViewArgs.section].id ? listViewArgs.sections[detailViewArgs.section].id : detailViewArgs.section; $.extend($detailView.data('view-args').context[contextID][0], newData); } }; /** * Available UI actions to perform for buttons */ var uiActions = { /** * Default behavior for actions -- just show a confirmation popup and add notification */ standard: function($detailView, args, additional) { var tab = args.tabs[args.activeTab]; var isMultiple = tab.multiple; var action = isMultiple ? tab.actions[args.actionName] : args.actions[args.actionName]; var preAction = action.preAction; var notification = action.notification ? action.notification : {}; var messages = action.messages; var id = args.id; var jsonObj = args.jsonObj; var context = $.extend(true, {}, args.context ? args.context : $detailView.data('view-args').context); var _custom = $detailView.data('_custom'); var customAction = action.action.custom; var noAdd = action.noAdd; var noRefresh = additional.noRefresh; var messageArgs = { name: $detailView.find('tr.name td.value').html(), context: context }; // Handle pre-action (occurs before any other behavior happens) if (preAction) { if (!preAction({ context: context })) return false; } var updateTabContent = function(newData) { var $detailViewElems = $detailView.find('ul.ui-tabs-nav, .detail-group').remove(); var viewArgs = $detailView.data('view-args'); var context = viewArgs.context; var activeContextItem = viewArgs.section && context[viewArgs.section] ? context[viewArgs.section][0] : null; $detailView.tabs('destroy'); $detailView.data('view-args').jsonObj = newData; if (activeContextItem) { $.extend(activeContextItem, newData); } makeTabs( $detailView, $detailView.data('view-args').tabs, { context: context, tabFilter: $detailView.data('view-args').tabFilter, newData: newData } ).appendTo($detailView); $detailView.tabs(); }; var performAction = function(data, options) { if (!options) options = {}; var $form = options.$form; var viewArgs = $detailView.data('view-args'); var $loading = $('