<commit_before>'use strict';

angular.module('openolitor').directive('ooSaveButton', ['msgBus', function(msgBus) {
  return {
    restrict: 'E',
    replace: true,
    scope: {
      entity: '@',
      model: '=',
      onSave: '=',
      onCancel: '=',
      form: '='
    },
    transclude: true,
    templateUrl: 'scripts/common/components/oo-savebutton.directive.html',
    controller: function($scope) {
      $scope.isNew = function() {
        return !$scope.model || $scope.model.id === undefined;
      };

      $scope.loading = false;
      msgBus.onMsg('EntityModified', $scope, function(event, msg) {
        if (msg.entity === $scope.entity && msg.data.id === $scope.model.id) {
          $scope.model = msg.data;
          $scope.loading = false;
          $scope.$apply();
        }
      });

      msgBus.onMsg('EntityCreated', $scope, function(event, msg) {
        if (msg.entity === $scope.entity && msg.data.id === $scope.model.id) {
          $scope.model = msg.data;
          $scope.loading = false;
          $scope.$apply();
        }
      });

      $scope.save = function() {
        $scope.loading = true;
        $scope.onSave();
      };

      $scope.cancel = function() {<commit_msg>check if we expected change from server side<commit_after>'use strict';

angular.module('openolitor').directive('ooSaveButton', ['msgBus', function(msgBus) {
  return {
    restrict: 'E',
    replace: true,
    scope: {
      entity: '@',
      model: '=',
      onSave: '=',
      onCancel: '=',
      form: '='
    },
    transclude: true,
    templateUrl: 'scripts/common/components/oo-savebutton.directive.html',
    controller: function($scope) {
      $scope.isNew = function() {
        return !$scope.model || $scope.model.id === undefined;
      };

      $scope.loading = false;
      msgBus.onMsg('EntityModified', $scope, function(event, msg) {
        if (msg.entity === $scope.entity && msg.data.id === $scope.model.id) {
          if (!$scope.loading) {
            //TODO: Use alertservice to notify user to reload page before saving
          }
          else {          
            //$scope.model = msg.data;
            $scope.loading = false;
            $scope.$apply();
          } 
       }
      });

      msgBus.onMsg('EntityCreated', $scope, function(event, msg) {
        if (msg.entity === $scope.entity && msg.data.id === $scope.model.id) {
          $scope.model = msg.data;
          $scope.loading = false;
          $scope.$apply();
        }
      });

      $scope.save = function() {
        $scope.loading = true;
        $scope.onSave();
      };

      $scope.cancel = function() {
{'fraction_non_alphanumeric': 0.17196969696969697, 'fraction_numerical': 0.0, 'mean_word_length': 2.0461361014994233, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '1368216', 'n_tokens_mistral': 814, 'n_tokens_neox': 806, 'n_words': 151}