text: // Generated by CoffeeScript 1.6.3
  (function() {
    var LanguageOptionViewModel, ListSortingOptionViewModel, PrioritiesViewModel;
  
    LanguageOptionViewModel = function(locale) {
      this.id = locale;
      this.label = kb.locale_manager.localeToLabel(locale);
      this.option_group = 'lang';
      return this;
    };
  
    PrioritiesViewModel = function(model) {
      this.priority = model.get('id');
      this.priority_text = kb.observable(kb.locale_manager, this.priority);
      this.priority_color = kb.observable(model, 'color');
      return this;
    };
  
    ListSortingOptionViewModel = function(string_id) {
      this.id = string_id;
      this.label = kb.observable(kb.locale_manager, string_id);
      this.option_group = 'list_sort';
      return this;
    };
  
    window.AppSettingsViewModel = function() {
      var priorities,
        _this = this;
      window.app_settings = this;
      this.collections = {
        priorities: new PriorityCollection()
      };
      _.delay((function() {
        _this.collections.priorities.fetch({
          success: function(collection) {
            if (!collection.get('high')) {
              collection.create({
                id: 'high',
                color: '#bf30ff'
              });
            }
            if (!collection.get('medium')) {
              collection.create({
                id: 'medium',
                color: '#98acff'
              });
            }
            if (!collection.get('low')) {
              return collection.create({
                id: 'low',
                color: '#38ff6a'
              });
            }
          }
        });
        $('.colorpicker').mColorPicker({
          imageFolder: $.fn.mColorPicker.init.imageFolder
        });
        $('.colorpicker').bind('colorpicked', function(event) {
          var $input, model;
          $input = $(event.currentTarget);
          model = _this.collections.priorities.get($input.attr('id'));
          if (model) {
            return model.save({
              color: $input.val()
            });
          }
        });
      }), 1000);
      this.language_options = _.map(kb.locale_manager.getLocales(), function(locale) {
        return new LanguageOptionViewModel(locale);
      });
      this.current_language = ko.observable();
      this.selected_language = ko.computed({
        read: function() {
          return _this.current_language();
        },
        write: function(new_locale) {
          kb.locale_manager.setLocale(new_locale);
          return _this.current_language(new_locale);
        }
      });
      this.selected_language('en');
      priorities = _.map(['high', 'medium', 'low'], function(priority) {
        return new Backbone.ModelRef(_this.collections.priorities, priority);
      });
      this.priorities = _.map(priorities, function(model) {
        return new PrioritiesViewModel(model);
      });
      this.getColorByPriority = function(priority) {
        var view_model, _i, _len, _ref;
        _ref = this.priorities;
        for (_i = 0, _len = _ref.length; _i < _len; _i++) {
          view_model = _ref[_i];
          view_model.priority_color();
        }
        view_model = _.find(this.priorities, function(test) {
          return test.priority === priority;
        });
        if (view_model) {
          return view_model.priority_color();
        } else {
          return '';
        }
      };
      this.default_priority = ko.observable('medium');
      this.default_priority_color = ko.computed(function() {
        return _this.getColorByPriority(_this.default_priority());
      });
      this.list_sorting_options = _.map(['label_title', 'label_created', 'label_priority'], function(label) {
        return new ListSortingOptionViewModel(label);
      });
      this.selected_list_sorting = ko.observable('label_title');
    };
  
  }).call(this);
  