<commit_before>/*jshint trailing:true, white:true, indent:2, strict:true, curly:true, plusplus:true
  immed:true, eqeqeq:true, forin:true, latedef:true, newcap:true, noarg:true, undef:true */
/*jslint bitwise: true, nomen: true, indent:2 */
/*global XT:true, XM:true, Backbone:true, _:true, console:true */

(function () {
  "use strict";

  /**
    @namespace

    A mixin shared by To-Do models that share common incident status
    functionality.
  */
  XM.ToDoStatus = {
    /** @scope XM.ToDoStatus */

    /**
    Returns to-do status as a localized string.

    @returns {String}
    */
    getToDoStatusString: function () {
      var K = XM.ToDo,
        status = this.get('status');
      if (status === K.PENDING) {
        return '_pending'.loc();
      }
      if (status === K.DEFERRED) {
        return '_deferred'.loc();
      }
      if (status === K.NEITHER) {
        return '_neither'.loc();
      }
      if (status === K.IN_PROCESS) {
        return '_inProcess'.loc();
      }
      if (status === K.COMPLETED) {
        return '_completed'.loc();
      }
    }

  };

  /**
    @class

    @extends XT.Model
  */
  XM.ToDo = XT.Model.extend({
    /** @scope XM.ToDo.prototype */

    recordType: 'XM.ToDo',

    privileges: {
      "all": {
        "create": "MaintainAllToDoItems",
        "read": "ViewAllToDoItems",
        "update": "MaintainAllToDoItems",
        "delete": "MaintainAllToDoItems"
      },
      "personal": {
        "create": "MaintainPersonalToDoItems",
        "read": "ViewPersonalToDoItems",
        "update": "MaintainPersonalToDoItems",
        "delete": "MaintainPersonalToDoItems",
        "properties": [
          "owner",
          "assignedTo"
        ]
      }
    },
    
    defaults: function () {
      return {
        isActive: true,
        owner: XM.currentUser,
        assignedTo: XM.currentUser,
        status: XM.ToDo.NEITHER
      };
    },
    
    requiredAttributes: [
      "dueDate",
      "name"
    ],

    relations: [{
      type: Backbone.HasOne,
      key: 'contact',
      relatedModel: 'XM.ContactInfo'
    }, {
      type: Backbone.HasOne,
      key: 'assignedTo',
      relatedModel: 'XM.UserAccountInfo'
    }, {
      type: Backbone.HasMany,
      key: 'accounts',
      relatedModel: 'XM.ToDoAccount',
      reverseRelation: {
        key: 'toDo'
      }
    }, {
      type: Backbone.HasMany,
      key: 'contacts',
      relatedModel: 'XM.ToDoContact',
      reverseRelation: {
        key: 'toDo'
      }
    }, {
      type: Backbone.HasMany,
      key: 'items',
      relatedModel: 'XM.ToDoItem',
      reverseRelation: {
        key: 'toDo'
      }
    }, {
      type: Backbone.HasMany,
      key: 'files',
      relatedModel: 'XM.ToDoFile',
      reverseRelation: {
        key: 'toDo'
      }
    }, {
      type: Backbone.HasMany,
      key: 'images',
      relatedModel: 'XM.ToDoImage',
      reverseRelation: {
        key: 'toDo'
      }
    }, {
      type: Backbone.HasMany,
      key: 'urls',
      relatedModel: 'XM.ToDoUrl',
      reverseRelation: {
        key: 'toDo'
      }
    }],
    
    // ..........................................................
    // METHODS
    //
    
    /**
      This is the source of data for the user three-way status interface where
      the only possible status options are `PENDING`, `DEFERRED` and `NEITHER`.
      
      @returns {String}
    */
    getToDoStatusProxy: function () {
      var K = XM.ToDo;
      return this._status || K.NEITHER;
    },
    
    initialize: function () {
      XT.Model.prototype.initialize.apply(this, arguments);
      this.on('change:startDate change:completeDate', this.toDoStatusDidChange);
      this.on('change:status', this.toDoDidChange);
      this.on('changeStatus', this.toDoDidChange);
    },
    
    toDoDidChange: function (model, value, options) {
      this.setToDoStatusProxy(this.get('status'));
    },
    
    /**
      Handles upkeep of the internal `status` value stored on the to-do record
      which can be one of five options.
    */
    toDoStatusDidChange: function (model, value, options) {
      var status = this.getStatus(),
          toDoStatus = this.getToDoStatusProxy(),
          startDate = this.get('startDate'),
          completeDate = this.get('completeDate'),
          K = XM.ToDo,
          attrStatus = K.NEITHER;
      if (options && options.force || !(status & XT.Model.READY)) { return; }
      
      // Set the `status` attribute with appropriate value
      if (completeDate) {
        attrStatus = K.COMPLETED;
        this.setToDoStatusProxy(K.NEITHER);
      } else if (toDoStatus === K.DEFERRED) {
        attrStatus = K.DEFERRED;
      } else if (toDoStatus === K.PENDING) {
        attrStatus = K.PENDING;
      } else if (startDate) {
        attrStatus = K.IN_PROCESS;
      }
      this.set('status', attrStatus);
    },
    
    /**
      Set the three-way status option.
      <commit_msg>tweaks.<commit_after>/*jshint trailing:true, white:true, indent:2, strict:true, curly:true, plusplus:true
  immed:true, eqeqeq:true, forin:true, latedef:true, newcap:true, noarg:true, undef:true */
/*jslint bitwise: true, nomen: true, indent:2 */
/*global XT:true, XM:true, Backbone:true, _:true, console:true */

(function () {
  "use strict";

  /**
    @namespace

    A mixin shared by To-Do models that share common incident status
    functionality.
  */
  XM.ToDoStatus = {
    /** @scope XM.ToDoStatus */

    /**
    Returns to-do status as a localized string.

    @returns {String}
    */
    getToDoStatusString: function () {
      var K = XM.ToDo,
        status = this.get('status');
      if (status === K.PENDING) {
        return '_pending'.loc();
      }
      if (status === K.DEFERRED) {
        return '_deferred'.loc();
      }
      if (status === K.NEITHER) {
        return '_neither'.loc();
      }
      if (status === K.IN_PROCESS) {
        return '_inProcess'.loc();
      }
      if (status === K.COMPLETED) {
        return '_completed'.loc();
      }
    }

  };

  /**
    @class

    @extends XT.Model
  */
  XM.ToDo = XT.Model.extend({
    /** @scope XM.ToDo.prototype */

    recordType: 'XM.ToDo',

    privileges: {
      "all": {
        "create": "MaintainAllToDoItems",
        "read": "ViewAllToDoItems",
        "update": "MaintainAllToDoItems",
        "delete": "MaintainAllToDoItems"
      },
      "personal": {
        "create": "MaintainPersonalToDoItems",
        "read": "ViewPersonalToDoItems",
        "update": "MaintainPersonalToDoItems",
        "delete": "MaintainPersonalToDoItems",
        "properties": [
          "owner",
          "assignedTo"
        ]
      }
    },
    
    defaults: function () {
      return {
        isActive: true,
        owner: XM.currentUser,
        assignedTo: XM.currentUser,
        status: XM.ToDo.NEITHER
      };
    },
    
    requiredAttributes: [
      "dueDate",
      "name"
    ],

    relations: [{
      type: Backbone.HasOne,
      key: 'contact',
      relatedModel: 'XM.ContactInfo'
    }, {
      type: Backbone.HasOne,
      key: 'assignedTo',
      relatedModel: 'XM.UserAccountInfo'
    }, {
      type: Backbone.HasMany,
      key: 'accounts',
      relatedModel: 'XM.ToDoAccount',
      reverseRelation: {
        key: 'toDo'
      }
    }, {
      type: Backbone.HasMany,
      key: 'contacts',
      relatedModel: 'XM.ToDoContact',
      reverseRelation: {
        key: 'toDo'
      }
    }, {
      type: Backbone.HasMany,
      key: 'items',
      relatedModel: 'XM.ToDoItem',
      reverseRelation: {
        key: 'toDo'
      }
    }, {
      type: Backbone.HasMany,
      key: 'files',
      relatedModel: 'XM.ToDoFile',
      reverseRelation: {
        key: 'toDo'
      }
    }, {
      type: Backbone.HasMany,
      key: 'images',
      relatedModel: 'XM.ToDoImage',
      reverseRelation: {
        key: 'toDo'
      }
    }, {
      type: Backbone.HasMany,
      key: 'urls',
      relatedModel: 'XM.ToDoUrl',
      reverseRelation: {
        key: 'toDo'
      }
    }],
    
    // ..........................................................
    // METHODS
    //
    
    /**
      This is the source of data for the user three-way status interface where
      the only possible status options are `PENDING`, `DEFERRED` and `NEITHER`.
      
      @returns {String}
    */
    getToDoStatusProxy: function () {
      var K = XM.ToDo;
      return this._status || K.NEITHER;
    },
    
    initialize: function () {
      XT.Model.prototype.initialize.apply(this, arguments);
      this.on('change:startDate change:completeDate', this.toDoStatusDidChange);
      this.on('change:status', this.toDoDidChange);
      this.on('changeStatus', this.toDoDidChange);
    },
    
    toDoDidChange: function (model, value, options) {
      this.setToDoStatusProxy(this.get('status'));
    },
    
    /**
      Handles upkeep of the internal `status` value stored on the to-do record
      which can be one of five options.
    */
    toDoStatusDidChange: function (model, value, options) {
      var status = this.getStatus(),
          proxy = this.getToDoStatusProxy(),
          startDate = this.get('startDate'),
          completeDate = this.get('completeDate'),
          K = XM.ToDo,
          attrStatus = K.NEITHER;
      if (options && options.force || !(status & XT.Model.READY)) { return; }
      
      // Set the `status` attribute with appropriate value
      if (completeDate) {
        attrStatus = K.COMPLETED;
        this.setToDoStatusProxy(K.NEITHER);
      } else if (proxy === K.DEFERRED) {
        attrStatus = K.DEFERRED;
      } else if (proxy === K.PENDING) {
        attrStatus = K.PENDING;
      } else if (startDate) {
        attrStatus = K.IN_PROCESS;
      }
      this.set('status', attrStatus);
    },
    
    /**
      Set the three-way status option.
      
{'fraction_non_alphanumeric': 0.1487678734408275, 'fraction_numerical': 0.0004056383733901227, 'mean_word_length': 1.9386174016686533, 'pattern_counts': {'":': 22, '<': 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': '6568863', 'n_tokens_mistral': 3223, 'n_tokens_neox': 3178, 'n_words': 656}