Changeset 160

Show
Ignore:
Timestamp:
08/19/08 19:33:25 (3 months ago)
Author:
johnbywater
Message:

Renamed Model to DomainObject?. Added model object. Trying to use mootools Chains to load thread factlets.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/microfacts/public/behaviour/app/controllers/factlet_controller.js

    r158 r160  
    44    initialize: function () { 
    55        this.parent.apply(this, arguments); 
    6         this.model = Model.Resource('Factlet', this.id()); 
     6        this.model = DomainObject.Resource('Factlet', this.id()); 
    77        this.views.push(new FillView()); 
    88        this.views.push(new PageTitleView('Factlets')); 
  • trunk/microfacts/public/behaviour/app/controllers/threadfactlets_controller.js

    r159 r160  
    44    initialize: function () { 
    55        this.parent.apply(this, arguments); 
    6 //        this.model = Model.Resource('Factlet', this.id()); 
     6//        this.model = DomainObject.Resource('Factlet', this.id()); 
    77//        this.views.push(new FillView()); 
    88//        this.views.push(new PageTitleView('Factlets')); 
     
    1919    }, 
    2020 
    21     onNewData: function(data) { 
    22 //       if data is relevant to us: 
    23 //            this.factlets.append ... 
     21    onThreadStart: function (thread) { 
     22        this.thread = thread; 
     23        //fctid = thread.factlets[0]; 
     24        //factlet = DomainObject.Resource('Factlet', fctid); 
     25        console.log("ThreadFactletsController saw threadStart event"); 
     26        console.log(thread); 
    2427    }, 
    25      
     28 
    2629    controls: { 
    2730        '.factlet click': function (e) { 
  • trunk/microfacts/public/behaviour/app/controllers/threadpage_controller.js

    r159 r160  
    99     
    1010    initialize: function (element) { 
     11        this.initModel(); 
     12        console.log('ThreadPageController: initialize'); 
    1113        this.controllers = []; 
    12         console.log('ThreadPageController: initialize'); 
    1314        element.getElements('.thread-factlets').each(function (el) { 
    1415            this.addController(new ThreadFactletsController(el)); 
    1516        }, this); 
    16         console.log(threadId); 
    17         this.model = Model.Resource('Thread', threadId); 
    18         console.log('Model is'); 
    19         console.log(this.model); 
     17 
     18        this.model.startWithThread(threadId); 
     19    }, 
     20 
     21    initModel: function (threadId) { 
     22        this.model = new Model(); 
     23        this.model.addEvent('threadStart', this.onThreadStart.bind(this)); 
     24    }, 
     25 
     26    onThreadStart: function(thread) { 
     27        console.log('ThreadPageController: onThreadStart'); 
     28        this.fireEvent('threadStart', thread); 
    2029    }, 
    2130 
     
    2433        controller.addEvent('factletSelect', this.onFactletSelect.bind(this)); 
    2534        this.addEvent('factletSelect', controller.onFactletSelect.bind(controller)); 
     35        this.addEvent('threadStart', controller.onThreadStart.bind(controller)); 
    2636    } 
    2737}); 
  • trunk/microfacts/public/behaviour/app/models/factlet.js

    r146 r160  
    11var Factlet = new Class({ 
    2     Extends: Model
     2    Extends: DomainObject
    33    options: { 
    44        name: 'factlet', 
  • trunk/microfacts/public/behaviour/app/models/thread.js

    r159 r160  
    11var Thread = new Class({ 
    2     Extends: Model
     2    Extends: DomainObject
    33    options: { 
    44        name: 'thread', 
    55        prefix: 'api/rest' 
     6    }, 
     7 
     8    // TODO: sort out getting factlets back ... 
     9 
     10    setData: function (data, json) { 
     11        this.data = data; 
     12        // Copy list of factlet ids. 
     13        var factletIds = $A(this.data.factlets); 
     14        this.incompleteIds = $A(this.data.factlets); 
     15        // Loop over factlet ids. 
     16        factletIds.each(function(factletId) { 
     17            DomainObject.Resource( 'Factlet', factletId); 
     18        }); 
     19    }, 
     20 
     21    onFactletLoadSuccess: function () { 
     22        // Remove from incomplete list. 
     23        // If incomplete list empty, fire event. 
     24    }, 
     25 
     26    onFactletLoadFailure: function () { 
     27        // Remove from incomplete list. 
     28        // Mark as errorful. 
    629    } 
    730 
    8     // TODO: sort out getting factlets back ... 
    931}); 
    1032 
  • trunk/microfacts/public/behaviour/lib/domainobject.js

    r153 r160  
    1 var Model = new Class({ 
     1var DomainObject = new Class({ 
    22    Implements: [Events, Options], 
    33     
     
    6464}); 
    6565 
    66 Model.Register = {}; 
     66DomainObject.Register = {}; 
    6767 
    68 Model.Resource = function (name, id) { 
    69     if ($type(Model.Register[name]) != 'object') { 
    70         Model.Register[name] = {}; 
     68DomainObject.Resource = function (name, id) { 
     69    if ($type(DomainObject.Register[name]) != 'object') { 
     70        DomainObject.Register[name] = {}; 
    7171    } 
    72     if (!$chk(Model.Register[name][id])) { 
     72    if (!$chk(DomainObject.Register[name][id])) { 
    7373        // FIXME: don't use eval (or at least not in such a horrible way) 
    7474        eval("var constructor = " + name); 
    75         Model.Register[name][id] = new constructor(id) 
     75        DomainObject.Register[name][id] = new constructor(id) 
    7676    } 
    77     return Model.Register[name][id]; 
     77    return DomainObject.Register[name][id]; 
    7878}; 
  • trunk/microfacts/public/behaviour/load.js

    r159 r160  
    3030 
    3131// ==================================================== 
    32 // = Base classes, Model, View, Controller, Delegator = 
     32// = Base classes, DomainObject, View, Controller, Delegator = 
    3333// ==================================================== 
    3434 
     
    3636    name: "model", 
    3737    type: "js", 
    38     path: "lib/model.js?" + Math.random(), 
     38    path: "app/models/model.js?" + Math.random(), 
    3939    requires: ['mootools'], 
    4040    varName: "Model" 
     41}); 
     42 
     43loader.addModule({ 
     44    name: "domainobject", 
     45    type: "js", 
     46    path: "lib/domainobject.js?" + Math.random(), 
     47    requires: ['mootools'], 
     48    varName: "DomainObject" 
    4149}); 
    4250 
     
    6674 
    6775// ========== 
    68 // = Models = 
     76// = DomainObjects = 
    6977// ========== 
    7078 
     
    7381    type: "js", 
    7482    path: "app/models/factlet.js?" + Math.random(), 
    75     requires: ['model'], 
     83    requires: ['domainobject'], 
    7684    varName: "Factlet" 
    7785}); 
     
    8189    type: "js", 
    8290    path: "app/models/thread.js?" + Math.random(), 
    83     requires: ['model'], 
     91    requires: ['domainobject'], 
    8492    varName: "Thread" 
    8593}); 
     
    165173    type: "js", 
    166174    path: "app/microfacts.js?" + Math.random(), 
    167     requires: ['model', 'view', 'controller', 'microfactscontroller', 'factletcontroller', 'threadfactletscontroller', 'mapcontroller', 'timelinecontroller'], 
     175    requires: ['domainobject', 'view', 'controller', 'microfactscontroller', 'factletcontroller', 'threadfactletscontroller', 'mapcontroller', 'timelinecontroller'], 
    168176    varName: "Microfacts" 
    169177}); 
     
    173181    type: "js", 
    174182    path: "app/controllers/threadpage_controller.js?" + Math.random(), 
    175     requires: ['model', 'view', 'controller', 'thread', 'threadfactletscontroller'], 
    176     varName: "TheadPageController" 
     183    requires: ['model', 'domainobject', 'view', 'controller', 'thread', 'factlet', 'threadfactletscontroller'], 
     184    varName: "ThreadPageController" 
    177185}); 
    178186