コード例 #1
0
ファイル: sync-controller.js プロジェクト: hflabs/perecoder
 loadModelsParams: function (){
     var xhr = this.sync('read', this, { url: routes.absoluteUrl(routes.TASKS_MODELS) });
     xhr.done(function(resp){
         TaskDescriptor.prototype.TASK_TYPES = _.indexBy(resp, 'id');
     });
     return xhr;
 },
コード例 #2
0
ファイル: group-model.js プロジェクト: hflabs/perecoder
define(function(require) {

    var _ = require('underscore'),
        i18n = require('locale/i18n'),
        routes = require('routes'),
        BaseModel = require('model/base-model'),
        Validator = require('common/validator');

    var GroupModel = BaseModel.extend({
        modelParams: {},
        defaults: {
            name: '',
            description: ''
        },
        urlRoot: routes.absoluteUrl(routes.GROUPS_DATA),
        initialize: function(){
            this.constructor.__super__.initialize.apply(this, arguments);
            this.validator = new Validator(this.modelParams.fields);
        },

        toJSON: function(){
            var keys = _.keys(this.modelParams.fields);
            return _.pick(this.attributes, keys);
        },

        validate: function(attrs){
            return this.validator.validate(attrs);
        }
    });

    return GroupModel;
});
コード例 #3
0
ファイル: task-descriptor.js プロジェクト: hflabs/perecoder
define(function(require) {
    var util = require('util'),
        i18n = require('locale/i18n'),
        routes = require('routes'),
        BaseModel = require('model/base-model'),
        Cron = require('common/cron-util'),
        LocalDate = require('common/local-date'),
        Validator = require('common/validator');

    /**
     * Task descriptor object
     * @class
     */
    var TaskDescriptor = BaseModel.extend({
        /**
         * abstract collection, must be overwritten in SyncController.applyConfig
         */
        TASK_TYPES: {},

        defaults: function() {
            return {
                description: '',
                parameters: {}
            }
        },

        urlRoot: routes.absoluteUrl(routes.TASKS_DATA),
        initialize: function() {
            this.constructor.__super__.initialize.apply(this,arguments);
            this.task_type = this.TASK_TYPES[this.get('name')];
            this.validator = new Validator(this.task_type.fields);
            _.defaults(this.get('parameters'), this.task_type.defaultParameters);
        },

        /**
         * Parses raw hash from server to correct Objects
         *
         * Replace timestamps with Date objects, cron's string with Cron object
         *
         * @param {*} attr  recieved hash of attributes
         * @returns         hash with typed values
         */
        parse: function(attr) {
            attr = _.clone(attr);
            attr.cron = new Cron(attr.cron);
            attr.nextScheduledDate = attr.nextScheduledDate && new LocalDate(attr.nextScheduledDate);
            return attr;
        },
        
        validate: function(attrs){
            return this.validator.validate(attrs);
        }
    });

    return TaskDescriptor;
});
コード例 #4
0
define(function(require) {

    var _ = require('underscore'),
        $ = require('jquery'),
        i18n = require('locale/i18n'),
        routes = require('routes'),
        BaseModel = require('model/base-model'),
        Validator = require('common/validator');

    /**
     * Model for uploading dictionaries. Is used to validate fields before sending form
     * @type {*|void|Backbone.Wreqr.Handlers.extend|Backbone.Wreqr.EventAggregator.extend|Marionette.extend|Marionette.Controller.extend}
     */
    var DictionaryModelUpload = BaseModel.extend({
        modelParams: {},
        setModelParams: function(params){
            this.modelParams = $.extend(true, {}, params, {
                fields: {
                    file: {
                        required: true,
                        uploadable: true
                    }
                }
            });
        },
        defaults: function() {
            return _.extend({
                file: '',
                name: '',
                description: '',
                groupId: ''
            }, this.modelParams.defaultParameters);
        },
        urlRoot: routes.absoluteUrl(routes.DICTIONARIES_DATA),
        initialize: function(){
            this.constructor.__super__.initialize.apply(this, arguments);
            this.validator = new Validator(this.modelParams.fields);
        },
        validate: function(attrs){
            return this.validator.validate(attrs);
        }
    });

    return DictionaryModelUpload;
});
コード例 #5
0
ファイル: groups-list.js プロジェクト: hflabs/perecoder
define(function(require) {
    var Backbone = require('backbone'),
        routes = require('routes'),
        GroupModel = require('model/groups/group-model');

    var GroupsList = Backbone.Collection.extend({
        model: GroupModel,
        url: routes.absoluteUrl(routes.GROUPS_DATA),

        fetch: function(options){
            if (this.search) {
                (options || (options = {})).data = {
                    search: this.search
                };
            }
            return Backbone.Collection.prototype.fetch.call(this, options);
        }
    });

    return GroupsList;
})