コード例 #1
0
module.exports = FormView.extend({
    fields: function () {
        return [
            new InputView({
                name: 'givenName',
                label: 'Given Name',
                placeholder: 'Jane',
                parent: this,
                required: true,
                value: this.model && this.model.givenName,
                tests: [
                    function (val) {
                        if (val.length < 4) return 'Must be > 3 characters';
                    }
                ]
            }),
            new InputView({
                name: 'familyName',
                label: 'Family Name',
                placeholder: 'Doe',
                parent: this,
                required: true,
                value: this.model && this.model.familyName,
                tests: [
                    function (val) {
                        if (val.length < 4) return 'Must be > 3 characters';
                    }
                ]
            })
        ];
    }
});
コード例 #2
0
module.exports = FormView.extend({
    fields: function () {
        return [
            new InputView({
                name: 'givenName',
                label: 'Given Name',
                placeholder: 'Mario',
                parent: this,
                require: true,

                // caso em mode de criação, o model ainda não existe
                value: this.model && this.model.givenName,

                tests: [
                    function (val) {
                        if (val.length < 3) {
                            return 'Given Name must have at least 3 characters';
                        }
                    }
                ]
            }),
            new InputView({
                name: 'familyName',
                label: 'Family Name',
                placeholder: 'Bros',
                parent: this,
                require: true,

                // caso em mode de criação, o model ainda não existe
                value: this.model && this.model.familyName,

                tests: [
                    function (val) {
                        if (val.length < 3) {
                            return 'Family Name must have at least 3 characters';
                        }
                    }
                ]
            }),
        ];
    }
});
コード例 #3
0
ファイル: envProps.js プロジェクト: SpencerSharkey/guvnor
var FormView = require('ampersand-form-view')

module.exports = FormView.extend({
  fields: function () {
    return []
  }
})
コード例 #4
0
ファイル: specie-collection.js プロジェクト: StochSS/stochss
var AddNewSpecieForm = AmpersandFormView.extend({
    submitCallback: function (obj) {
        var validSubdomains = this.baseModel.mesh.uniqueSubdomains.map( function(model) { return model.name; } );

        var i = this.collection.models.length;
        var name = 'S' + i;
        var names = this.collection.map( function(specie) { return specie.name; } );
        while(_.contains(names, name))
        {
            i += 1;
            name = 'S' + i;
        }

        var model = this.collection.addSpecie(name, 0, 0, validSubdomains);

        this.selectView.select(model, true);
    },
            // this valid callback gets called (if it exists)
            // when the form first loads and any time the form
            // changes from valid to invalid or vice versa.
            // You might use this to disable the "submit" button
            // any time the form is invalid, for exmaple.
    validCallback: function (valid) {
        if (valid) {
            this.button.prop('disabled', false);
        } else {
            this.button.prop('disabled', true);
        }
    },
    initialize: function(attr, options) {
        this.collection = options.collection;

        this.baseModel = this.collection.parent;

        this.selectView = attr.selectView;
    },
    render: function()
    {
        AmpersandFormView.prototype.render.apply(this, arguments);

        $( this.el ).find('input').prop('autocomplete', 'off');

        this.button = $('<button class="btn btn-large btn-primary" type="submit">Add Species</button>').appendTo( $( this.el ) );
    }
});
コード例 #5
0
module.exports = FormView.extend({
  fields: function () {
    return [
      new ExtendedInput({
        label: 'Name',
        name: 'name',
        value: this.model && this.model.name || '',
        required: false,
        placeholder: 'Name',
        parent: this
      }),
      new ExtendedInput({
        label: 'Image',
        name: 'img',
        value: this.model && this.model.img || '',
        required: false,
        placeholder: 'Image',
        parent: this
      }),
      new ExtendedInput({
        label: 'Area',
        name: 'area',
        value: this.model && this.model.area || '',
        required: false,
        placeholder: 'Area',
        parent: this
      }),
      new ExtendedInput({
        label: 'Site',
        name: 'site',
        value: this.model && this.model.site || '',
        required: false,
        placeholder: 'Site',
        parent: this
      }),
      new TextareaInput({
        label: 'Contacts',
        name: 'contacts',
        value: this.model && this.model.contacts || '',
        required: false,
        placeholder: 'Contacts',
        parent: this
      }),
      new TextareaInput({
        label: 'Description',
        name: 'description',
        value: this.model && this.model.description || '',
        required: false,
        placeholder: 'Description',
        parent: this
      }),
      new TextareaInput({
        label: 'History',
        name: 'history',
        value: this.model && this.model.history || '',
        required: false,
        placeholder: 'History',
        parent: this
      })
    ]
  }
})
コード例 #6
0
ファイル: my-model.js プロジェクト: RUN-CMD/ampersand-foo
var FormView = require('ampersand-form-view');
var InputView = require('ampersand-input-view');


