Changeset 355


Ignore:
Timestamp:
07/11/12 18:45:51 (13 years ago)
Author:
tjcschipper
Message:
  • surveyEditor more or less works! Only needed change is addition of "topic" property in question objects (database-side), and the change from "category"(string) to "categories"(string[]).
  • surveyEditor still needs removal function and infofunction to be written properly!
  • Added all files belonging to SurveyAdvanced?. Most do not work properly yet, but at least there will not be a 404 page when you click btnPreview on survey.html.
Location:
Dev/branches/rest-dojo-ui/client/rft
Files:
11 added
8 edited

Legend:

Unmodified
Added
Removed
  • Dev/branches/rest-dojo-ui/client/rft/css/layout.css

    r354 r355  
    343343.claro.blue .inheritBgColor {
    344344    background-color: #0072bc;
     345    color: #ffffff;
    345346}
    346347.claro div.green.inheritBgColor,
     
    348349.claro.green .inheritBgColor {
    349350    background-color: #3aa605;
     351    color: #ffffff;
    350352}
    351353.claro div.orange.inheritBgColor,
     
    353355.claro.orange .inheritBgColor {
    354356    background-color: #ff5b12;
     357    color: #ffffff;
    355358}
    356359.claro div.purple.inheritBgColor,
     
    358361.claro.purple .inheritBgColor {
    359362    background-color: #6529b7;
     363    color: #ffffff;
    360364}
    361365.claro div.red.inheritBgColor,
     
    363367.claro.red .inheritBgColor {
    364368    background-color: #8c0310;
     369    color: #ffffff;
    365370}
    366371.claro div.trans.inheritBgColor,
     
    368373.claro.trans .inheritBgColor {
    369374    background-color: transparent;
     375    color: #ffffff;
    370376}
    371377.claro div.blue.inheritBgColor.light,
     
    373379.claro.blue .inheritBgColor.light {
    374380    background-color: #0794d1;
     381    color: #ffffff;
    375382}
    376383.claro div.green.inheritBgColor.light,
     
    378385.claro.green .inheritBgColor.light {
    379386    background-color: #79ca0a;
     387    color: #ffffff;
    380388}
    381389.claro div.orange.inheritBgColor.light,
     
    383391.claro.orange .inheritBgColor.light {
    384392    background-color: #ff9140;
     393    color: #ffffff;
    385394}
    386395.claro div.purple.inheritBgColor.light,
     
    388397.claro.purple .inheritBgColor.light {
    389398    background-color: #993dec;
     399    color: #ffffff;
    390400}
    391401.claro div.red.inheritBgColor.light,
     
    393403.claro.red .inheritBgColor.light {
    394404    background-color: #bd0013;
     405    color: #ffffff;
    395406}
    396407
     
    453464
    454465
    455 
    456 
    457466/* Alignment */
    458467.claro .floatRight {
     
    461470    padding: 0;
    462471}
     472
     473
     474/* SurveyListView */
     475.claro .rftSurveyListView {
     476}
     477.claro .rftSurveyListView .rftSurveyListViewContent {
     478    height: 300px;
     479    background: #444444;
     480    overflow: auto;
     481}
     482.claro .rftSurveyListView .rftLineWithButtons .rftLineWithButtonsTitle {
     483    max-width: 200px;
     484    overflow: hidden;
     485}
  • Dev/branches/rest-dojo-ui/client/rft/css/rftLineWithButtons.css

    r349 r355  
    2222}
    2323
    24 /* Colour settings */
    25 .claro div.blue.rftLineWithButtons,
    26 .claro .blue .rftLineWithButtons {
    27     background-color: #0072bc;
     24/* SurveyListView stuff */
     25.claro div.blue.inheritBgColor.dojoDndItemAnchor,
     26.claro .blue .inheritBgColor.dojoDndItemAnchor,
     27.claro.blue .inheritBgColor.dojoDndItemAnchor {
     28    background-color: #0794d1;
    2829    color: #ffffff;
    2930}
    30 .claro div.red.rftLineWithButtons,
    31 .claro .red .rftLineWithButtons {
    32     background-color: #8c0310;
     31.claro div.green.inheritBgColor.dojoDndItemAnchor,
     32.claro .green .inheritBgColor.dojoDndItemAnchor,
     33.claro.green .inheritBgColor.dojoDndItemAnchor {
     34    background-color: #79ca0a;
    3335    color: #ffffff;
    3436}
    35 .claro div.green.rftLineWithButtons,
    36 .claro .green .rftLineWithButtons {
    37     background-color: #3aa605;
     37.claro div.orange.inheritBgColor.dojoDndItemAnchor,
     38.claro .orange .inheritBgColor.dojoDndItemAnchor,
     39.claro.orange .inheritBgColor.dojoDndItemAnchor {
     40    background-color: #ff9140;
    3841    color: #ffffff;
    3942}
    40 .claro div.purple.rftLineWithButtons,
    41 .claro .purple .rftLineWithButtons {
    42     background-color: #6529b7;
     43.claro div.purple.inheritBgColor.dojoDndItemAnchor,
     44.claro .purple .inheritBgColor.dojoDndItemAnchor,
     45.claro.purple .inheritBgColor.dojoDndItemAnchor {
     46    background-color: #993dec;
    4347    color: #ffffff;
    4448}
    45 .claro div.orange.rftLineWithButtons,
    46 .claro *.orange .rftLineWithButtons {
    47     background-color: #ff5b12;
     49.claro div.red.inheritBgColor.dojoDndItemAnchor,
     50.claro .red .inheritBgColor.dojoDndItemAnchor,
     51.claro.red .inheritBgColor.dojoDndItemAnchor {
     52    background-color: #bd0013;
    4853    color: #ffffff;
    4954}
    50 .claro div.trans.rftLineWithButtons,
    51 .claro .trans .rftLineWithButtons {
    52     background-color: transparent;
    53     color: #ffffff;
     55
     56.claro .rftLineWithButtons.dojoDndItem {
     57    transition: all 0.2s;
     58    -moz-transition: all 0.2s;
     59    -webkit-transition: all 0.2s;
     60    -o-transition: all 0.2s;
    5461}
     62.claro .rftLineWithButtons.dojoDndItem.dojoDndItemBefore {
     63    margin-top: 6px;
     64    border-top: 6px solid #ffffff;
     65}
     66.claro .rftLineWithButtons.dojoDndItem.dojoDndItemAfter {
     67    margin-bottom: 6px;
     68    border-bottom: 6px solid #ffffff;
     69}
     70.claro .dojoDndAvatar {
     71    color: #000000;
     72}
     73.claro .dojoDndSourceMoved .rftLineWithButtons.dojoDndItemAnchor {
     74    height: 0;
     75    overflow: hidden;
     76}
  • Dev/branches/rest-dojo-ui/client/rft/css/rftSelector.css

    r344 r355  
    3939    background-color: #00ff00;
    4040}
     41
     42.claro .rftSelector .rftSelectorOptions .rftLineWithButtons.selected {
     43   
     44}
  • Dev/branches/rest-dojo-ui/client/rft/pages/survey.html

    r354 r355  
    1 <div data-dojo-type="rft.pages.survey" id="survey">
     1<div data-dojo-type="rft.pages.survey" id="survey" class="blue">
    22    <div data-dojo-type="dijit.layout.BorderContainer" data-dojo-props="region:'center'" style="height: 500px;">
     3
    34        <div data-dojo-type="dijit.layout.ContentPane" data-dojo-props="region:'top'">
    45            <h2>
     
    78            </h2>
    89        </div>
     10       
    911        <div data-dojo-type="dijit.layout.BorderContainer" data-dojo-props="region:'center'">
    10             <div data-dojo-type="dijit.layout.ContentPane" data-dojo-props="region:'top'">
    11                 Presets
    12             </div>
    1312            <div id="tabList" data-dojo-type="dijit.layout.TabContainer" class="blue" data-dojo-props="tabPosition:'left-h',region:'center'">
    1413                <!-- tabs go here -->
    1514            </div>
    1615        </div>
    17         <!-- "Shopping cart" -->
     16       
    1817        <div data-dojo-type="dijit.layout.BorderContainer" data-dojo-props="region:'right'" style="width: 300px">
    19             <div data-dojo-type="dijit.layout.BorderContainer" data-dojo-props="region:'top'">
    20                 <h3>Included questions</h3>
     18            <div id="SurveyListViewNode" class="rftSurveyListView">
    2119            </div>
    22             <div data-dojo-type="rft.ui.List" data-dojo-props="region:'center'">
    23                 <!-- These would have to be dynamically generated instead of declared here! -->
    24                 <div data-dojo-type="rft.ui.LineWithActionsWidget" data-dojo-props="title:'Question one', actions: {'Cancel':{callback: function(){}, properties: {blockButton: false, icon: 'Delete', modifiers:'white'}}}"></div>
    25                 <div data-dojo-type="rft.ui.LineWithActionsWidget" data-dojo-props="title:'Question two', actions: {'Cancel':{callback: function(){}, properties: {blockButton: false, icon: 'Delete', modifiers:'white'}}}"></div>
    26             </div>
     20
    2721            <div data-dojo-type="dijit.layout.ContentPane" data-dojo-props="region: 'bottom'">
    2822                <button id="btnProperties" data-dojo-type="dijit.form.Button" data-dojo-props="baseClass: 'rftLargeButton', iconClass: 'rftIcon rftIconProperties'">Properties</button>
  • Dev/branches/rest-dojo-ui/client/rft/pages/survey.js

    r354 r355  
    11define(['dojo/_base/declare',
    2     'dojo/_base/lang',
    3     'dojo/_base/event',
    4     'dojo/_base/Deferred',
    5     'rft/ui/AccordionList',
    6     'rft/ui/LineWithActionsWidget',
    7     'rft/store',
    8     'rft/ui/_Page',
    9     'rft/api',
    10     'dijit/registry',
    11     'rft/content',
    12     'dojo/on',
    13     'dojo/query'],
    14     function(declare,lang,event,Deferred,AccordionList,LineWithActionsWidget,store,_Page,api,registry,content, on, query){
    15         return declare('rft.pages.survey',[_Page],{
    16             object: null,
    17             onVisit: function() {
    18                 if ( this.pageArgs.uid ) {
    19                     Deferred.when(store.get(this.pageArgs.uid))
    20                     .then(lang.hitch(this,function(obj){
    21                        this.object = obj;
    22                        return Deferred.when( obj.creator && store.dereference(obj.creator) );
    23                    }));
    24                     this._createQuestionBrowser();
    25                 } else {
    26                     //this.header.innerHTML = "Error: no uid for survey!"
    27                 }
    28                 this._setupButtons(this);
    29                 this._insertQuestion({title: "This is the question title!", sorting: {categories: ['CategoryOne', 'CategoryB123'], topic: 'The first question topic'}});
    30                 this._insertQuestion({title: "BLablabla question text!", sorting: {categories: ['CategoryOne'], topic: 'The first question topic'}});
    31                 this._insertQuestion({title: "Yaddayaddayaddaa ... sigh", sorting: {categories: ['CategoryThree', 'CategoryB123'], topic: 'Another topic'}});
    32             },
    33             onLeave: function() {
    34                 this.inherited(arguments);
    35             },
    36             onReset: function() {
    37                 this.setFields(this.object);
    38             },
    39             onSave: function(evt) {
    40                 /*lang.mixin(this.object,this.form.get('value'));
    41                 Deferred.when( store.put(this.object) )
    42                 .then(lang.hitch(this,function(obj){
    43                     this.object = obj;
    44                     this.setFields(obj);
    45                     api.notify("Object saved");
    46                 }),lang.hitch(this,function(){
    47                     api.notify("Object save failed",'error');
    48                 }));
    49                 event.stop(evt);
    50                 evt.stopPropagation();
    51                 return false;
    52                 */
    53             },
    54             _goToPreview: function() {
    55                 content.goTo('surveyAdvanced', {uid: this.object._id});
    56                 /*
    57                 * TODO: How to prevent widgets with identical id's on different pages clashing?
    58                 * For example: btnSave clashes when going from survey to surveyAdvanced, since both contain one. survey.btnSave is not destroyed when loading surveyAdvanced.btnSave!
    59                 * Since there is no page reload, only a contentPane content swap!
    60                 * Talk to Hendrik about this!
    61                 * TEMPORARY FIX IN THIS.ONLEAVE!
    62                 */
    63             },
    64             _setupButtons: function() {
    65                 // Setup button events
    66                 registry.byId("btnSave").on("click", lang.hitch(this, function(){
    67                     this.onSave(arguments);
    68                 }));
    69                 registry.byId("btnPreview").on("click", lang.hitch(this, function(){
    70                     this._goToPreview();
    71                 }));
    72             },
    73             _createQuestionBrowser: function() {
    74                 Deferred.when(store.query('_design/default/_view/by_type',{key:'Question'}))
    75                 .then(lang.hitch(this,function(questions){
    76                  questions.forEach(function(question) {
    77                     this._insertQuestion(question);
    78                 }, this);
    79              }));
    80             },
    81             _insertQuestion: function(question) {
    82                 // MASSIVE TODO: The question categories cannot have spaces currently, due to the way we append them to the ID property of the container. ID's cannot have spaces.
    83                 // Easy fix: Replace spaces with underscores for the time being? The alternative is to make these containers have an actual "questioncategory" property in the governing widget. Not fun.
    84                 var tabs = registry.byId("tabList");
    85                 for (var c in question.sorting.categories) {
    86                     var cat = question.sorting.categories[c];
    87                     var catPane = query("#tab"+cat, tabs.containerNode)[0];
    88                     if (catPane) {
    89                         this._insertIntoCategory(question, catPane);
    90                     } else {
    91                         catPane = this._createCategoryTab(cat);
    92                         if (catPane) {
    93                             this._insertIntoCategory(question, catPane);
    94                         } else {
    95                             throw "Error: could not find or create category pane!";
    96                         }
    97                     }
    98                 }
    99             },
    100             _createCategoryTab: function(category) {
    101                 var tabs = registry.byId("tabList");
    102                 var newCat = new dijit.layout.ContentPane({
    103                     title: category
    104                 });
    105                 newCat.domNode.id = "tab"+category;
    106                 tabs.addChild(newCat);
    107                 var pane = query("#tab"+category, tabs.containerNode)[0];
    108                 return (pane) ? pane : false;
    109             },
    110             _insertIntoCategory: function(question, container) {
    111                 debugger;
    112                 var selector = query(".rftSelector[title='"+question.sorting.topic+"']", container)[0];
    113                 var selectorWidget;
    114                 if (selector) {
    115                     selectorWidget = registry.byNode(selector);
    116                    
    117                 } else {
    118                     selectorWidget = new rft.ui.Selector({
    119                         title: question.sorting.topic
    120                     });
    121                     selectorWidget.placeAt(container);
    122                 }
    123                 selectorWidget.addQuestion(question);
    124             },
     2        'dojo/_base/lang',
     3        'dojo/_base/event',
     4        'dojo/_base/Deferred',
     5        'rft/ui/AccordionList',
     6        'rft/ui/LineWithActionsWidget',
     7        'rft/ui/SurveyListView',
     8        'rft/store',
     9        'rft/ui/_Page',
     10        'rft/api',
     11        'dijit/registry',
     12        'rft/content',
     13        'dojo/on',
     14        'dojo/query'],
     15        function(declare,lang,event,Deferred,AccordionList,LineWithActionsWidget,SurveyListView,store,_Page,api,registry,content, on, query){
     16                return declare('rft.pages.survey',[_Page],{
     17                        object: null,
     18                        questions: null,
     19                        listView: null,
     20                       
     21                        onVisit: function() {
     22                                if ( this.pageArgs.uid ) {      // Load survey
     23                                        Deferred.when(store.get(this.pageArgs.uid))
     24                                        .then(lang.hitch(this,function(obj){
     25                                                this.object = obj;
     26                                                return Deferred.when( obj.creator && store.dereference(obj.creator) );
     27                                        }));
    12528
     29                                        //this._createQuestionBrowser();        // Load questions database and create browser
     30                                        this.questions = new dojo.store.Memory({        // Create local copy store of questions database
     31                                                data: [],
     32                                                idProperty: "_id"
     33                                        });
     34                                } else {
     35                                        throw "No valid uid or survey passed!";
     36                                }
     37                                this._setupButtons(this);
     38                                var testQuestion1 = {_id: "123", title: "How long have you worked here?", categories: ['Professional background'], topic: 'Work experience'};
     39                                this.questions.add(testQuestion1);
     40                                this._insertQuestion(testQuestion1);
     41                                var testQuestion2 = {_id: "234", title: "How many years have you been employed here?", categories: ['Respondent personals','Professional background'], topic: 'Work experience'};
     42                                this.questions.add(testQuestion2);
     43                                this._insertQuestion(testQuestion2);
     44                                var testQuestion3 = {_id: "345", title: "Have you worked here longer than 10 years?", categories: ['Respondent personals','Professional background'], topic: 'Work experience'};
     45                                this.questions.add(testQuestion3);
     46                                this._insertQuestion(testQuestion3);
     47                                var testQuestion4 = {_id: "456", title: "Rate your experience at your current employer from 1 to 10.", categories: ['Respondent personals','Professional background'], topic: 'Work experience'};
     48                                this.questions.add(testQuestion4);
     49                                this._insertQuestion(testQuestion4);
     50                               
     51                                this._createListView(this.questions);
     52                        },
     53                        onLeave: function() {
     54                                this.inherited(arguments);
     55                        },
     56                        onReset: function() {
     57                                this.setFields(this.object);
     58                        },
     59                        onSave: function(evt) {
     60                                /*lang.mixin(this.object,this.form.get('value'));
     61                                Deferred.when( store.put(this.object) )
     62                                .then(lang.hitch(this,function(obj){
     63                                this.object = obj;
     64                                this.setFields(obj);
     65                                api.notify("Object saved");
     66                                }),lang.hitch(this,function(){
     67                                api.notify("Object save failed",'error');
     68                                }));
     69                                event.stop(evt);
     70                                evt.stopPropagation();
     71                                return false;
     72                                */
     73                        },
     74                        _goToPreview: function() {
     75                                content.goTo('surveyAdvanced', {uid: this.object._id});
     76                        },
     77                        _setupButtons: function() {
     78                                // Setup button events
     79                                registry.byId("btnSave").on("click", lang.hitch(this, function(){
     80                                        this.onSave(arguments);
     81                                }));
     82                                registry.byId("btnPreview").on("click", lang.hitch(this, function(){
     83                                        this._goToPreview();
     84                                }));
     85                        },
     86                        /* Store code */
     87                        GetQuestion: function(_id) {
     88                                return this.questions.get(_id);
     89                        },
     90                        SetQuestion: function(question) {
     91                                return this.questions.put(question);
     92                        },
     93                        SyncStore: function() {
     94                        },
     95                        /* Browser code */
     96                        _createQuestionBrowser: function() { // TODO: Do all operations from the local store. Put querying routine in SyncStore()!
     97                                var getQuestions = function(self){
     98                                        return questions = Deferred.when(store.query('_design/default/_view/by_type', {key:'Question'}), function(res){
     99                                                self.questions.setData(res);    // Store queried questions in this.questions MemoryStore
     100                                                return res;
     101                                        });
     102                                };
    126103
     104                                Deferred.when(getQuestions(this), lang.hitch(this, function(questions){
     105                                        questions.forEach(function(question){
     106                                                this._insertQuestion(question)
     107                                        }, this);
     108                                }), function(err){
     109                                        throw "Questions could not be fetched. No connection or null query!";
     110                                });
     111                        },
     112                        _insertQuestion: function(question) {
     113                                var tabs = registry.byId("tabList");
     114                                for (var c in question.categories) {
     115                                        var cat = question.categories[c];
     116                                        var q = "div[data-category='"+cat+"']";
     117                                        var catPane = query(q, tabs.containerNode)[0];
     118                                        if (catPane) {
     119                                                this._insertIntoCategory(question, catPane);
     120                                        } else {
     121                                                catPane = this._createCategoryTab(cat);
     122                                                if (catPane) {
     123                                                        this._insertIntoCategory(question, catPane);
     124                                                } else {
     125                                                        throw "Error: could not find or create category pane!";
     126                                                }
     127                                        }
     128                                }
     129                        },
     130                        _createCategoryTab: function(category) {
     131                                var tabs = registry.byId("tabList");
     132                                var newCat = new dijit.layout.ContentPane({
     133                                        title: category,
     134                                        postCreate: function(){
     135                                                this.domNode.dataset["category"] = category;
     136                                        }
     137                                });
     138                                newCat.domNode.id = "tab"+category;
     139                                tabs.addChild(newCat);
     140                                var q = "div[data-category='"+category+"']";
     141                                var pane = query(q, tabs.containerNode)[0];
     142                                return (pane) ? pane : false;
     143                        },
     144                        _insertIntoCategory: function(question, container) {
     145                                var selector = query(".rftSelector[data-topic='"+question.topic+"']", container)[0];
     146                                var selectorWidget;
     147                                if (selector) {
     148                                        selectorWidget = registry.byNode(selector);
    127149
     150                                } else {
     151                                        selectorWidget = new rft.ui.Selector({
     152                                                topic: question.topic,
     153                                                controller: this
     154                                        });
     155                                        selectorWidget.placeAt(container);
     156                                }
     157                                selectorWidget.addQuestion(question._id);
     158                        },
     159                        /* ListView code */
     160                        _createListView: function() {
     161                                this.listView = new SurveyListView({
     162                                        controller: this
     163                                }).placeAt("SurveyListViewNode");
     164                        },
     165                        IncludeQuestion: function(_id) {
     166                                this.listView.insertItem(_id);
     167                        },
    128168
    129         });
     169                });
    130170});
    131171
  • Dev/branches/rest-dojo-ui/client/rft/ui/LineWithActionsWidget.js

    r350 r355  
    1 define(['dojo/_base/declare','dojo/_base/lang','dojo/on','dojo/dom', 'dojo/dom-class', 'dijit/form/Button',
    2     'dijit/_WidgetBase','dijit/_TemplatedMixin','dijit/_WidgetsInTemplateMixin',
    3     'dojo/text!./templates/LineWithActionsWidget.html'
    4     ],
    5     function(declare,lang,on,dom,domClass,Button,_WidgetBase,_TemplatedMixin,_WidgetsInTemplateMixin,templateString){
    6         return declare('rft.ui.LineWithActionsWidget',[_WidgetBase,_TemplatedMixin,_WidgetsInTemplateMixin],{
    7             templateString: templateString,
    8             baseClass: 'rftLineWithButtons',
    9             title: '',
    10             modifiers: "blue",
    11             userObject: null,
    12             actions: {},
    13             postCreate: function() {
    14                 dom.setSelectable(this.domNode, false);
    15                 on(this.titleNode,'click',lang.hitch(this,'_onClick'));
    16             },
    17             startup: function() {
    18                 this.inherited(arguments);
    19                 this._setupActions();
    20                 domClass.add(this.domNode, this.modifiers);
    21                 this.refresh();
    22             },
    23             _setupActions: function() {
    24                 for (var action in this.actions) {
    25                     var properties;
    26                     if (this.actions[action].properties.blockButton == true) {  // BlockButton
    27                         properties = lang.mixin({
    28                             baseClass: 'rftBlockButton',
    29                             modifiers: this.modifiers,
    30                             label: "Default",
    31                             iconClass: 'rftIcon rftIcon'+this.actions[action].properties.icon,
    32                             title: action,
    33                             onClick: lang.hitch(this, this.actions[action].callback)
    34                         }, this.actions[action].properties);
    35                         properties["class"] = properties.modifiers;
    36                         new Button(properties).placeAt(this.buttonsNode);
    37                     } else {    //InlineButton
    38                         properties = lang.mixin({
    39                             baseClass: 'rftInlineButton',
    40                             modifiers: 'black',
    41                             label: "Default",
    42                             showLabel: false,
    43                             iconClass: 'rftIcon rftIcon'+this.actions[action].properties.icon,
    44                             title: action,
    45                             onClick: lang.hitch(this, this.actions[action].callback)
    46                         }, this.actions[action].properties);
    47                         properties["class"] = properties.modifiers;
    48                         new Button(properties).placeAt(this.buttonsNode);
    49                     }
    50                 }
    51             },
    52             refresh: function() {
    53                 this.titleNode.innerHTML = this.title;
    54             },
    55             _onClick: function(e){
    56                 var preventDefault = this.onClick(e) === false;
    57                 if(preventDefault){
    58                     e.preventDefault();
    59                 }
    60                 return !preventDefault;
    61             },
    62             onClick: function(e) {},
    63             _setTitleAttr: function(value){
    64                 this.title = value;
    65                 this.refresh();
    66             }
    67         });
    68     });
     1define(['dojo/_base/declare',
     2        'dojo/_base/lang',
     3        'dojo/on',
     4        'dojo/dom',
     5        'dojo/_base/event',
     6        'dojo/dom-class',
     7        'dijit/form/Button',
     8        'dijit/_WidgetBase',
     9        'dijit/_TemplatedMixin',
     10        'dijit/_WidgetsInTemplateMixin',
     11        'dojo/text!./templates/LineWithActionsWidget.html'
     12        ],
     13        function(declare,lang,on,dom,event,domClass,Button,_WidgetBase,_TemplatedMixin,_WidgetsInTemplateMixin,templateString){
     14                return declare('rft.ui.LineWithActionsWidget',[_WidgetBase,_TemplatedMixin,_WidgetsInTemplateMixin],{
     15                        templateString: templateString,
     16                        baseClass: 'rftLineWithButtons',
     17                        title: '',
     18                        modifiers: "blue",
     19                        selectable: false,
     20                        userObject: null,
     21
     22                        actions: {},
     23                        postCreate: function() {
     24                                dom.setSelectable(this.domNode, false); // Text selection, has nothing to do with object selection!
     25                                on(this.domNode,'click',lang.hitch(this,'_onClick'));
     26                        },
     27                        startup: function() {
     28                                this.inherited(arguments);
     29                                this._setupActions();
     30                                domClass.add(this.domNode, this.modifiers);
     31                                this.refresh();
     32                        },
     33                        _setupActions: function() {
     34                                for (var action in this.actions) {
     35                                        var properties;
     36                                        if (this.actions[action].properties.blockButton == true) {
     37                                                properties = lang.mixin({
     38                                                        baseClass: 'rftBlockButton',
     39                                                        modifiers: this.modifiers,
     40                                                        label: "Default",
     41                                                        iconClass: 'rftIcon rftIcon'+this.actions[action].properties.icon,
     42                                                        title: action,
     43                                                        onClick: lang.hitch(this, function(e){
     44                                                                lang.hitch(this, this.actions[action].callback )(e);
     45                                                                event.stop(e);
     46                                                                return false;
     47                                                        })
     48                                                }, this.actions[action].properties);
     49                                                properties["class"] = properties.modifiers;
     50                                                new Button(properties).placeAt(this.buttonsNode);
     51                                        } else {
     52                                                properties = lang.mixin({
     53                                                        baseClass: 'rftInlineButton',
     54                                                        modifiers: 'black',
     55                                                        label: "Default",
     56                                                        showLabel: false,
     57                                                        iconClass: 'rftIcon rftIcon'+this.actions[action].properties.icon,
     58                                                        title: action,
     59                                                        onClick: lang.hitch(this, function(e){
     60                                                                lang.hitch(this, this.actions[action].callback)(e);
     61                                                                event.stop(e);
     62                                                                return false;
     63                                                        })
     64                                                }, this.actions[action].properties);
     65                                                properties["class"] = properties.modifiers;
     66                                                new Button(properties).placeAt(this.buttonsNode);
     67                                        }
     68                                }
     69                        },
     70                        refresh: function() {
     71                                this.titleNode.innerHTML = this.title;
     72                        },
     73                        _onClick: function(e){
     74                                var preventDefault = this.onClick(e) === false;
     75                                if (preventDefault) {
     76                                        event.stop(e);
     77                                }
     78                                return !preventDefault;
     79                        },
     80                        onClick: function(e) {
     81                        },
     82                        _setTitleAttr: function(value){
     83                                this.title = value;
     84                                this.refresh();
     85                        }
     86                });
     87});
  • Dev/branches/rest-dojo-ui/client/rft/ui/Selector.js

    r354 r355  
    11define([
    22    'dojo/_base/declare',
     3    'dojo/_base/array',
     4    'dijit/registry',
    35    'dojo/_base/lang',
    46    'dojo/fx',
     
    1214    ],function(
    1315        declare,
     16        baseArray,
     17        registry,
    1418        lang,
    1519        fx,
     
    2428        return declare('rft.ui.Selector',[_WidgetBase,_TemplatedMixin,_WidgetsInTemplateMixin,_Container],{
    2529            templateString: templateString,
    26             title: "The professional as a participant",
     30            title: "ERROR: NULL_TOPIC",
    2731            baseClass: 'rftSelector',
    2832            modifiers: 'blue',
     33            currentlySelectedId: null,
     34            controller: null,   // Use events/pubsub instead of a controller variable? Decoupling!
     35
    2936            postCreate: function() {
    3037                domClass.add(this.domNode, this.modifiers);
    3138                domClass.add(this.selectedColorNode, "pending");
    32                
     39                this.domNode.dataset["topic"] = this.topic;
     40
    3341                new LineWithActionsWidget({
    34                     title: this.title,
     42                    title: this.topic,
    3543                    modifiers: this.modifiers,
    3644                    actions: {
    3745                        "AddToSurvey" : {
    38                             callback: function(arg){},
     46                            callback: lang.hitch(this, this.includeQuestion),
    3947                            properties: {
    4048                                blockButton: true,
     
    4654                    }
    4755                },this.titleNode);
    48                
     56
    4957                this.selectorLine = new LineWithActionsWidget({
    5058                    title: 'None',
     
    6371                },this.selectedItemNode);
    6472            },
    65             _toggleDropdown: function(selectorLine) {
     73            _toggleDropdown: function() {
     74
    6675                var node = this.optionsNode;
    6776                var show = fx.wipeIn({
     
    94103                };
    95104            },
    96             addQuestion: function(question) {
    97                 new LineWithActionsWidget({
    98                     title: question.title,
    99                     question: question,
    100                     actions: {
    101                         "InfoHover" : {
    102                             callback: this.infoFunction,
    103                             properties: {
    104                                 blockButton: false,
    105                                 showLabel: false,
    106                                 icon: "Inspect"
     105            addQuestion: function(questionId) {
     106                var question = this.controller.GetQuestion(questionId);
     107                if (question) {
     108                    var w = new LineWithActionsWidget({
     109                        title: question.title,
     110                        questionId: questionId,
     111                        actions: {
     112                            "InfoHover" : {
     113                                callback: dojo.partial(this.infoFunction, this),
     114                                properties: {
     115                                    blockButton: false,
     116                                    showLabel: false,
     117                                    icon: "Inspect"
     118                                }
    107119                            }
    108120                        }
    109                     }
    110                 }).placeAt(this.optionsNode);
     121                    });
     122                    w.placeAt(this.optionsNode);
     123                    w.on("Click", lang.hitch(this, function(){
     124                        this.selectQuestion(questionId);
     125                        this._toggleDropdown();
     126                    }, questionId));
     127
     128                }   
    111129            },
    112             infoFunction: function(){
    113                 alert("Some info here!");text
     130            infoFunction: function(selector) {
     131                var question = selector.controller.GetQuestion(this.questionId);
     132                console.log(question);
     133                alert("Some info here!");
     134            },
     135            includeQuestion: function() {
     136                if (this.currentlySelectedId) {
     137                    this.controller.IncludeQuestion(this.currentlySelectedId)
     138                } else {
     139                    return false;
     140                }
     141            },
     142            selectQuestion: function(questionId) {
     143                /* TODO: TEST THOROUGHLY! */
     144                var question = this.controller.GetQuestion(questionId);
     145                if (question) {
     146                    this.currentlySelectedId = questionId;
     147                    this.selectorLine.questionId = questionId;
     148                    this.selectorLine.set("title", question.title);
     149                    // Iterate through optionsNode, add "selected" class to currently selected node
     150                    baseArray.forEach(this.optionsNode.childNodes, function(node, index){
     151                        var line = registry.byNode(node);
     152                        if (line) {
     153                            if (line.questionId == this.currentlySelectedId) {
     154                                domClass.add(line.domNode, "inheritBgColor light");
     155                            } else {
     156                                domClass.remove(line.domNode, "inheritBgColor light");
     157                            }
     158                        }
     159                    }, this);
     160                }
    114161            }
    115162        });
  • Dev/branches/rest-dojo-ui/client/rft/ui/templates/LineWithActionsWidget.html

    r316 r355  
    1 <div class="${baseClass}">
     1<div class="${baseClass} inheritBgColor">
    22    <span class="${baseClass}Title" data-dojo-attach-point="titleNode"></span>
    33    <span class="${baseClass}Buttons" data-dojo-attach-point="buttonsNode"></span>
Note: See TracChangeset for help on using the changeset viewer.