<commit_before>/* global app:true */

(function() {
  'use strict';

  app = app || {};

  app.Settings = Backbone.Model.extend({
    initialize: function() {
      //for (var key in app.mainView.model) {
      //  if (app.mainView.model.hasOwnProperty(key)) {
      //    this.set(key, app.mainView.model[key].value);
      //  }
      //}
    },
    idAttribute: '_id',
    defaults: {
      success: false,
      errors: [],
      errfor: {}
    },
    url: function() {
      return '/admin/settings';
    }
  });

  app.HeaderView = Backbone.View.extend({
    el: '#header',
    template: _.template( $('#tmpl-header').html() ),

    initialize: function() {
      this.model = app.mainView.model;
      //this.listenTo(this.model, 'change', this.render);
      this.render();
    },

    render: function() {
      this.$el.html(this.template( this.model.attributes ));
    }
  });

  app.SettingsView = Backbone.View.extend({
    el: '#settings',
    template: _.template( $('#tmpl-settings').html() ),
    events: {
      'click .btn-update': 'update'
    },
    initialize: function() {
      this.model = new app.Settings();
      this.syncUp();
      this.listenTo(app.mainView.model, 'change', this.syncUp);
      this.listenTo(this.model, 'sync', this.render);
      this.render();
    },
    syncUp: function() {
      for (var key in this.model.attributes) {
        this.model.set(key, app.mainView.model.get(key));
      }
    },
    render: function() {
      this.$el.html(this.template( this.model.attributes ));

      for (var key in this.model.attributes) {
        if (this.model.attributes.hasOwnProperty(key)) {
          this.$el.find('[name="'+ key +'"]').val(this.model.attributes[key]);
        }
      }
    },
    update: function() {
      var toSave = {};
      this.$el.find('.form-role input').each(function(i, el) {
        toSave[el.name] = el.value;
        console.log(el);
      });
      this.$el.find('.form-role select').each(function(i, el) {
        toSave[el.name] = el.value;
      });
      console.log(toSave);
      this.model.save(toSave);
    }
  });

  app.MainView = Backbone.View.extend({
    el: '.page .container',
    initialize: function() {
      app.mainView = this;
      this.model = new app.Settings( JSON.parse( unescape($('#data-record').html())) );

      app.headerView = new app.HeaderView();
      app.settingsView = new app.SettingsView();
    }
  });

  $(document).ready(function() {
    app.mainView = new app.MainView();
  });
}());<commit_msg>settings page<commit_after>/* global app:true */

(function() {
  'use strict';

  app = app || {};

  app.Settings = Backbone.Model.extend({
    initialize: function() {
      //for (var key in app.mainView.model) {
      //  if (app.mainView.model.hasOwnProperty(key)) {
      //    this.set(key, app.mainView.model[key].value);
      //  }
      //}
    },
    idAttribute: '_id',
    defaults: {
      success: false,
      errors: [],
      errfor: {}
    },
    url: function() {
      return '/admin/settings';
    }
  });

  app.HeaderView = Backbone.View.extend({
    el: '#header',
    template: _.template( $('#tmpl-header').html() ),

    initialize: function() {
      this.model = app.mainView.model;
      //this.listenTo(this.model, 'change', this.render);
      this.render();
    },

    render: function() {
      this.$el.html(this.template( this.model.attributes ));
    }
  });

  app.SettingsView = Backbone.View.extend({
    el: '#settings',
    template: _.template( $('#tmpl-settings').html() ),
    events: {
      'click .btn-update': 'update'
    },
    initialize: function() {
      this.model = new app.Settings();
      this.syncUp();
      this.listenTo(app.mainView.model, 'change', this.syncUp);
      this.listenTo(this.model, 'sync', this.render);
      this.render();
    },
    syncUp: function() {
      for (var key in this.model.attributes) {
        this.model.set(key, app.mainView.model.get(key));
      }
    },
    render: function() {
      this.$el.html(this.template( this.model.attributes ));

      for (var key in this.model.attributes) {
        if (this.model.attributes.hasOwnProperty(key)) {
          this.$el.find('[name="'+ key +'"]').val(this.model.attributes[key]);
        }
      }
    },
    update: function() {
      var toSave = {};
      this.$el.find('.form-role input').each(function(i, el) {
        toSave[el.name] = el.value;

      });
      this.$el.find('.form-role select').each(function(i, el) {
        toSave[el.name] = el.value;
      });

      this.model.save(toSave);
    }
  });

  app.MainView = Backbone.View.extend({
    el: '.page .container',
    initialize: function() {
      app.mainView = this;
      this.model = new app.Settings( JSON.parse( unescape($('#data-record').html())) );

      app.headerView = new app.HeaderView();
      app.settingsView = new app.SettingsView();
    }
  });

  $(document).ready(function() {
    app.mainView = new app.MainView();
  });
}());
{'fraction_non_alphanumeric': 0.18997995991983968, 'fraction_numerical': 0.0, 'mean_word_length': 2.322902796271638, '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': '957528', 'n_tokens_mistral': 1639, 'n_tokens_neox': 1620, 'n_words': 277}