Ignore:
Timestamp:
07/05/12 12:49:21 (13 years ago)
Author:
hendrikvanantwerpen
Message:

Added DB code to sessions page.
Removed old static mockups.
Removed dup widgets.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • Dev/branches/rest-dojo-ui/client/rft/pages/sessions.js

    r350 r353  
    1 define(['dojo/_base/declare','dojo/_base/lang','dojo/_base/Deferred','dojo/data/ObjectStore','rft/auth','rft/store','rft/content','rft/ui/_Page'],
    2     function(declare,lang,Deferred,ObjectStore,auth,store,content,_Page){
     1define(['dojo/_base/declare','dojo/_base/lang','rft/store','rft/content','rft/ui/_Page','rft/ui/ObjectBox'],
     2    function(declare,lang,store,content,_Page,ObjectBox){
    33        return declare('rft.pages.sessions',[_Page],{
    44            selectedObject: null,
    55            onVisit: function() {
    6                 this.grid.setStore(
    7                     ObjectStore({objectStore: store}),
    8                     "_design/default/_view/by_type",{key:'Survey'});
    9                
    10                 this.grid.on('rowclick',lang.hitch(this,function(evt){
    11                     this.selectedObject = evt.grid.getItem(evt.rowIndex);
    12                     this.btnEdit.set('disabled',!this.selectedObject);
     6                this._refresh();
     7            },
     8            _refresh: function() {
     9                this.containerTemplates.set('content','');
     10                this.containerSessions.set('content','');
     11                this._refreshByType('SessionTemplate',this.containerTemplates.domNode);
     12                this._refreshByType('SessionInstance',this.containerSessions.domNode);
     13            },
     14            _refreshByType: function(type,container) {
     15                store.query("_design/default/_view/by_type",{key:type})
     16                .forEach(lang.hitch(this,function(obj){
     17                    var widget = new ObjectBox({
     18                        title: obj.title || "Untitled",
     19                        actions: {
     20                            "Edit": function(){alert('Custom edit code');},
     21                            "Delete": lang.hitch(this,function(){
     22                                store.remove(store.getIdentity(obj),store.getRevision(obj))
     23                                .then(lang.hitch(this,function(){
     24                                    this._refresh();
     25                                }));
     26                            }),
     27                            "Custom function": function(){alert('newCommand');},
     28                            "Publish": lang.hitch(this,this._publishSession,obj)
     29                        }
     30                    });
     31                    widget.startup();
     32                    widget.placeAt(container, "last");
    1333                }));
    14 
    15                 this.grid.on('rowdblclick',lang.hitch(this,function(evt){
    16                     var obj = evt.grid.getItem(evt.rowIndex);
    17                     content.goTo('/survey',{uid:store.getIdentity(obj)});
     34            },
     35            onAddSessionTemplate: function(){
     36                store.put({
     37                    type: 'SessionTemplate',
     38                    title: 'TeamUp Basic Template'
     39                })
     40                .then(lang.hitch(this,function(){
     41                    this._refresh();
    1842                }));
    19                                
    20                 this.btnNew.on('click',lang.hitch(this,function(){
    21                     Deferred.when( store.add({type:'Survey',creator:auth.getUser()}) )
    22                     .then(function(obj) {
    23                         content.goTo('/survey',{uid:store.getIdentity(obj)});
    24                     });
    25                 }));
    26 
    27                 this.btnEdit.on('click',lang.hitch(this,function(){
    28                     if ( this.selectedObject ) {
    29                         content.goTo('/survey',{uid:store.getIdentity(this.selectedObject)});
    30                     }
    31                    
     43            },
     44            _publishSession: function(sessionTemplate) {
     45                var publishDate = new Date();
     46                var session = {
     47                    type: "SessionInstance",
     48                    title: sessionTemplate.title,
     49                    date: publishDate.getDate()+"-"+publishDate.getMonth()+"-"+publishDate.getFullYear(),
     50                    creator: "Igor Mayer"
     51                };
     52                store.add(session)
     53                .then(lang.hitch(this,function(){
     54                    this._refresh();
    3255                }));
    3356            }
Note: See TracChangeset for help on using the changeset viewer.