(function($, cloudStack) { /** * Add 'pending' notification */ var addNotification = function(notification, success, successArgs, error, errorArgs) { if (!notification) { success(successArgs); return false; }; var $notifications = $('div.notifications'); if (!notification.poll) { $notifications.notifications('add', { section: notification.section, desc: notification.desc, interval: 0, poll: function(args) { success(successArgs); args.complete(); } }); } else { $notifications.notifications('add', { section: notification.section, desc: notification.desc, interval: 2000, _custom: notification._custom, poll: function(args) { var complete = args.complete; notification.poll({ _custom: args._custom, complete: function(args) { success($.extend(successArgs, args)); complete(args); }, error: function(args) { if (args.message) { if (args.message) { cloudStack.dialog.notice({ message: args.message }); } error($.extend(errorArgs, args)); complete(args); } } }); } }); } return true; }; var replaceListViewItem = function($detailView, newData) { var $row = $detailView.data('list-view-row'); if (!$row) return; var $listView = $row.closest('.list-view'); var $newRow; var jsonObj = $row.data('json-obj'); $listView.listView('replaceItem', { $row: $row, data: $.extend(jsonObj, newData), after: function($newRow) { $detailView.data('list-view-row', $newRow); setTimeout(function() { $('.data-table').dataTable('selectRow', $newRow.index()); }, 100); } }); // Refresh detail view context $.extend( $detailView.data('view-args').context[ $detailView.data('view-args').section ][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 action = args.actions[args.actionName]; var notification = action.notification ? action.notification : {}; var messages = action.messages; var messageArgs = { name: $detailView.find('tr.name td.value').html() }; var id = args.id; var context = $detailView.data('view-args').context; var _custom = $detailView.data('_custom'); var customAction = action.action.custom; var noAdd = action.noAdd; var updateTabContent = function(newData) { var $detailViewElems = $detailView.find('ul.ui-tabs-nav, .detail-group').remove(); $detailView.tabs('destroy'); $detailView.data('view-args').jsonObj = 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; if (customAction && !noAdd) { customAction({ context: context, complete: function(args) { // Set loading appearance var $loading = $('