<commit_before>$.namespace('WulinMaster.ActionManager');
$.namespace('WulinMaster.actions');

// action manager
WulinMaster.ActionManager = function(){
  var actions = {};

  return {
    register: function(a_obj) {
      //console.log("Action: " + b_name + " registered!")
      actions[a_obj.name] = a_obj;
    },

    unregister: function(a_obj) {
      delete actions[a_obj.name];
    },

    getAction: function(a_name) {
      return actions[a_name];
    },

    dispatchActions: function(target, actions) {
      // try to find target's behaviors, and subsribe for target
      for(var i in actions) {
        var action = this.getAction(actions[i]);
        if(action){
          $.extend(action, {target: target});
          action.init();
        }
      }
    }
  };
}();


// we assume the wulin_master action is a click event on toolbar item, but you can override to satisfy your requirement
WulinMaster.actions.BaseAction = {
  _isAction: true,
  name: null,
  event: "click", 
  triggerElement: null,
  target: null,

  // in most case, don't need to override
  init : function() {
    // get the trigger element, can be overrided
    this.triggerElement = this.triggerElement || $("." + this.name + "_action");

    // activate the action
    this.activate();
  },

  // get the grid
  getGrid: function(){
    if(this.target) {
      this.grid = this.target;
    } else {
      var grid_name = this.triggerElement.closest(".toolbar").data("grid");
      this.grid = gridManager.getGrid(grid_name);
    }
    return this.grid;
  },

  // can be overrided
  activate: function(){
    var self = this;
    this.triggerElement.on(self.event, function(){
      self.handler();
    })
  },

  // override this to define what the action to do
  handler: $.noop
}

<commit_msg>Fixed a Wulin action identifier bug<commit_after>$.namespace('WulinMaster.ActionManager');
$.namespace('WulinMaster.actions');

// action manager
WulinMaster.ActionManager = function(){
  var actions = {};

  return {
    register: function(a_obj) {
      //console.log("Action: " + b_name + " registered!")
      actions[a_obj.name] = a_obj;
    },

    unregister: function(a_obj) {
      delete actions[a_obj.name];
    },

    getAction: function(a_name) {
      return actions[a_name];
    },

    dispatchActions: function(target, actions) {
      // try to find target's behaviors, and subsribe for target
      for(var i in actions) {
        var action = this.getAction(actions[i]);
        if(action){
          $.extend(action, {target: target});
          action.init();
        }
      }
    }
  };
}();


// we assume the wulin_master action is a click event on toolbar item, but you can override to satisfy your requirement
WulinMaster.actions.BaseAction = {
  _isAction: true,
  name: null,
  event: "click", 
  triggerElementIdentifier: null,
  target: null,

  // in most case, don't need to override
  init : function() {
    // get the trigger element, you can override triggerElementIdentifier
    this.triggerElement = $("#content").find(this.triggerElementIdentifier);
    if(this.triggerElement.length == 0){
      this.triggerElement = $("." + this.name + "_action");
    }

    // activate the action
    this.activate();
  },

  // get the grid
  getGrid: function(){
    if(this.target) {
      this.grid = this.target;
    } else {
      var grid_name = this.triggerElement.closest(".toolbar").data("grid");
      this.grid = gridManager.getGrid(grid_name);
    }
    return this.grid;
  },

  // can be overrided
  activate: function(){
    var self = this;
    console.log("activate")
    console.log(this.triggerElement);
    this.triggerElement.bind(self.event, function(){
      self.handler();
    })
  },

  // override this to define what the action to do
  handler: $.noop
}


{'fraction_non_alphanumeric': 0.13578947368421052, 'fraction_numerical': 0.0002631578947368421, 'mean_word_length': 2.7448275862068967, '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': '3512900', 'n_tokens_mistral': 1168, 'n_tokens_neox': 1132, 'n_words': 293}