source: Dev/branches/rest-dojo-ui/client/rft/ui/Breadcrumbs.js @ 411

Last change on this file since 411 was 410, checked in by hendrikvanantwerpen, 13 years ago

Next steps to actually make taking surveys possible.

Split Controller in Router and Content. Updated the view.html to work
with the new app/Content mechanism. Include view page in build profile.

Rearranged Couch design documents per type. Changed config tool so the
docs.js can be more readable, functions don't have to be on one line
anymore but are serialized later. Because the .htaccess proxy is limited
to the rft database for security reasons, the config tool has to be run
on Node.js, to be able to access the Couch port (which is limited by
cross domain security in the browser).

Added elastic search to .htaccess proxy as well. Seperated CouchStore?
from rft/store, which contains application specific data.

Removed some old API files that were hanging around still.

Introduced preview mode for viewSurvey page. Changed survey page to
only show published questions to be included. The surveys page has
three categories: drafts, published and runs. Creating survey runs is
not yet implemented.

File size: 4.0 KB
Line 
1define([
2    'dojo/_base/declare',
3    'dojo/_base/array',
4    'dijit/form/Button',
5    'dojo/dom-class',
6    'dojo/topic',
7    'dijit/_WidgetBase',
8    '../app/Router'
9], function(declare, baseArray, Button, domClass, topic, _WidgetBase,Router){
10    return declare([_WidgetBase], {
11        _crumbs: [],
12       
13        _last: function(){
14            return this._crumbs[this._crumbs.length-1];
15        },
16        _getIndexOf: function(label) {
17            baseArray.forEach(this._crumbs, function(crumb, index){
18                if (crumb.label === label) {
19                    return index;
20                }
21            }, this);
22            return -1;
23        },
24       
25        addCrumb: function(label, path) {
26            this._crumbs.push({
27                label: label,
28                path:path
29            });
30        },
31        _removeAfter: function(index) {
32            var removals = this._crumbs.slice(index+1);
33            this._crumbs = this._crumbs.slice(0, index+1);
34            baseArray.forEach(removals, function(removal){
35                removal.widget.destroyRecursive(false); // boolean "keepDOMnode"
36            }, this);
37            this._highlightLast();
38        },
39       
40        _highlightLast: function() {
41            domClass.add(this._last().widget, "breadcrumbCurrent");
42        },
43        _unhighlightLast: function() {
44            domClass.remove(this._last(), "breadcrumbCurrent");
45        },
46       
47        _changeTo: function(label, path) {
48            // TODO: Differentiate between navigating backwards and sideways/forward!
49            var index = baseArray.indexOf({label:label , path:path});
50            //var index = this._getIndexOf(label);  // Use this if passing path as an argument is not possible!
51            if (index >= 0) this._removeAfter(index);
52            this._addCrumb(label, path);
53            this._createBreadcrumbs();
54        },
55       
56        _createBreadcrumb: function(label, path) {
57            return new Button({
58                baseClass: "breadcrumb",
59                label: label,
60                showlabel: true,
61                iconClass: "dijitNoIcon",
62                onClick: lang.hitch(this, function(){
63                    Router.go(path);  // TODO: fix this call!
64                })
65            });
66        },
67        _createBreadcrumbs: function() {
68            baseArray.forEach(this._crumbs, function(crumb, index){
69                if (!crumb.widget) {
70                    crumb.widget = this._createBreadcrumb(crumb.label, crumb.path);
71                }
72            }, this);
73            this._highlightLast();
74        },
75        startup: function() {
76            if ( this._started ){ return; }
77            this.inherited(arguments);
78            // TODO: start page crumb creation?
79            this._createBreadCrumbs();
80            this._setupEvents();
81            this.inherited(arguments);
82        },
83        _setupEvents: function() {
84        // TODO: Bind changeTo() listener to an "onLoadPage" event exposed by rft.api!
85        topic.subscribe("rft/content/goTo", this._changeTo(label, path));
86        }
87    });
88});
89
90/*  Breadcrumbs system, which automatically generates styled buttons in the topBar.
91 *  Updates are triggered through a "changePage" subscription to "rft/connect/goTo" (method that loads pages in rft.connect.js)
92 *
93 * Todo: Startup() does not handle initial creation well. No initial breadcrumb is created on page load. What happens when I refresh the page, do all previous crumbs disappear?
94 * Todo: Pages should have a label/name besides the path, for display in the breadcrumbs bar. Perhaps the page main title? (Generate this header dynamically?)
95 * Todo: Put connect.publish("rft/content/goTo", args); call in rft/content, to trigger breadcrumbs updates
96 *      This method uses path and 'args'(?) instead of label and path, change terminology accordingly?
97 * Todo: breadcrumbs do not have context yet, unless we can somehow create that context from the path. Split path at "/" char, lookup label/title for each step?
98 *      (See before!)
99 *
100 */
Note: See TracBrowser for help on using the repository browser.