<commit_before>// Workflow mode switching and approval request button

function AposWorkflow() {
  var self = this;
  $(function() {
    $('body').on('aposReady', function() {
      var mode = apos.data.workflow.mode;
      reflectMode(mode);
    });
    $('body').on('click', '[data-workflow-mode]', function() {
      var mode = $(this).attr('data-workflow-mode');
      $.jsonCall('/apos/workflow-mode', { mode: mode }, function(data) {
        if (data.status !== 'ok') {
          return alert('Server Error, Please Try Again');
        }
        apos.data.workflow.mode = mode;
        reflectMode(mode);
        // Refresh the actual content to show draft or public version
        apos.change('workflowMode');
      });
      return false;
    });
    $('body').on('click', '[data-workflow-approve-changes]', function() {
      var $areas = $('.apos-refreshable .apos-area,.apos-refreshable .apos-singleton');
      var slugs = _.map($areas, function(area) {
        return $(area).attr('data-slug');
      });
      _.each($areas, function(area) {
        var $area = $(area);
        // Locate auto-saving areas and tell them to save now
        // so we have consistency in what we publish
        if ($area.is('[data-save]')) {
          // Save synchronously so we know when we're done
          var editor = $area.data('editor');
          if (editor) {
            editor.saveIfNeeded(true);
          }
        }
      });
      $.jsonCall('/apos/workflow-approve-changes', { slugs: slugs }, function(data) {
        if (data.status !== 'ok') {
          return alert('Server Error, Please Try Again');
        }
        if (data.submitted && (!data.published)) {
          alert('Your changes have been submitted to the moderators for approval.');
        } else if (data.submitted) {
          alert('Some of your changes will require approval. Others were made live.');
          apos.change('workflowApproveCahanges');
        } else if (data.published) {
          alert('Your changes were made live.');
          apos.change('workflowApproveCahanges');
        }
      });
      return false;
    });
    function reflectMode(mode) {
      $('[data-workflow-approve-changes]').toggle(mode === 'draft');
      $('[data-workflow-mode]').removeClass('apos-current');
      $('[data-workflow-mode="' + mode + '"]').addClass('apos-current');
    }
  });
}

// Workflow manager dialog

function AposWorkflowManager() {
  var self = this;
  self.modal = function() {
    self.$el = apos.modalFromTemplate('.apos-workflow-manager', self);
  };

  // Invoked when the modal is ready
  self.init = function(callback) {
    console.log(self.$el[0]);
    self.$list = self.$el.find('[data-pages]');
    console.log(self.$list[0]);
    self.$template = self.$list.find('[data-item].apos-template');
    self.$template.remove();

    return self.load(callback);
  };

  self.addItem = function(item) {
    console.log(self.$template[0]);
    var $newItem = apos.fromTemplate(self.$template);
    console.log($newItem[0]);
    self.$list.append($newItem);
    $newItem.attr('data-slug', item.slug);
    $newItem.attr('data-date', item.submitDraft);
    $newItem.attr('data-author', item.draftSubmittedBy);
    return $newItem;
  };
<commit_msg>manager wasnt reflecting info about drafts, is now<commit_after>// Workflow mode switching and approval request button

function AposWorkflow() {
  var self = this;
  $(function() {
    $('body').on('aposReady', function() {
      var mode = apos.data.workflow.mode;
      reflectMode(mode);
    });
    $('body').on('click', '[data-workflow-mode]', function() {
      var mode = $(this).attr('data-workflow-mode');
      $.jsonCall('/apos/workflow-mode', { mode: mode }, function(data) {
        if (data.status !== 'ok') {
          return alert('Server Error, Please Try Again');
        }
        apos.data.workflow.mode = mode;
        reflectMode(mode);
        // Refresh the actual content to show draft or public version
        apos.change('workflowMode');
      });
      return false;
    });
    $('body').on('click', '[data-workflow-approve-changes]', function() {
      var $areas = $('.apos-refreshable .apos-area,.apos-refreshable .apos-singleton');
      var slugs = _.map($areas, function(area) {
        return $(area).attr('data-slug');
      });
      _.each($areas, function(area) {
        var $area = $(area);
        // Locate auto-saving areas and tell them to save now
        // so we have consistency in what we publish
        if ($area.is('[data-save]')) {
          // Save synchronously so we know when we're done
          var editor = $area.data('editor');
          if (editor) {
            editor.saveIfNeeded(true);
          }
        }
      });
      $.jsonCall('/apos/workflow-approve-changes', { slugs: slugs }, function(data) {
        if (data.status !== 'ok') {
          return alert('Server Error, Please Try Again');
        }
        if (data.submitted && (!data.published)) {
          alert('Your changes have been submitted to the moderators for approval.');
        } else if (data.submitted) {
          alert('Some of your changes will require approval. Others were made live.');
          apos.change('workflowApproveCahanges');
        } else if (data.published) {
          alert('Your changes were made live.');
          apos.change('workflowApproveCahanges');
        }
      });
      return false;
    });
    function reflectMode(mode) {
      $('[data-workflow-approve-changes]').toggle(mode === 'draft');
      $('[data-workflow-mode]').removeClass('apos-current');
      $('[data-workflow-mode="' + mode + '"]').addClass('apos-current');
    }
  });
}

// Workflow manager dialog

function AposWorkflowManager() {
  var self = this;
  self.modal = function() {
    self.$el = apos.modalFromTemplate('.apos-workflow-manager', self);
  };

  // Invoked when the modal is ready
  self.init = function(callback) {
    self.$list = self.$el.find('[data-pages]');
    self.$template = self.$list.find('[data-item].apos-template');
    self.$template.remove();

    return self.load(callback);
  };

  self.addItem = function(item) {
    var $newItem = apos.fromTemplate(self.$template);
    $newItem.find('[data-slug]').text(item.slug);
    $newItem.find('[data-slug]').attr('href', item.slug);
    $newItem.find('[data-date]').text(item.submitDraft);
    $newItem.find('[data-author]').text(item.draftSubmittedBy);
    self.$list.append($newItem);

    return $newItem;
  };

{'fraction_non_alphanumeric': 0.17146818672007394, 'fraction_numerical': 0.0006162378678169774, 'mean_word_length': 2.6349384098544233, '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': '3994767', 'n_tokens_mistral': 1964, 'n_tokens_neox': 1982, 'n_words': 428}