Document model appears to fetch mostly properly
Can fetch Documents, and then get pages triggers page retrieval and related field retrieval.
This commit is contained in:
parent
806f22db17
commit
9d2d000e48
5 changed files with 159 additions and 9 deletions
|
@ -11,7 +11,11 @@
|
|||
Page,
|
||||
Field,
|
||||
PageCollection,
|
||||
FieldCollection;
|
||||
FieldCollection,
|
||||
FieldData,
|
||||
FieldDataCollection,
|
||||
|
||||
DocumentView;
|
||||
|
||||
if (typeof exports !== 'undefined') {
|
||||
PDFFormFiller = exports;
|
||||
|
@ -25,6 +29,12 @@
|
|||
model: Field
|
||||
});
|
||||
|
||||
FieldData = PDFFormFiller.FieldData = Backbone.Model.extend({});
|
||||
|
||||
FieldDataCollection = PDFFormFiller.FieldDataCollection = Backbone.Collection.extend({
|
||||
model: FieldData
|
||||
});
|
||||
|
||||
Page = PDFFormFiller.Page = Backbone.Model.extend({
|
||||
initialize: function (options) {
|
||||
var fields,
|
||||
|
@ -42,16 +52,53 @@
|
|||
fetch: function () {
|
||||
var self = this;
|
||||
|
||||
Backbone.Model.prototype.fetch.apply(this, arguments).then(function () {
|
||||
return Backbone.Model.prototype.fetch.apply(this, arguments).then(function () {
|
||||
var model = self;
|
||||
// Auto-fetch the fields collection
|
||||
if (typeof model.get('fields') !== 'undefined') {
|
||||
model.get('fields').fetch();
|
||||
return model.get('fields').fetch();
|
||||
}
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
PageCollection = PDFFormFiller.PageCollection = Backbone.Collection.extend({
|
||||
model: Page
|
||||
});
|
||||
|
||||
Document = PDFFormFiller.Document = Backbone.Model.extend({
|
||||
initialize: function (options) {
|
||||
console.log(options);
|
||||
|
||||
if (typeof options.pages === 'undefined') {
|
||||
this.pages = new PageCollection();
|
||||
this.pages.url = this.url + '../page/';
|
||||
}
|
||||
},
|
||||
|
||||
getPage: function (page_num) {
|
||||
var page_ids = this.get('page_ids'),
|
||||
page_id = page_ids[page_num],
|
||||
page = this.pages.findWhere({id: page_id}),
|
||||
defer = new $.Deferred();
|
||||
|
||||
if (typeof page === 'undefined') {
|
||||
page = new Page();
|
||||
page.url = '/formfiller/api/page/' + page_id + '/';
|
||||
this.pages.add(page);
|
||||
page.fetch()
|
||||
.then(function () {
|
||||
return defer.resolve(page);
|
||||
});
|
||||
} else {
|
||||
defer.resolve(page);
|
||||
return defer.promise();
|
||||
}
|
||||
|
||||
return defer.promise();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
FieldItemPreviewView = PDFFormFiller.FieldItemPreviewView = Marionette.ItemView.extend({
|
||||
/* template: _.template('<div class="pff-field pff-field-<%= fieldtype %>"><%= name %></div>'), */
|
||||
|
@ -131,5 +178,22 @@
|
|||
|
||||
});
|
||||
|
||||
DocumentView = PDFFormFiller.DocumentView = Marionette.Layout.extend({
|
||||
template: _.template('<div class="buttons"><a class="prev" href="#">prev</a><a href="#">next</a></div><div class="editor"></div>'),
|
||||
regions: {
|
||||
buttons: '.buttons',
|
||||
editor: '.editor'
|
||||
},
|
||||
|
||||
ui: {
|
||||
next: ':contains("next")',
|
||||
prev: ':contains("prev")'
|
||||
},
|
||||
|
||||
initialize: function (options) {
|
||||
console.log(this.ui.next);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
}).call(this);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue