Changeset 101
- Timestamp:
- 04/25/08 22:05:36 (4 months ago)
- Files:
-
- trunk/microfacts/public/app/controllers/thread_controller.js (modified) (3 diffs)
- trunk/microfacts/public/app/master.js (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/microfacts/public/app/controllers/thread_controller.js
r99 r101 7 7 // id out of the ElementStore. See master.js to see where 8 8 // it was put in. 9 this. data = this.element.retrieve('thread:data');9 this.id = this.element.retrieve('thread:id'); 10 10 11 11 // Store data object in the ElementStore. See 12 12 // factlet_controller.js for comments about this. 13 13 this.element.store('thread:controller', this); 14 15 // Get our own copy of our data from the server. This saves16 // us parsing HTML.17 Thread.entityGet(this.data.id).callback(function (reqData) {18 this.data = Thread.entities[this.data.id];19 }, this).send();20 21 14 22 15 if(this.getElement('.thread-factlets')) { … … 36 29 }).unmarshal(this.getElement('.thread-factlets')); 37 30 38 this.deckController = new DeckController(this.deck, $('thread-control-'+this. data.id));31 this.deckController = new DeckController(this.deck, $('thread-control-'+this.id)); 39 32 40 33 // TODO: Ideally somehow factor these two out of here. … … 60 53 } 61 54 }, 55 data: function () { 56 return Thread.entityGet(this.id); 57 }, 62 58 appendFactlet: function (id) { 63 var reqData = $deepClone(this.data); 64 reqData.factlets = reqData.factlets.extend([id]); 65 Thread.entityPut(reqData.id).callback(function () { 66 this.data = Thread.get(reqData.id); 67 this.redraw(); 68 }, this).send(JSON.encode(reqData)); 59 this.data().callback(function(data) { 60 var reqData = $deepClone(data); 61 reqData.factlets = reqData.factlets.extend([id]); 62 Thread.entityPut(reqData.id).callback(function (respData) { 63 this.redraw(respData); 64 }, this).send(JSON.encode(reqData)); 65 }, this).send(); 69 66 }, 70 redraw: function () { 71 var renderData = $deepClone(this.data); 72 renderData.factlets = renderData.factlets.map(function (id) { 73 return Factlet.get(id); 74 }); 75 this.renderViewTo(this.getElement('.thread-factlets'), 'thread/factlet-list', renderData); 67 redraw: function (threadData) { 68 var len = threadData.factlets.length; 69 threadData.factlets.each(function (id, idx) { 70 Factlet.entityGet(id).callback(function(factlet) { 71 threadData.factlets[idx] = factlet; 72 if (idx === (len - 1)) { 73 this.renderViewTo(this.getElement('.thread-factlets'), 'thread/factlet-list', threadData); 74 } 75 }, this).send(); 76 }, this); 76 77 } 77 78 }); trunk/microfacts/public/app/master.js
r88 r101 36 36 $$('.thread').each(function (elem) { 37 37 var id = elem.get('id').split('-').at(-1); 38 elem.store('thread: data', {id: id});38 elem.store('thread:id', id); 39 39 threadControllers[id] = new ThreadController(elem); 40 40 });
