<commit_before>// 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) {
      $.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 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 context = 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();
        $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;
        var viewArgs = $detailView.data('view-args');
        var $loading = $('<div>').addClass('loading-overlay');

        var setLoadingState = function() {
          if (viewArgs && viewArgs.onPerformAction) {
            viewArgs.onPerformAction();
          }

          $detailView.addClass('detail-view-loading-state');
          $detailView.prepend($loading);
        };

        if (customAction && !noAdd) {
          customAction({
            context: context,
            $detailView: $detailView,
            start: setLoadingState,
            complete: function(args) {
              if (!$detailView.hasClass('detail-view-loading-state')) {
                setLoadingState();
              }
              
              args = args ? args : {};

              var $item = args.$item;
              var $row = $detailView.data('list-view-row');

              notification.desc = messages.notification(args.messageArgs);
              notification._custom = $.extend(args._custom ? args._custom : {}, {
                $detailView: $detailView
              });

              cloudStack.ui.notifications.add(
                notification,

                // Success
                function(args) {
                  if (viewArgs && viewArgs.onActionComplete) {
                    viewArgs.onActionComplete();
                  }

                  if (!$detailView.parents('html').size()) {
                    replaceListViewItem(null, args.data, { $row: $row });
                    return;
                  }

                  replaceListViewItem($detailView, args.data);
                  $loading.remove();
                  $detailView.removeClass('detail-view-loading-state');

                  if (!noRefresh) {
                    updateTabContent(args.data);
                  }
                },

                {},

                // Error
                function(args) {
                  $loading.remove();
                }
              );
            }
          });
        } else {
          // Set loading appearance
          var $loading = $('<div>').addClass('loading-overlay');
          $detailView.prepend($loading);

          action.action({
            data: data,
            _custom: _custom,
            ref: options.ref,
            context: context,
            $form: $form,
            response: {
              success: function(args) {
                args = args ? args : {};
                notification._custom = $.extend(args._custom ? args._custom : {}, {
                  $detailView: $detailView
                });

                if (additional && additional.success) additional.success(args);

                // Setup notification
                cloudStack.ui.notifications.add(
                  notification,
                  function(args2) { //name parameter as "args2" instead of "args" to avoid override "args" from success: function(args) {
                    if ($detailView.parents('html').size()) {
                      $loading.remove();

                      if (!noRefresh && !viewArgs.compact) {
                        updateTabContent(args.data? args.data : args2.data);
                      }
                    }

                    if (messages.complete) {
                      cloudStack.dialog.notice({
                        message: messages.complete(args2.data)
                      });
                    }
                    if (additional && additional.complete) additional.complete($.extend(true, args, {
                      $detailView: $detailView
                    }));

                    replaceListViewItem($detailView, args.data ? args.data : args2.data);

                    if (viewArgs && viewArgs.onActionComplete) {
                      viewArgs.onActionComplete();<commit_msg>Detail view, multi-group actions: Prevent refresh of all tabs<commit_after>// 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) {
      $.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 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 context = 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();
        $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;
        var viewArgs = $detailView.data('view-args');
        var $loading = $('<div>').addClass('loading-overlay');

        var setLoadingState = function() {
          if (viewArgs && viewArgs.onPerformAction) {
            viewArgs.onPerformAction();
          }

          $detailView.addClass('detail-view-loading-state');
          $detailView.prepend($loading);
        };

        if (customAction && !noAdd) {
          customAction({
            context: context,
            $detailView: $detailView,
            start: setLoadingState,
            complete: function(args) {
              if (!$detailView.hasClass('detail-view-loading-state')) {
                setLoadingState();
              }
              
              args = args ? args : {};

              var $item = args.$item;
              var $row = $detailView.data('list-view-row');

              notification.desc = messages.notification(args.messageArgs);
              notification._custom = $.extend(args._custom ? args._custom : {}, {
                $detailView: $detailView
              });

              cloudStack.ui.notifications.add(
                notification,

                // Success
                function(args) {
                  if (viewArgs && viewArgs.onActionComplete) {
                    viewArgs.onActionComplete();
                  }

                  if (!$detailView.parents('html').size()) {
                    replaceListViewItem(null, args.data, { $row: $row });
                    return;
                  }

                  replaceListViewItem($detailView, args.data);
                  $loading.remove();
                  $detailView.removeClass('detail-view-loading-state');

                  if (!noRefresh) {
                    updateTabContent(args.data);
                  }
                },

                {},

                // Error
                function(args) {
                  $loading.remove();
                }
              );
            }
          });
        } else {
          // Set loading appearance
          var $loading = $('<div>').addClass('loading-overlay');
          $detailView.prepend($loading);

          action.action({
            data: data,
            _custom: _custom,
            ref: options.ref,
            context: context,
            $form: $form,
            response: {
              success: function(args) {
                args = args ? args : {};
                notification._custom = $.extend(args._custom ? args._custom : {}, {
                  $detailView: $detailView
                });

                if (additional && additional.success) additional.success(args);

                // Setup notification
                cloudStack.ui.notifications.add(
                  notification,
                  function(args2) { //name parameter as "args2" instead of "args" to avoid override "args" from success: function(args) {
                    if ($detailView.parents('html').size()) {
                      $loading.remove();

                      if (!noRefresh && !viewArgs.compact) {
                        if (isMultiple) {
                          $detailView.find('.refresh').click();
                        } else {
                          updateTabContent(args.data? args.data : args2.data);
                        }
                      }
                    }

                    if (messages.complete) {
                      cloudStack.dialog.notice({
                        message: messages.complete(args2.data)
                      });
                    }
                    if (additional && additional.complete) additional.complete($.extend(true, args, {
                      $detailView: $detailView
                    }));

                    replaceListViewItem($detailView, args.data ? args.data : args2.data);

                    if (viewArgs && viewArgs.onActionComplete) {
                      viewArgs.onActionComplete();
{'fraction_non_alphanumeric': 0.12175165281141585, 'fraction_numerical': 0.0019637363356679975, 'mean_word_length': 1.6761254160098091, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5432382', 'n_tokens_mistral': 3941, 'n_tokens_neox': 3754, 'n_words': 907}