module.exports = FormView.extend({
    fields: function () {
        return [new InputView({
                label: 'Id',
                name: 'id',
                value: this.model && this.model.id,
                required: false,
                placeholder: 'Id',
                parent: this
            })];
    }
});
コード例 #7
0
ファイル: app.js プロジェクト: SpencerSharkey/guvnor
module.exports = FormView.extend({
  fields: function () {
    return [
      new InputView({
        label: 'Name',
        name: 'name',
        value: this.model.name || '',
        required: false,
        placeholder: 'Name',
        parent: this
      }),
      new InputView({
        label: 'User',
        name: 'user',
        value: this.model.user || '',
        required: false,
        placeholder: 'User',
        parent: this
      }),
      new InputView({
        label: 'Url',
        name: 'url',
        value: this.model.url || '',
        required: false,
        placeholder: 'Url',
        parent: this
      }),
      new InputView({
        label: 'Cwd',
        name: 'cwd',
        value: this.model.cwd || '',
        required: false,
        placeholder: 'Cwd',
        parent: this
      }),
      new InputView({
        label: 'Exec Argv',
        name: 'execArgv',
        value: this.model.execArgv || '',
        required: false,
        placeholder: 'Exec Argv',
        parent: this
      }),
      new InputView({
        label: 'Group',
        name: 'group',
        value: this.model.group || '',
        required: false,
        placeholder: 'Group',
        parent: this
      }),
      new CheckboxView({
        label: 'Debug',
        name: 'debug',
        value: this.model.debug,
        parent: this
      }),
      new InputView({
        label: 'Instances',
        name: 'instances',
        value: this.model.instances || '',
        required: false,
        placeholder: 'Instances',
        parent: this
      })
    ]
  }
})
コード例 #8
0
ファイル: login-form.js プロジェクト: brakmic/Amoklauf
let LoginForm = Form.extend({
    fields: function() {
        return [
            new InputView({
                template    : `<div class="control-group"><label class="control-label" for="username">
                                User Name</label><div class="controls"><input id="username" data-hook="username"></div></div>`,
                name        : 'username',
                type        : 'text',
                placeholder : 'User Name',
                parent      : this,
                value       : this.model.username || '',
                validityClassSelector: '.err',
                tests       : [
                    function(val) {
                        if (val.length < 1) {
                            return 'User name can not be empty';
                        }
                    }
                ]
            }),
            new InputView({
                template    : `<div class="control-group"><label class="control-label"
                                for="password">Password</label><div class="controls">
                                <input id="password" data-hook="password"></div></div>`,
                name        : 'password',
                placeholder : 'Password',
                type        : 'password',
                value       : this.model.password || '',
                parent      : this,
                required    : true
            })
        ];
    }
});
コード例 #9
0
ファイル: envProp.js プロジェクト: SpencerSharkey/guvnor
var FormView = require('ampersand-form-view')
var InputView = require('ampersand-input-view')

module.exports = FormView.extend({
  fields: function () {
    return [
      new InputView({
        label: 'Name',
        name: 'name',
        value: this.model.name || '',
        required: false,
        placeholder: 'Name',
        parent: this
      }),
      new InputView({
        label: 'Value',
        name: 'value',
        value: this.model.value || '',
        required: false,
        placeholder: 'Value',
        parent: this
      })
    ]
  }
})
コード例 #10
0
module.exports = FormView.extend({
  initialize: function () {
    var self = this

    if (this.model && this.model.threadKind === 'company') {
      _addPollFields(self)
    }
  },
  fields: function () {
    return [
      new SelectView({
        template: templates.includes.formSelect(),
        unselectedText: 'please choose one',
        name: 'event',
        label: 'Event',
        parent: this,
        options: app.events,
        value: this.model && this.model.event || '',
        idAttribute: 'id',
        textAttribute: 'name',
        yieldModel: false
      }),
      new SelectView({
        template: templates.includes.formSelect(),
        unselectedText: 'please choose one',
        name: 'member',
        label: 'Member',
        parent: this,
        options: this.model.membersList,
        value: this.model && this.model.member || '',
        idAttribute: 'id',
        textAttribute: 'name',
        yieldModel: false
      }),
      new SelectView({
        template: templates.includes.formSelect(),
        unselectedText: 'please choose one',
        name: 'status',
        label: 'Status',
        parent: this,
        options: options.statuses[this.model && this.model.threadKind || 'company'].map(function (s) { return [s.id, s.name] }),
        value: this.model && this.model.status || '',
        yieldModel: false
      })
    ]
  }
})
コード例 #11
0
ファイル: todo.js プロジェクト: isaacchansky/daily_todo
var FormView = require('ampersand-form-view');
var InputView = require('ampersand-input-view');
var templates = require('../templates');
var ExtendedInput = InputView.extend({
    template: templates.includes.formInput()
});

