bobamo /plugins/generator/views/views/finder.js

Language Javascript Lines 55
MD5 Hash 253d0d493e7d86078ff251f0516c06de
Repository git://github.com/jspears/bobamo.git View Raw File
| Open JSFiddle
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// Filename: ${baseUrl}/js/views/list.js
define([
    'underscore',
    'Backbone.Form',
    'libs/bobamo/list',

    'modelcollections/${model.modelName}',
    'text!templates/${model.modelName}/table.html',
    'text!templates/${model.modelName}/table-item.html'
], function (_,Form,View, m, tableTemplate, tableItemTemplate) {
    "use strict";

     var qform = {{html JSON.stringify(model.finder(view).display) || 'null' }};
    return View.extend({
        initialize:function(options, params){
            var FM =     m.Collection.extend({
                url:'${api}/${model.modelName}/finder/${view}'
            });
            this.collection = new FM()
            View.prototype.initialize.apply(this, arguments);
        },
        events:_.extend({},View.prototype.events,{
                submit:'onFormSubmit'
        }),
        onFormSubmit:function(e){
            e.preventDefault();
            console.log('onFormSubmit',this.form.getValue());
            this.$paginate.paginate('update', {skip:0}); //reset the skip.
            this.update(null, {skip:0});
        },
        update:function(mesg, data){
            View.prototype.update.call(this, mesg, _.extend({}, data,  this.form && this.form.getValue() || null));
        },
        template:_.template(tableTemplate),
        render:function(){
            View.prototype.render.apply(this, arguments);
            if (qform){
                var form = this.form = new Form(qform).render();
                form.$el.append('<div class="form-actions"><input type="reset" class="btn" value="Clear"><button type="submit" class="btn pull-right btn-primary save finish">Submit</button></div>')
                this.$el.find('.table').before(form.el);
            }

            this.$table.find('.title').append(" &gt; <span>${model.finder(view).title}</span>")

            return this;
        },
        listItemTemplate:_.template(tableItemTemplate),
        config:{
            title:'${model.title}',
            modelName:'${model.modelName}',
            plural:'${model.plural}'
        }
    });
});
Back to Top