module.exports = FormView.extend({
    fields: function () {
        return [
            new ExtendedInput({
                label: 'Task',
                name: 'task',
                value: this.model && this.model.task,
                placeholder: 'I need to ...',
                parent: this
            })
        ];
    }
});
コード例 #12
0
module.exports = FormView.extend({
    fields: function () {
        return [
            new ExtendedInput({
                label: 'First Name',
                name: 'firstName',
                value: this.model && this.model.firstName,
                placeholder: 'First Name',
                parent: this
            }),
            new ExtendedInput({
                label: 'Last Name',
                name: 'lastName',
                value: this.model && this.model.lastName,
                placeholder: 'Last Name',
                parent: this
            }),
            new ExtendedInput({
                label: 'Coolness Factor',
                name: 'coolnessFactor',
                value: this.model && this.model.coolnessFactor,
                type: 'number',
                placeholder: '8',
                parent: this,
                tests: [
                    function (val) {
                        if (val < 0 || val > 11) return "Must be between 0 and 11";
                    },
                    function (val) {
                        if (!/^[0-9]+$/.test(val)) return "Must be a number.";
                    }
                ]
            })
        ];
    }
});
コード例 #13
0
ファイル: model-collection.js プロジェクト: StochSS/stochss
var AddNewModelForm = AmpersandFormView.extend({
    submitCallback: function (units, obj) {
        var isSpatial = false;

        if(units == 'spatial')
        {
            units = 'population'
            isSpatial = true;
        }

        var i = this.collection.models.length;
        var name = 'model' + i;
        var names = this.collection.map( function(specie) { return specie.name; } );
        while(_.contains(names, name))
        {
            i += 1;
            name = 'model' + i;
        }

        var model = new Model({ name : name,
                                units : units,
                                type : 'massaction',
                                isSpatial : isSpatial,
                                mesh : this.meshCollection.at(0) });

        this.collection.add(model).save();

        this.selectView.select(model, true);
    },
    validCallback: function (valid) {
        if (valid) {
            this.button.prop('disabled', false);
        } else {
            this.button.prop('disabled', true);
        }
    },
    initialize: function(attr, options) {
        this.collection = attr.collection;
        this.meshCollection = attr.meshCollection;
        this.selectView = attr.selectView;
    },
    render: function()
    {
        AmpersandFormView.prototype.render.apply(this, arguments);

        $( this.el ).find('input').prop('autocomplete', 'off');

        this.buttonTemplate = '<div class="btn-group"> \
  <a class="btn btn-large btn-primary dropdown-toggle" data-toggle="dropdown" href="#"> \
    New Model \
    <span class="caret"></span> \
  </a> \
  <ul class="dropdown-menu"> \
    <li><a data-hook="concentration" tabindex="-1" href="#">Concentration, Well-mixed</a></li> \
    <li><a data-hook="population" tabindex="-1" href="#">Population, Well-mixed</a></li> \
    <li><a data-hook="spatial" tabindex="-1" href="#">Population, Spatial</a></li> \
  </ul> \
</div>';

        this.button = $( this.buttonTemplate ).appendTo( $( this.el ) );

        $( this.el ).find('[data-hook=concentration]').click( _.bind(_.partial(this.submitCallback, 'concentration'), this));
        $( this.el ).find('[data-hook=population]').click( _.bind(_.partial(this.submitCallback, 'population'), this));
        $( this.el ).find('[data-hook=spatial]').click( _.bind(_.partial(this.submitCallback, 'spatial'), this));
    }
});