Changeset 410
- Timestamp:
- 09/07/12 16:59:14 (13 years ago)
- Location:
- Dev/branches/rest-dojo-ui
- Files:
-
- 5 added
- 4 deleted
- 28 edited
- 2 copied
- 2 moved
Legend:
- Unmodified
- Added
- Removed
-
Dev/branches/rest-dojo-ui/build/debug.profile.js
r408 r410 37 37 'config/db' :{ 38 38 include: [ 'config/db' ] 39 } /*,39 }, 40 40 'rft/view' :{ 41 41 include: [ 'rft/view' ] 42 } */42 } 43 43 } 44 44 }; -
Dev/branches/rest-dojo-ui/build/release.profile.js
r408 r410 52 52 'config/db' :{ 53 53 include: [ 'config/db' ] 54 } /*,54 }, 55 55 'rft/view' :{ 56 56 include: [ 'rft/view' ] 57 } */57 } 58 58 } 59 59 }; -
Dev/branches/rest-dojo-ui/client/config/db.js
r408 r410 1 require([ 2 'dojo/_base/json', 3 'dojo/_base/lang', 4 'dojo/_base/xhr', 5 'dojo/parser', 6 'dojo/query', 7 'dijit/registry', 8 'dojo/domReady!' 9 ],function(json,lang,xhr,parser,query,registry){ 10 var logNode; 11 var usernameInput, passwordInput, resetInput, configButton; 12 var defaultUsername = "", defaultPassword = ""; 13 var dbUrl = "../data/"; 1 define([ 2 'dojo/_base/json', 3 'dojo/_base/lang', 4 'dojo/Deferred', 5 'dojo/request', 6 'dojox/lang/functional', 7 './docs' 8 ],function(json,lang,Deferred,request,func,docs){ 9 var dbUrl = "http://localhost:5984/"; 14 10 15 parser.parse() 16 .then(function(){ 17 query("#log").forEach(function(n){logNode = n;}); 18 usernameInput = registry.byId('username'); 19 passwordInput = registry.byId('password'); 20 resetInput = registry.byId('reset'); 21 configButton = registry.byId('configure'); 22 23 usernameInput.set('value',defaultUsername); 24 passwordInput.set('value',defaultPassword); 25 configButton.on('click',configure); 26 27 log("Give CouchDB admin username & password and click 'Configure' to start.\nIf the database already exists, rft_admin password will suffice.",true); 28 }); 29 30 function configure(){ 31 var docs; 32 33 log("Configuring CouchDB for RFT:",true); 34 35 var username = usernameInput.get('value'); 36 var password = passwordInput.get('value'); 37 var reset = resetInput.get('value'); 38 39 log("Downloading most recent configuration."); 40 xhr('GET',{ 41 url: 'docs.json', 42 handleAs: 'json', 43 sync: true 44 },true) 45 .then(function(result){ 46 docs = result; 47 }); 48 49 function req(method,url,body) { 50 var args = { 51 url: dbUrl+url, 52 contentType: 'application/json', 53 handleAs: 'json', 54 sync: true 55 }; 56 if ( !body || lang.isObject(body) ) { 57 body = json.toJson(body || {}); 58 } 59 args.rawBody = body; 60 if ( username ) { 61 args.user = username; 62 args.password = password; 63 } 64 return xhr(method,args,true); 11 function serializeFunctions(value) { 12 if ( value === null ) { 13 return null; 14 } else if ( lang.isArray(value) ) { 15 return value; 16 } else if ( lang.isFunction(value) ) { 17 return value.toString(); 18 } else if ( lang.isObject(value) ) { 19 return func.mapIn(value,serializeFunctions); 20 } else { 21 return value; 65 22 } 66 67 log("Checking CouchDB version");68 req('GET','/')69 .then(function(res){70 if (res.version !== "1.2.0" ) {71 log("Found "+res.version+", only tested with CouchDB 1.2.0")72 } else {73 log("CouchDB 1.2.0 found")74 }75 });76 77 var exists = false;78 log("Checking database 'rft'");79 req('GET','/rft')80 .then(function(db){81 log("Database 'rft' found.")82 exists = true;83 });84 if ( exists && reset ) {85 req('DELETE','/rft');86 exists = false;87 }88 if ( !exists ) {89 log("Creating database 'rft'")90 req('PUT','/rft')91 };92 93 function processDoc(docUrl,doc){94 var configAction = doc.__configAction;95 delete doc.__configAction;96 switch (configAction) {97 case "ignore":98 log(docUrl+" ignored.");99 return false;100 case "update":101 log(docUrl+" updating.");102 return req('GET',docUrl)103 .then(function(oldDoc){104 lang.mixin(oldDoc,doc);105 return req('PUT',docUrl,oldDoc);106 },function(){107 return req('PUT',docUrl,doc);108 });109 case "replace":110 default:111 log(docUrl+" replacing.");112 return req('GET',docUrl)113 .then(function(oldDoc){114 doc['_rev'] = oldDoc['_rev'];115 return req('PUT',docUrl,doc);116 },function(){117 return req('PUT',docUrl,doc);118 });119 }120 }121 122 for (var docUrl in docs) {123 processDoc(docUrl,docs[docUrl]);124 }125 126 log("Done!");127 23 } 128 24 129 function log(text,overwrite) { 130 if ( overwrite ) logNode.innerHTML = text 131 else logNode.innerHTML = logNode.innerHTML + '\n' + text; 25 function req(method,path,body) { 26 var args = { 27 contentType: 'application/json', 28 handleAs: 'json', 29 data: json.toJson(body || {}) 30 }; 31 return request[method](dbUrl+path,args); 132 32 } 133 33 34 function asyncSeq(functions) { 35 var d = new Deferred(); 36 (function stepper(fs,arg) { 37 if ( fs.length > 0 ) { 38 try { 39 var f = fs.shift(); 40 var ret = f(arg); 41 if ( ret && ret.then ) { 42 ret.then(function(ret){ 43 stepper(fs,ret); 44 }); 45 } else { 46 stepper(fs,ret); 47 } 48 } catch(err) { 49 d.reject(err); 50 } 51 } else { 52 d.resolve(); 53 } 54 })(functions); 55 return d.promise; 56 } 57 58 function asyncFor(list,callback,ctx) { 59 var d = new Deferred(); 60 (function stepper(list,idx){ 61 if ( list.length > 0 ) { 62 var el = list.shift(); 63 var ret = callback.call(ctx,el,idx); 64 if ( ret && ret.then ) { 65 ret.then(function(){ 66 stepper(list,idx+1); 67 }); 68 } else { 69 stepper(list,idx+1); 70 } 71 } else { 72 d.resolve(); 73 } 74 })(list,0); 75 return d.promise; 76 } 77 78 asyncSeq([ 79 function(){ 80 console.log("Configuring CouchDB for RFT:"); 81 }, 82 function(){ 83 console.log("Checking CouchDB version"); 84 return req('get','') 85 .then(function(res){ 86 if (res.version !== "1.2.0" ) { 87 console.log("Found "+res.version+", only tested with CouchDB 1.2.0") 88 } else { 89 console.log("CouchDB 1.2.0 found"); 90 } 91 }); 92 },function(){ 93 console.log("Checking database 'rft'"); 94 return req('get','rft') 95 .then(function(){ 96 console.log("Database 'rft' found."); 97 },function(){ 98 console.log("Creating database 'rft'"); 99 return req('put','/rft'); 100 }); 101 },function(){ 102 return serializeFunctions(docs); 103 },function(docs){ 104 console.log("Putting documents in database."); 105 return asyncFor(func.keys(docs),function(docUrl){ 106 var doc = docs[docUrl]; 107 var configAction = doc.__configAction; 108 delete doc.__configAction; 109 switch (configAction) { 110 case "ignore": 111 console.log(docUrl+" ignored."); 112 case "update": 113 console.log(docUrl+" updating."); 114 return req('get',docUrl) 115 .then(function(oldDoc){ 116 lang.mixin(oldDoc,doc); 117 return req('put',docUrl,oldDoc); 118 },function(){ 119 return req('put',docUrl,doc); 120 }); 121 case "replace": 122 default: 123 console.log(docUrl+" replacing."); 124 return req('get',docUrl) 125 .then(function(oldDoc){ 126 doc['_rev'] = oldDoc['_rev']; 127 return req('put',docUrl,doc); 128 },function(){ 129 return req('put',docUrl,doc); 130 }); 131 } 132 }); 133 },function(){ 134 console.log("Done!"); 135 } 136 ]); 137 138 134 139 }); -
Dev/branches/rest-dojo-ui/client/config/docs.js
r409 r410 1 { 2 "_users/rft_admin": { 3 "__configAction": "ignore", 4 "_id": "org.couchdb.user:rft_admin", 5 "name": "rft_admin", 6 "password": "Welkom01", 7 "roles": [ "rft_admin" ], 8 "type": "user" 9 }, 10 "rft/_security": { 11 "__configAction": "ignore", 12 "admins" : { 13 "names" : [], 14 "roles" : ["rft_admin"] 1 define([],function(){ 2 return { 3 "_users/rft_admin": { 4 __configAction: "ignore", 5 _id: "org.couchdb.user:rft_admin", 6 name: "rft_admin", 7 password: "Welkom01", 8 roles: [ "rft_admin" ], 9 type: "user" 15 10 }, 16 "readers" : { 17 "names" : [], 18 "roles" : ["rft_user"] 19 } 20 }, 21 "rft/_design/default": { 22 "__configAction": "replace", 23 "_id": "_design/default", 24 "language": "javascript", 25 "validate_doc_update": "function(newDoc, oldDoc, userCtx, secObj) { if(oldDoc&&oldDoc.published){throw({forbidden:'Published documents cannot be modified.'});} if (!newDoc.type){throw({forbidden:'Documents must have a type field.'});} }", 26 "views": { 27 "by_type": { 28 "map": "function(doc){ emit(doc.type, doc); }" 11 "rft/_security": { 12 __configAction: "ignore", 13 admins: { 14 names: [], 15 roles: ["rft_admin"] 29 16 }, 30 "unpublished": { 31 "map": "function(doc){ if ( doc.type === 'Survey' && !doc.published ) { emit(doc._id, doc); } }" 17 readers: { 18 names: [], 19 roles: ["rft_user"] 20 } 21 }, 22 "rft/_design/default": { 23 __configAction: "replace", 24 _id: "_design/default", 25 language: "javascript", 26 validate_doc_update: function(newDoc, oldDoc, userCtx, secObj) { 27 if ( oldDoc && oldDoc.publicationDate ) { throw({forbidden:'Published documents cannot be modified.'}); } 28 if ( !newDoc._deleted && !newDoc.type ) { throw({forbidden:'Documents must have a type field.'}); } 32 29 }, 33 "questions": { 34 "map": "function(doc){ if ( doc.type === 'Question' ) { if ( doc.categories && doc.categories.length > 0 ) { for (var i = 0; i < doc.categories.length; i++) { emit([doc.categories[i],doc.topic || null],1); } } else { emit([null,null],1); } } }", 35 "reduce": "function(keys,values) { return sum(values); }" 30 views: { 31 by_type: { 32 map: function(doc){ 33 emit(doc.type, doc); 34 } 35 } 36 } 37 }, 38 "rft/_design/questions": { 39 __configAction: "replace", 40 _id: "_design/questions", 41 language: "javascript", 42 validate_doc_update: function(newDoc, oldDoc, userCtx, secObj) { 43 if( newDoc._deleted || newDoc.type!=='Question' ){ return; } 44 if( !newDoc.code ){ throw({forbidden:'Question must have a code field.'});} 36 45 }, 37 "topics": { 38 "map": "function(doc){ if ( doc.type === 'Question' ) { emit(doc.topic, 1); } }", 39 "reduce": "function(keys, values) { return null; }" 46 views: { 47 all: { 48 map: function(doc){ 49 if ( doc.type !== 'Question' ) { return; } 50 if ( doc.categories && doc.categories.length > 0 ) { 51 for ( var i = 0; i < doc.categories.length; i++ ) { 52 emit([doc.categories[i],doc.topic||null],1); 53 } 54 } else { 55 emit([null,null],1); 56 } 57 }, 58 reduce: function(keys,values){ return sum(values); } 59 }, 60 published: { 61 map: function(doc){ 62 if ( doc.type!=='Question' || !doc.publicationDate ) { return; } 63 if ( doc.categories && doc.categories.length > 0 ) { 64 for ( var i = 0; i < doc.categories.length; i++ ) { 65 emit([doc.categories[i],doc.topic||null],1); 66 } 67 } else { 68 emit([null,null],1); 69 } 70 }, 71 reduce: function(keys,values){ return sum(values); } 72 }, 73 all_topics: { 74 map: function(doc){ 75 if( doc.type !== 'Question' ){ return; } 76 emit(doc.topic); 77 } 78 }, 79 published_topics: { 80 map: function(doc){ 81 if ( doc.type !== 'Question' || !doc.publicationDate ) { return; } 82 emit(doc.topic); 83 } 84 } 85 } 86 }, 87 "rft/_design/surveys": { 88 __configAction: "replace", 89 _id: "_design/surveys", 90 language: "javascript", 91 views: { 92 drafts: { 93 map: function(doc){ 94 if ( doc.type !== 'Survey' || doc.publicationDate ) { return; } 95 emit(doc._id,doc); 96 } 97 }, 98 published: { 99 map: function(doc){ 100 if ( doc.type !== 'Survey' || !doc.publicationDate ) { return; } 101 emit(doc._id,doc); 102 } 103 } 40 104 } 41 105 } 42 } 43 } 106 }; 107 }); -
Dev/branches/rest-dojo-ui/client/data/.htaccess
r352 r410 1 1 RewriteEngine on 2 RewriteRule (.*) http://localhost:5984/$1 [P,QSA] 2 RewriteRule couch/(.*) http://localhost:5984/rft/$1 [P,QSA] 3 RewriteRule elastic http://localhost:9200/rft/_search [P,QSA] -
Dev/branches/rest-dojo-ui/client/index.html
r407 r410 15 15 </div> 16 16 </div> 17 <div id="toaster" data-dojo-type="rft/ui/Notifications"> 18 </div> 17 <div id="toaster" data-dojo-type="rft/ui/Notifications"></div> 19 18 </body> 20 19 </html> -
Dev/branches/rest-dojo-ui/client/rft/app/Router.js
r407 r410 4 4 'dojo/io-query', 5 5 'dojo/topic', 6 './ Page',7 ' dijit/registry'8 ],function(declare,hash,ioQuery,topic, Page,registry){6 './Content', 7 './Page' 8 ],function(declare,hash,ioQuery,topic,Content,Page){ 9 9 10 11 var Controller = declare(null,{ 10 var Router = declare(null,{ 12 11 _started: false, 13 12 _routes: null, 14 _container: null,15 13 _previousHash: null, 16 _previousContent: null,17 14 18 15 _paramMatch: /:(\w[\w\d]*)/g, 19 _paramReplace: "([^\\/ ]+)",16 _paramReplace: "([^\\/!]+)", 20 17 21 18 constructor: function() { … … 24 21 startup: function() { 25 22 if ( this._started ) { return; } 23 if ( !Content._started ) { 24 Content.startup(); 25 } 26 this._started = true; 26 27 27 28 var self = this; 28 29 this._container = registry.byId('content');30 if ( !this._container || !this._container.addChild ) {31 throw new Error("Cannot find container widget with id 'content'.");32 }33 this._started = true;34 29 35 30 if ( hash() === "" ) { … … 42 37 }, 43 38 register: function(route) { 39 if ( this._started ) { 40 console.warn('Registering routes after startup() is called is discouraged.'); 41 } 44 42 var self = this; 45 43 var callback; 46 44 if ( route.callback ) { 47 45 callback = function(params){ 48 self._setContent(route.callback(params));46 Content.set(route.callback(params)); 49 47 }; 50 48 } else if ( route.redirect ) { … … 54 52 } else if ( route.constructor ) { 55 53 callback = function(params){ 56 self._setContent( new route.constructor(params) );54 Content.set( new route.constructor(params) ); 57 55 }; 58 56 } … … 75 73 } 76 74 path = path.replace(this._paramMatch, this._paramReplace); 77 route.regexp = new RegExp('^!'+path+'(! .*)?$');75 route.regexp = new RegExp('^!'+path+'(!(.*))?$'); 78 76 return route; 79 77 }, … … 94 92 } 95 93 96 if ( result.length > numParams+1 ) {97 params.options = ioQuery.queryToObject(result[numParams ]);94 if ( result.length > numParams+1 && result[numParams+2] ) { 95 params.options = ioQuery.queryToObject(result[numParams+2]); 98 96 } 99 97 … … 126 124 return hash; 127 125 }, 128 _setContent: function(widget) {129 if ( this._previousContent ) {130 this._previousContent.destroyRecursive();131 this._previousContent = null;132 }133 widget.region = 'center';134 this._container.addChild(widget);135 this._previousContent = widget;136 },137 126 _defaultCallback: function() { 138 this._setContent(new Page({127 Content.set(new Page({ 139 128 templateString: "<div>Requested page not found. Go <a href=\"#!/\">home</a>.</div>" 140 129 })); … … 142 131 }); 143 132 144 return new Controller();133 return new Router(); 145 134 }); -
Dev/branches/rest-dojo-ui/client/rft/pages/index.js
r407 r410 1 1 define([ 2 2 'dojo/_base/declare', 3 '../app/ Controller',3 '../app/Router', 4 4 '../app/Page', 5 5 'dojo/text!./index.html' 6 ],function(declare, Controller,Page,template){6 ],function(declare,Router,Page,template){ 7 7 return declare([Page],{ 8 8 templateString: template, … … 11 11 if ( this._started ) { return; } 12 12 this.inherited(arguments); 13 this.btnContentCreate.on("click",function(){ Controller.go("/sessions"); });14 this.btnContentFacilitate.on("click",function(){ Controller.go("/run"); });15 this.btnSurveys.on("click",function(){ Controller.go("/surveys"); });16 this.btnQuestions.on("click",function(){ Controller.go("/questions"); });17 this.btnApplications.on("click",function(){ Controller.go("/applications"); });18 this.btnDashboards.on("click",function(){ Controller.go("/dashboards"); });19 this.btnResults.on("click",function(){ Controller.go("/results"); });13 this.btnContentCreate.on("click",function(){ Router.go("/sessions"); }); 14 this.btnContentFacilitate.on("click",function(){ Router.go("/run"); }); 15 this.btnSurveys.on("click",function(){ Router.go("/surveys"); }); 16 this.btnQuestions.on("click",function(){ Router.go("/questions"); }); 17 this.btnApplications.on("click",function(){ Router.go("/applications"); }); 18 this.btnDashboards.on("click",function(){ Router.go("/dashboards"); }); 19 this.btnResults.on("click",function(){ Router.go("/results"); }); 20 20 } 21 21 }); -
Dev/branches/rest-dojo-ui/client/rft/pages/question.js
r407 r410 5 5 'dojo/_base/lang', 6 6 '../store', 7 '../app/Controller', 7 '../app/Content', 8 '../app/Router', 8 9 '../app/Page', 9 10 '../ui/QuestionEditorPreview', 10 11 '../ui/QuestionEditorToolkit', 11 12 'dojo/text!./question.html' 12 ],function(declare, Deferred, event, lang, store, Cont roller, Page, QuestionEditorPreview, QuestionEditorToolkit, template){13 ],function(declare, Deferred, event, lang, store, Content, Router, Page, QuestionEditorPreview, QuestionEditorToolkit, template){ 13 14 return declare([Page], { 14 15 templateString: template, … … 43 44 store.put(this.question) 44 45 .then(function() { 45 Controller.go('/questions'); 46 Router.go('/questions'); 47 },function(err){ 48 Content.notify(err.reason,'error'); 46 49 }); 47 50 evt && event.stop( evt ); … … 49 52 }, 50 53 _onDiscard: function() { 51 Controller.go('/questions');54 Router.go('/questions'); 52 55 return true; 53 56 }, -
Dev/branches/rest-dojo-ui/client/rft/pages/questions.js
r407 r410 4 4 'dojo/_base/event', 5 5 'dojo/_base/lang', 6 '../app/Controller',7 6 '../store', 7 '../app/Content', 8 '../app/Router', 8 9 '../app/Page', 9 10 '../ui/TabbedQuestionBrowser', 10 11 'dojo/text!./questions.html' 11 ],function(declare,Deferred,event,lang, Controller,store,Page,TabbedQuestionBrowser,template) {12 ],function(declare,Deferred,event,lang,store,Content,Router,Page,TabbedQuestionBrowser,template) { 12 13 return declare([Page],{ 13 14 templateString: template, … … 19 20 'class': 'blue', 20 21 itemActions: { 21 'Edit': {22 Edit: { 22 23 callback: lang.hitch(this,"onEditQuestion"), 23 icon: 'Edit', 24 description: 'Edit question' 24 icon: 'Edit', 25 description: 'Edit question' 26 }, 27 Publish: { 28 callback: lang.hitch(this,"onPublishQuestion"), 29 icon: 'Publish', 30 description: 'Publish question' 25 31 } 26 32 } 27 33 },this.questionBrowser); 28 34 this.questionBrowser.startup(); 29 },30 _refresh: function() {31 Deferred.when(store.query('_design/default/_view/by_type',{key: 'Question'}))32 .then(lang.hitch(this,function(items){33 this._list.setItems(items);34 }));35 35 }, 36 36 onNewQuestion: function() { … … 41 41 }, 42 42 onEditQuestion: function(question) { 43 Controller.go("/question/"+question._id); 43 Router.go("/question/"+question._id); 44 }, 45 onPublishQuestion: function(question) { 46 question.publicationDate = store.timestamp(); 47 store.put(question) 48 .then(function(){ 49 Content.notify("Question puplished."); 50 },function(err){ 51 Content.notify(err.reason,'error'); 52 }); 44 53 } 45 54 }); -
Dev/branches/rest-dojo-ui/client/rft/pages/session.js
r407 r410 2 2 'dojo/_base/array', 3 3 'dojo/_base/declare', 4 'dojo/_base/Deferred', 5 'dojo/_base/event', 4 6 'dojo/_base/lang', 5 'dojo/_base/event', 6 'dojo/_base/Deferred', 7 '../app/Controller', 7 '../search', 8 8 '../store', 9 '../elastic/ElasticSearchFilteringSelect',10 '../elastic/ElasticReadStore',11 9 '../app/Page', 10 '../app/Router', 11 '../ui/ThresholdFilteringSelect', 12 12 '../ui/lists/AccountListView', 13 13 'dojo/text!./session.html' 14 ],function(array,declare, lang,event,Deferred,ElasticSearchFilteringSelect,ElasticReadStore,store,Page,Controller,AccountListView,template){14 ],function(array,declare,Deferred,event,lang,search,store,Page,Router,ThresholdFilteringSelect,AccountListView,template){ 15 15 return declare([Page],{ 16 16 templateString: template, … … 48 48 store.put(this.session) 49 49 .then(function(){ 50 Controller.go('/sessions');50 Router.go('/sessions'); 51 51 }); 52 52 event.stop(evt); … … 56 56 this.propertiesForm.reset(); 57 57 event.stop(evt); 58 Controller.go('/sessions');58 Router.go('/sessions'); 59 59 return false; 60 60 }, … … 70 70 }, 71 71 _setupAutoComplete: function() { 72 var accountStore = new ElasticReadStore({ 73 url: "http://localhost:9200/rft/_search", 74 requestMethod: "POST" 75 }); 76 this._select = new ElasticSearchFilteringSelect({ 77 store: accountStore, 72 this._select = new ThresholdFilteringSelect({ 73 store: search, 78 74 autoComplete: false, 79 75 required: false, -
Dev/branches/rest-dojo-ui/client/rft/pages/sessions.js
r407 r410 4 4 'dojo/date/stamp', 5 5 '../store', 6 '../app/ Controller',6 '../app/Router', 7 7 '../app/Page', 8 8 '../ui/ObjectBox', 9 9 'dojo/text!./sessions.html' 10 ],function(declare,lang,dateStamp,store, Controller,Page,ObjectBox,template){10 ],function(declare,lang,dateStamp,store,Router,Page,ObjectBox,template){ 11 11 return declare([Page],{ 12 12 templateString: template, … … 18 18 this.templateActions = { 19 19 "Edit": function(obj){ 20 Controller.go('/session/'+store.getIdentity(obj));20 Router.go('/session/'+store.getIdentity(obj)); 21 21 }, 22 22 "Delete": lang.hitch(this,function(obj){ … … 30 30 this.sessionActions = { 31 31 "Facilitate": function(obj){ 32 Controller.go('run',{uid:store.getIdentity(obj)});32 Router.go('run',{uid:store.getIdentity(obj)}); 33 33 }, 34 34 "Delete": lang.hitch(this,function(obj){ … … 62 62 }) 63 63 .then(lang.hitch(this,function(obj){ 64 Controller.go('/session/'+store.getIdentity(obj));64 Router.go('/session/'+store.getIdentity(obj)); 65 65 })); 66 66 }, … … 70 70 delete session[store.revProperty]; 71 71 session.type = "SessionInstance"; 72 session.publi shedDate = dateStamp.toISOString(new Date(),{zulu: true});72 session.publicationDate = store.timestamp(); 73 73 session.creator = "Igor Mayer"; 74 74 store.add(session) -
Dev/branches/rest-dojo-ui/client/rft/pages/survey.js
r407 r410 5 5 'dojo/_base/event', 6 6 'dojo/_base/lang', 7 '../app/ Controller',7 '../app/Router', 8 8 '../store', 9 9 '../app/Page', … … 11 11 '../ui/TabbedQuestionBrowser', 12 12 'dojo/text!./survey.html' 13 ],function(array,declare,Deferred,event,lang, Controller,store,Page,13 ],function(array,declare,Deferred,event,lang,Router,store,Page, 14 14 QuestionListView,TabbedQuestionBrowser,template){ 15 15 return declare([Page],{ … … 27 27 this._setupQuestionBrowser(); 28 28 this._setupListView(); 29 Deferred.when(store.get(this.surveyId)) 30 .then(lang.hitch(this,function(obj){ 31 this.survey = obj; 32 store.query(null,{keys:this.survey.questions,include_docs:true}) 33 .forEach(lang.hitch(this.questionList,'appendItem')); 34 this.refresh(); 35 })); 29 this._setupSurvey(); 36 30 } else { 37 31 throw "No valid uid or survey passed!"; … … 42 36 region: 'center', 43 37 'class': 'blue', 38 include: 'published', 44 39 selectedActions: { 45 40 "Include": { … … 59 54 this.questionBrowser.startup(); 60 55 }, 61 _includeQuestion: function(question) {62 this.questionList.insertItem(question);63 },64 56 _setupListView: function() { 65 57 this.questionList = new QuestionListView({ … … 67 59 },this.surveyListViewNode); 68 60 this.questionList.startup(); 61 }, 62 _setupSurvey: function() { 63 Deferred.when(store.get(this.surveyId)) 64 .then(lang.hitch(this,function(survey){ 65 this.survey = survey; 66 store.query(null,{keys:this.survey.questions || [], include_docs: true}) 67 .forEach(lang.hitch(this.questionList,'appendItem')); 68 this.refresh(); 69 })); 70 }, 71 _includeQuestion: function(question) { 72 this.questionList.insertItem(question); 69 73 }, 70 74 refresh: function() { … … 94 98 store.put(this.survey) 95 99 .then(function() { 96 Controller.go('/surveys');100 Router.go('/surveys'); 97 101 }); 98 102 event.stop(evt); … … 100 104 }, 101 105 _onDiscard: function(evt) { 106 Router.go('/surveys'); 102 107 }, 103 108 _onShowPreview: function() { 104 Controller.go('/viewSurvey/'+store.getIdentity(this.survey)); 109 Router.go('/viewSurvey/'+store.getIdentity(this.survey),{ 110 preview: true 111 }); 105 112 } 106 113 }); -
Dev/branches/rest-dojo-ui/client/rft/pages/surveys.html
r407 r410 1 1 <div> 2 <div data-dojo-type="dijit/layout/ContentPane" data-dojo-props="region: 'center'"> 3 <button data-dojo-type="dijit/form/Button" class="blue" data-dojo-props="disabled: true, baseClass: 'rftBlockButton', iconClass: 'rftIcon rftIconEdit'" data-dojo-attach-point="btnEdit">Edit</button> 4 <button data-dojo-type="dijit/form/Button" class="blue" data-dojo-props="baseClass: 'rftBlockButton', iconClass: 'rftIcon rftIconPlus'" data-dojo-attach-point="btnNew">New</button> 5 <div data-dojo-type="dojox/grid/DataGrid" data-dojo-props="autoWidth:true,autoHeight:true,structure:[{name:'Title',field:'title'}]" data-dojo-attach-point="grid"></div> 2 3 <div data-dojo-type="dijit/layout/ContentPane" data-dojo-props="region:'top'"> 4 <h2> 5 <span class="rftIcon rftIconSurvey"></span> 6 <span class="headerText">Surveys</span> 7 </h2> 6 8 </div> 9 10 <div data-dojo-attach-point="tabContainer" data-dojo-type="dijit/layout/TabContainer" class="blue" data-dojo-props="tabPosition:'left-h',region:'center'"> 11 12 <div data-dojo-type="dijit/layout/BorderContainer" title="Drafts" data-dojo-attach-point="draftsTab"> 13 <div data-dojo-type="dijit/layout/ContentPane" data-dojo-props="region: 'center'" data-dojo-attach-point="draftsContainer"> 14 </div> 15 <div data-dojo-type="dijit/layout/ContentPane" data-dojo-props="region: 'bottom'" style="height: 40px;"> 16 <button data-dojo-type="dijit/form/Button" class="blue" data-dojo-props="baseClass: 'rftBlockButton', iconClass: 'rftIcon rftIconNew'" data-dojo-attach-event="onClick:_onNewSurvey">New survey</button> 17 </div> 18 </div> 19 20 <div data-dojo-type="dijit/layout/BorderContainer" title="Published" data-dojo-attach-point="publishedTab"> 21 <div data-dojo-type="dijit/layout/ContentPane" data-dojo-props="region: 'center'" data-dojo-attach-point="publishedContainer"> 22 </div> 23 <div data-dojo-type="dijit/layout/ContentPane" data-dojo-props="region: 'bottom'" style="height: 40px;"> 24 </div> 25 </div> 26 27 <div data-dojo-type="dijit/layout/BorderContainer" title="Runs" data-dojo-attach-point="runsTab"> 28 <div data-dojo-type="dijit/layout/ContentPane" data-dojo-props="region: 'center'" data-dojo-attach-point="runsContainer"> 29 </div> 30 <div data-dojo-type="dijit/layout/ContentPane" data-dojo-props="region: 'bottom'" style="height: 40px;"> 31 </div> 32 </div> 33 </div> 34 7 35 </div> -
Dev/branches/rest-dojo-ui/client/rft/pages/surveys.js
r407 r410 1 1 define([ 2 'dojo/_base/array', 2 3 'dojo/_base/declare', 3 4 'dojo/_base/lang', 4 'dojo/_base/Deferred', 5 'dojo/data/ObjectStore', 6 '../auth', 5 'dojo/when', 7 6 '../store', 8 '../app/Cont roller',7 '../app/Content', 9 8 '../app/Page', 9 '../app/Router', 10 '../ui/LineWithActionsWidget', 10 11 'dojo/text!./surveys.html' 11 ],function( declare,lang,Deferred,ObjectStore,auth,store,Controller,Page,template){12 ],function(array,declare,lang,when,store,Content,Page,Router,LineWithActionsWidget,template){ 12 13 return declare([Page],{ 13 14 templateString: template, 14 selectedObject: null,15 15 startup: function() { 16 16 if ( this._started ) { return; } 17 17 this.inherited(arguments); 18 this.grid.setStore( 19 ObjectStore({objectStore: store}), 20 "_design/default/_view/by_type",{key:'Survey'}); 21 22 this.grid.on('rowclick',lang.hitch(this,function(evt){ 23 this.selectedObject = evt.grid.getItem(evt.rowIndex); 24 this.btnEdit.set('disabled',!this.selectedObject); 18 this.refresh(); 19 }, 20 _onNewSurvey: function(){ 21 when( store.add({type:'Survey'}) ) 22 .then(function(survey) { 23 Router.go('/survey/'+store.getIdentity(survey)); 24 }); 25 }, 26 _onPublishSurvey:function(survey){ 27 var self = this; 28 survey.publicationDate = store.timestamp(); 29 store.put(survey).then(function(){ 30 self.refreshDrafts(); 31 self.refreshPublished(); 32 },function(err){ 33 Content.notify(err.reason,'error'); 34 }); 35 }, 36 _onDeleteSurvey:function(survey){ 37 var self = this; 38 store.remove(store.getIdentity(survey),store.getRevision(survey)) 39 .then(function(){ 40 self.refreshDrafts(); 41 },function(err){ 42 Content.notify(err.reason,'error'); 43 }); 44 }, 45 _onEditSurvey:function(survey){ 46 Router.go('/survey/'+store.getIdentity(survey)); 47 }, 48 _onPreviewSurvey:function(survey){ 49 Router.go('/viewSurvey/'+store.getIdentity(survey),{preview:true}); 50 }, 51 _onRunSurvey:function(survey){ 52 53 }, 54 refresh: function() { 55 this.refreshDrafts(); 56 this.refreshPublished(); 57 this.refreshRuns(); 58 }, 59 refreshDrafts: function() { 60 this.draftsContainer.set('content',''); 61 when(store.query("_design/surveys/_view/drafts") 62 ,lang.hitch(this,function(surveys){ 63 this.draftsTab.set('title','Drafts ('+surveys.length+')'); 64 array.forEach(surveys,function(survey){ 65 var w = new LineWithActionsWidget({ 66 title: survey.title || '(unnamed)', 67 actions: [{ 68 callback: lang.hitch(this,'_onPublishSurvey',survey), 69 properties: { 70 label: 'Publish', 71 tooltip: 'Publish survey', 72 icon: 'Publish' 73 } 74 },{ 75 callback: lang.hitch(this,'_onPreviewSurvey',survey), 76 properties: { 77 label: 'Preview', 78 tooltip: 'Preview survey', 79 icon: 'Preview' 80 } 81 },{ 82 callback: lang.hitch(this,'_onDeleteSurvey',survey), 83 properties: { 84 label: 'Delete', 85 tooltip: 'Delete survey', 86 icon: 'Delete' 87 } 88 },{ 89 callback: lang.hitch(this,'_onEditSurvey',survey), 90 properties: { 91 label: 'Edit', 92 tooltip: 'Edit survey', 93 icon: 'Edit' 94 } 95 }] 96 }); 97 this.draftsContainer.addChild(w); 98 },this); 25 99 })); 26 27 this.grid.on('rowdblclick',lang.hitch(this,function(evt){ 28 var obj = evt.grid.getItem(evt.rowIndex); 29 Controller.go('/survey/'+store.getIdentity(obj)); 100 }, 101 refreshPublished: function() { 102 this.publishedContainer.set('content',''); 103 when(store.query("_design/surveys/_view/published") 104 ,lang.hitch(this,function(surveys){ 105 this.publishedTab.set('title','Published ('+surveys.length+')'); 106 array.forEach(surveys,function(survey){ 107 var w = new LineWithActionsWidget({ 108 title: survey.title, 109 actions:[{ 110 callback: lang.hitch(this,'_onPreviewSurvey',survey), 111 properties: { 112 label: 'Preview', 113 tooltip: 'Preview survey', 114 icon: 'Preview' 115 } 116 },{ 117 callback: lang.hitch(this,'_onRunSurvey',survey), 118 properties: { 119 label: 'Run', 120 tooltip: 'Run survey', 121 icon: 'Run' 122 } 123 }] 124 }); 125 this.publishedContainer.addChild(w); 126 },this); 30 127 })); 31 32 this.btnNew.on('click',lang.hitch(this,function(){ 33 Deferred.when( store.add({type:'Survey',creator:auth.getUser()}) ) 34 .then(function(obj) { 35 Controller.go('/survey/'+store.getIdentity(obj)); 36 }); 37 })); 38 39 this.btnEdit.on('click',lang.hitch(this,function(){ 40 if ( this.selectedObject ) { 41 Controller.go('/survey/'+store.getIdentity(this.selectedObject)); 42 } 43 128 }, 129 refreshRuns: function() { 130 this.runsContainer.set('content',''); 131 when(store.query("_design/default/_view/by_type",{key:'SurveyRun'}) 132 ,lang.hitch(this,function(surveyRuns){ 133 this.runsTab.set('title','Runs ('+surveyRuns.length+')'); 134 array.forEach(surveyRuns,function(surveyRun){ 135 var w = new LineWithActionsWidget({ 136 title: survey.title, 137 actions:[{ 138 callback: lang.hitch(this,'_onCloseRun',surveyRun), 139 properties: { 140 label: 'Close', 141 tooltip: 'Close survey', 142 icon: 'Close' 143 } 144 }] 145 }); 146 this.runsContainer.addChild(w); 147 },this); 44 148 })); 45 149 } -
Dev/branches/rest-dojo-ui/client/rft/pages/viewSurvey.html
r407 r410 16 16 </div> 17 17 18 <div data-dojo- type="dijit/layout/ContentPane" data-dojo-props="region:'bottom'">18 <div data-dojo-attach-point="buttonsPane" data-dojo-type="dijit/layout/ContentPane" data-dojo-props="region:'bottom'"> 19 19 <button data-dojo-type="dijit/form/Button" 20 20 type="submit" -
Dev/branches/rest-dojo-ui/client/rft/pages/viewSurvey.js
r407 r410 13 13 templateString: template, 14 14 survey: null, 15 surveyId: "", 16 options: null, 15 17 constructor: function(){ 16 18 this._dataMap = {}; 19 this.options = this.options || {}; 17 20 }, 18 21 startup: function() { 19 22 if ( this._started ) { return; } 20 23 this.inherited(arguments); 24 25 21 26 if ( this.surveyId ) { 22 27 Deferred.when(store.get(this.surveyId)) 23 .then(lang.hitch(this,function(obj){ 28 .then(lang.hitch(this,function(survey){ 29 if ( !survey.published ) { 30 this.options.preview = true; 31 } 32 if ( this.options.preview ) { 33 this.buttonsPane.destroyRecursive(); 34 } 35 this.titleNode.innerHTML = survey.title + 36 (this.options.preview?' [preview]':''); 24 37 var f = new ContentWidgetFactory(); 25 this.survey = obj;38 this.survey = survey; 26 39 store.query(null,{keys:this.survey.questions,include_docs:true}) 27 40 .forEach(function(question){ … … 37 50 })); 38 51 } else { 39 throw "No valid uid or survey passed!";52 throw new Error("No valid uid or survey passed!"); 40 53 } 41 54 }, 42 55 _onSubmit: function(evt) { 56 if ( this.options.preview ) { return; } 43 57 var value = this.questionsForm.get('value'); 44 58 this.questionsPane.set('content','<pre>'+JSON.stringify(value)+'</pre>'); … … 47 61 }, 48 62 _onCancel: function(evt) { 63 if ( this.options.preview ) { return; } 49 64 event.stop(evt); 50 65 return false; -
Dev/branches/rest-dojo-ui/client/rft/run.js
r407 r410 2 2 'dojo/_base/array', 3 3 'dojo/parser', 4 'rft/app/ Controller',4 'rft/app/Router', 5 5 'rft/routes', 6 6 'rft/stddeps', 7 7 'dojo/domReady!' 8 ],function(array,parser, controller,routes) {8 ],function(array,parser,router,routes) { 9 9 parser.parse(); 10 10 array.forEach(routes,function(route){ 11 controller.register(route);11 router.register(route); 12 12 }); 13 controller.startup();13 router.startup(); 14 14 }); -
Dev/branches/rest-dojo-ui/client/rft/store.js
r407 r410 1 1 define([ 2 'dojo/_base/array', 3 'dojo/_base/declare', 4 'dojo/_base/Deferred', 5 'dojo/_base/json', 6 'dojo/_base/lang', 7 'dojo/_base/xhr', 8 'dojo/store/util/QueryResults' 9 ],function(array,declare,Deferred,json,lang,xhr,QueryResults){ 2 'dojo/date/stamp', 3 './store/CouchStore' 4 ],function(stamp,CouchStore){ 10 5 11 var CouchStore = declare(null, { 12 /** dojo Store implementation for CouchDB 13 * 14 * See for details on the REST API, the wiki 15 * at http://wiki.apache.org/couchdb/HTTP_Document_API. 16 */ 17 target: "", 18 accepts: "application/json", 19 idProperty: "_id", 20 revProperty: "_rev", 21 _responseIdProperty: "id", 22 _responseRevProperty: "rev", 23 constructor: function(options){ 24 declare.safeMixin(this, options); 25 }, 26 getIdentity: function(object){ 27 return object[this.idProperty]; 28 }, 29 getRevision: function(object){ 30 return object[this.revProperty]; 31 }, 32 get: function(id){ 33 var dfd = new Deferred(); 34 xhr("GET", { 35 url: this.target + id, 36 handleAs: "json", 37 headers: { 38 Accept: this.accepts 39 } 40 }).then(function(result){ 41 if ( result.error ) { 42 dfd.reject(result.reason); 43 } else { 44 dfd.resolve(result); 45 } 46 }, function(err){ 47 dfd.reject(err); 48 }); 49 return dfd.promise; 50 }, 51 put: function(object, options){ 52 // summary: 53 // put an object in CouchDB 54 // object: Object 55 // The object to put 56 // options: Object 57 // Options object as 58 // id: String 59 // 60 options = options || {}; 61 62 var dfd = new Deferred(); 63 var id = options.id ? options.id : this.getIdentity(object); 64 var hasId = typeof id != "undefined"; 65 xhr(hasId ? "PUT" : "POST", { 66 url: hasId ? this.target + id : this.target, 67 postData: json.toJson(object), 68 handleAs: "json", 69 headers:{ 70 "Content-Type": "application/json", 71 Accept: this.accepts 72 } 73 }).then(lang.hitch(this,function(result){ 74 if ( result.error ) { 75 dfd.reject(result.reason); 76 } else { 77 object[this.idProperty] = result[this._responseIdProperty]; 78 object[this.revProperty] = result[this._responseRevProperty]; 79 dfd.resolve(object); 80 } 81 }), function(err){ 82 dfd.reject(err); 83 }); 84 return dfd.promise; 85 }, 86 add: function(object, options){ 87 return this.put(object,options); 88 }, 89 remove: function(id,rev){ 90 var dfd = new Deferred(); 91 xhr("DELETE",{ 92 url: this.target + id, 93 headers: { 94 'If-Match': rev 95 } 96 }).then(function(result){ 97 if ( result.error ) { 98 dfd.reject(result.reason); 99 } else { 100 dfd.resolve(); 101 } 102 },function(err){ 103 dfd.reject(err); 104 }); 105 return dfd.promise; 106 }, 107 query: function(query, options){ 108 // summary: 109 // query a couchdb view 110 // query: String 111 // name of a couchdb view you want to query, relative to the current database 112 // options: Object 113 // options object as 114 // start: Number 115 // Start results at this item 116 // count: Number 117 // Number of items to return 118 // sort: [{attribute:'key',descending:true|false}] 119 // CouchDB only support sorting by key, so only 'key' 120 // is allowed as attribute value. Multiple sort items 121 // are ignored. 122 // key: String|Array|Object 123 // Return only values with this key. 124 // Excludes start/endkey usage. 125 // startkey: String|Array|Object 126 // Return values starting from this key. 127 // endkey: String|Array|Object 128 // Return values with key lower than this key. 129 // include_docs: true|false 130 // Return the full documents instead of the view 131 // values. 132 // reduce: true|false 133 // Execute reduce on the view or not. Default depends 134 // on if a reduce function is defined on the view. 135 // group: true|false 136 // Should values be grouped per key or not? Default 137 // is false. 138 // group_level: Number 139 // When group = true and the key is an array, 140 // determines which elements starting from the first 141 // are used for grouping. Default is 0. 142 // get_keys: true|false 143 // Instead of returning the values or documents, 144 // return the array of keys as the result. 145 // This does not affect the forPairs function. 146 options = options || {}; 147 148 var dfd = new Deferred(); 149 var queryOpts = {}; 150 if ( !query ) { 151 query = '_all_docs'; 152 } 153 154 if (!lang.isString(query)) { 155 console.warn("Query must be a view name"); 156 } 157 158 // Standard options 159 if (options.start >= 0) { 160 queryOpts.skip = options.start; 161 } 162 if (options.count >= 0) { 163 queryOpts.limit = options.count; 164 } 165 if (options.sort) { 166 if (options.sort[0]) { 167 if (options.sort[0].attribute && options.sort[0].attribute !== "key") { 168 console.warn("Can only sort on key"); 169 } 170 if (options.sort[0].descending) { 171 queryOpts.descending = true; 172 } 173 } 174 if (options.sort.length > 1) { 175 console.warn("multiple sort fields not supported"); 176 } 177 } 178 179 // Custom options 180 if (options.key !== undefined) { 181 queryOpts.key = options.key; 182 } else if (options.keys !== undefined) { 183 queryOpts.keys = options.keys; 184 } else if (options.startkey !== undefined || options.endkey !== undefined) { 185 queryOpts.startkey = options.startkey; 186 queryOpts.endkey = options.endkey; 187 } 188 if (options.include_docs !== undefined) { 189 queryOpts.include_docs = options.include_docs; 190 } 191 if (options.reduce !== undefined) { 192 queryOpts.reduce = options.reduce; 193 } 194 if (options.group !== undefined) { 195 queryOpts.group = options.group; 196 if (options.group_level !== undefined) { 197 queryOpts.group_level = options.group_level; 198 } 199 } 200 201 for (var qp in queryOpts) { 202 queryOpts[qp] = json.toJson(queryOpts[qp]); 203 } 204 query += '?' + xhr.objectToQuery(queryOpts); 205 206 xhr("GET", { 207 url: this.target + query, 208 handleAs: "json", 209 headers: { 210 Accept: this.accepts 211 } 212 }).then(function(result){ 213 if (result.error) { 214 dfd.reject(result.reason); 215 } else { 216 var results; 217 var values = array.map(result.rows,function(result){ 218 return options.include_docs === true ? result.doc : result.value; 219 }); 220 var keys = array.map(result.rows,function(result){ 221 return result.key; 222 }); 223 if (options.get_keys === true) { 224 results = keys; 225 results.values = values; 226 } else { 227 results = values; 228 results.keys = keys; 229 } 230 dfd.resolve(results); 231 } 232 },function(err){ 233 dfd.reject(err); 234 }); 235 return CouchResults(dfd.promise); 236 } 237 }); 238 239 function CouchResults(results) { 240 results = QueryResults(results); 241 results.forPairs = function(callback,thisObject) { 242 callback = lang.hitch(thisObject,callback); 243 return Deferred.when(results,function(results) { 244 var values = results.values || results; 245 var keys = results.keys || results; 246 return array.forEach(values, function(value,index) { 247 callback(value,keys[index],index); 248 }); 249 }); 250 }; 251 return results; 252 } 253 254 return new CouchStore({target: 'data/rft/'}); 6 var store = new CouchStore({target: 'data/couch/'}); 7 store.formatDate = function(date){ 8 return stamp.toISOString(date,{zulu:true}); 9 }; 10 store.parseDate = function(dateString){ 11 return stamp.fromISOString(dateString); 12 }; 13 store.timestamp = function() { 14 return this.formatDate(new Date()); 15 }; 16 return store; 255 17 256 18 }); -
Dev/branches/rest-dojo-ui/client/rft/store/ElasticReadStore.js
r407 r410 5 5 'dojo/_base/xhr', 6 6 'dojox/data/QueryReadStore' 7 ],function(declare, json, lang, xhr, QueryReadStore) { 8 7 ],function(declare, json, lang, xhr, QueryReadStore) { 9 8 return declare(QueryReadStore, { 10 9 fetch:function(request){ 11 10 var attr = Object.keys(request.query)[0]; 12 if (request.query[attr].length == 0) {11 if (request.query[attr].length === 0) { 13 12 return 0; 14 13 } … … 51 50 } 52 51 }); 53 }) 52 }); -
Dev/branches/rest-dojo-ui/client/rft/ui/Breadcrumbs.js
r407 r410 6 6 'dojo/topic', 7 7 'dijit/_WidgetBase', 8 '../app/ Controller'9 ], function(declare, baseArray, Button, domClass, topic, _WidgetBase, Controller){8 '../app/Router' 9 ], function(declare, baseArray, Button, domClass, topic, _WidgetBase,Router){ 10 10 return declare([_WidgetBase], { 11 11 _crumbs: [], … … 61 61 iconClass: "dijitNoIcon", 62 62 onClick: lang.hitch(this, function(){ 63 Controller.go(path); // TODO: fix this call!63 Router.go(path); // TODO: fix this call! 64 64 }) 65 65 }); -
Dev/branches/rest-dojo-ui/client/rft/ui/LoginDialog.js
r408 r410 1 1 define(['dojo/_base/declare','dojo/_base/lang','dojo/_base/event','dijit/Dialog', 2 2 'dijit/_WidgetsInTemplateMixin','../auth', 'dojo/text!./templates/LoginDialog.html', 3 '../app/ Controller','dijit/form/Form','dijit/form/Button','dijit/form/TextBox'],3 '../app/Router','dijit/form/Form','dijit/form/Button','dijit/form/TextBox'], 4 4 function (declare, lang, event, Dialog, _WidgetsInTemplateMixin, auth, template, content) { 5 5 return declare([Dialog,_WidgetsInTemplateMixin], { -
Dev/branches/rest-dojo-ui/client/rft/ui/MenuBarLink.js
r407 r410 1 define(['dojo/_base/declare','dijit/MenuBarItem','../app/ Controller'],2 function(declare,MenuBarItem, Controller){1 define(['dojo/_base/declare','dijit/MenuBarItem','../app/Router'], 2 function(declare,MenuBarItem,Router){ 3 3 return declare([MenuBarItem],{ 4 4 options:{ … … 6 6 }, 7 7 onClick: function(){ 8 this.path && Controller.go(this.path);8 this.path && Router.go(this.path); 9 9 } 10 10 }); -
Dev/branches/rest-dojo-ui/client/rft/ui/MenuLink.js
r407 r410 1 define(['dojo/_base/declare','dijit/MenuItem','../app/ Controller'],2 function(declare,MenuItem, Controller){1 define(['dojo/_base/declare','dijit/MenuItem','../app/Router'], 2 function(declare,MenuItem,Router){ 3 3 return declare([MenuItem],{ 4 4 options:{ … … 6 6 }, 7 7 onClick: function(){ 8 this.path && Controller.go(this.path);8 this.path && Router.go(this.path); 9 9 } 10 10 }); -
Dev/branches/rest-dojo-ui/client/rft/ui/Notifications.js
r407 r410 1 define(['dojo/_base/declare','dojo/_base/lang','dojo/_base/connect','dojox/widget/Toaster'], 2 function(declare,lang,connect,Toaster){ 3 return declare([Toaster],{ 4 positionDirection: "br-up", 5 duration: 1000, 6 postCreate: function() { 7 this.inherited(arguments); 8 this.handle = connect.subscribe('/rft/notify',lang.hitch(this,function(notification){ 9 this.setContent(notification.text,notification.type || 'message'); 10 })); 11 }, 12 destroy: function() { 13 connect.unsubscribe(this.handle); 14 this.inherited(arguments); 15 } 16 }); 1 define(['dojo/_base/declare','dojo/_base/lang','dojox/widget/Toaster'], 2 function(declare,lang,Toaster){ 3 return declare([Toaster],{ 4 positionDirection: "br-up", 5 duration: 1000 17 6 }); 7 }); -
Dev/branches/rest-dojo-ui/client/rft/ui/QuestionEditorToolkit.js
r407 r410 129 129 _setupCategories: function() { 130 130 this._categoryStore = new Memory({data: [] }); 131 store.query("_design/ default/_view/questions", {reduce:true, group:false, group_level:1})131 store.query("_design/questions/_view/all", {reduce:true, group:false, group_level:1}) 132 132 .forPairs(lang.hitch(this, function(value, key) { 133 133 this._categoryStore.put({ id: key[0] }); … … 143 143 _setupTopic: function(topic) { 144 144 this._topicStore = new Memory( {data: [] }); 145 store.query("_design/ default/_view/topics", {reduce:true, group:true})145 store.query("_design/questions/_view/all_topics", {reduce:true, group:true}) 146 146 .forPairs(lang.hitch(this, function(value, key) { 147 147 this._topicStore.put({ id: key }); -
Dev/branches/rest-dojo-ui/client/rft/ui/Selector.js
r407 r410 149 149 }, 150 150 151 addItem: function(item ) {151 addItem: function(item,displayTitle) { 152 152 var actions = {}; 153 153 var action; … … 156 156 action = this.itemActions[actionName]; 157 157 actions[actionName] = { 158 callback: function(){ 159 action.callback && action.callback(item); 160 }, 158 callback: action.callback && lang.partial(action.callback,item), 161 159 properties: { 162 160 blockButton: false, … … 165 163 tooltip: action.description 166 164 } 167 } 165 }; 168 166 } 169 167 } 170 168 var w = new LineWithActionsWidget({ 171 title: item.title,169 title: displayTitle || item.title, 172 170 actions: actions 173 171 }).placeAt(this.optionsNode); -
Dev/branches/rest-dojo-ui/client/rft/ui/TabbedQuestionBrowser.js
r407 r410 9 9 'rft/ui/Selector', 10 10 'dojo/domReady!' 11 ], 12 function(declare,lang,win,ContentPane,TabContainer,Standby,store,Selector){13 return declare([TabContainer],{14 tabPosition: 'left-h',11 ],function(declare,lang,win,ContentPane,TabContainer,Standby,store,Selector){ 12 return declare([TabContainer],{ 13 tabPosition: 'left-h', 14 include: 'all', 15 15 16 17 16 selectedActions: null, 17 itemActions: null, 18 18 19 _dataMap: null, 20 _busyCount: 0, 21 constructor: function(){ 22 this.inherited(arguments); 23 this._dataMap = {}; 24 }, 25 startup: function() { 26 if ( this._started ){ return; } 27 this.inherited(arguments); 28 this._busyWidget = new Standby({ 29 target: this.domNode, 30 duration: 200 31 }).placeAt(win.body()); 32 this._busyWidget.startup(); 33 this.watch("selectedChildWidget",lang.hitch(this,function(name,oldTab,newTab){ 34 this._fillCategoryTab(newTab.__category); 19 _dataMap: null, 20 _busyCount: 0, 21 constructor: function(){ 22 this.inherited(arguments); 23 this._dataMap = {}; 24 }, 25 postCreate: function() { 26 this.inherited(arguments); 27 this._query = '_design/questions/_view/'+this.include; 28 }, 29 startup: function() { 30 if ( this._started ){ return; } 31 this.inherited(arguments); 32 this._busyWidget = new Standby({ 33 target: this.domNode, 34 duration: 200 35 }).placeAt(win.body()); 36 this._busyWidget.startup(); 37 this.watch("selectedChildWidget",lang.hitch(this,function(name,oldTab,newTab){ 38 this._fillCategoryTab(newTab.__category); 39 })); 40 store.query(this._query, {reduce:true,group:true,group_level:1}) 41 .forPairs(lang.hitch(this,function(value,key){ 42 this._createCategoryTab(key[0],value); 43 })); 44 }, 45 _createCategoryTab: function(category,count) { 46 if (this._dataMap[category] === undefined) { 47 var categoryTab = new ContentPane({ 48 __category: category, 49 title: (category || '[No category]')+" ("+count+")" 50 }); 51 categoryTab.startup(); 52 this._dataMap[category] = { 53 _widget: categoryTab 54 }; 55 this.addChild(categoryTab); 56 } 57 }, 58 _fillCategoryTab: function(category) { 59 var categoryMap = this._dataMap[category]; 60 if (!categoryMap._filled) { 61 this._busy(); 62 categoryMap._filled = true; 63 store.query(this._query, {reduce:true,group:true,group_level:2,startkey:[category],endkey:[category,{}]}) 64 .forPairs(lang.hitch(this,function(value,key){ 65 this._createTopicSelector(key[1],category,value); 66 })).then(lang.hitch(this,function(){ 67 this._done(); 35 68 })); 36 store.query('_design/default/_view/questions', {reduce:true,group:true,group_level:1}) 37 .forPairs(lang.hitch(this,function(value,key){ 38 this._createCategoryTab(key[0],value); 69 } 70 }, 71 _createTopicSelector: function(topic,category,count){ 72 var categoryMap = this._dataMap[category]; 73 if (categoryMap[topic] === undefined) { 74 var w = new Selector({ 75 __category: category, 76 __topic: topic, 77 title: (topic || '[No topic]')+" ("+count+")", 78 selectedActions: this.selectedActions, 79 itemActions: this.itemActions 80 }).placeAt(categoryMap._widget.containerNode); 81 w.startup(); 82 categoryMap[topic] = { 83 _widget: w 84 }; 85 this._fillTopicSelector(topic,category); 86 } 87 }, 88 _fillTopicSelector: function(topic,category) { 89 var categoryMap = this._dataMap[category]; 90 var topicMap = categoryMap[topic]; 91 if (!topicMap._filled) { 92 topicMap._filled = true; 93 this._busy(); 94 store.query(this._query, {reduce:false,include_docs:true,key:[category,topic]}) 95 .forEach(lang.hitch(this,function(value){ 96 var title; 97 if ( this.include === 'all' ) { 98 title = value.title+(value.publicationDate?' (published on '+value.publicationDate+')':' (unpublished)'); 99 } 100 topicMap._widget.addItem(value,title); 101 })).then(lang.hitch(this,function(){ 102 this._done(); 39 103 })); 40 }, 41 _createCategoryTab: function(category,count) { 42 if (this._dataMap[category] === undefined) { 43 var categoryTab = new ContentPane({ 44 __category: category, 45 title: (category || '[No category]')+" ("+count+")" 46 }); 47 categoryTab.startup(); 48 this._dataMap[category] = { 49 _widget: categoryTab 50 }; 51 this.addChild(categoryTab); 104 } 105 }, 106 _busy: function() { 107 if ( this._busyCount === 0 ) { 108 this._busyWidget.show(); 109 } 110 this._busyCount++; 111 }, 112 _done: function() { 113 if ( this._busyCount > 0 ) { 114 this._busyCount--; 115 if ( this._busyCount === 0 ) { 116 this._busyWidget.hide(); 52 117 } 53 }, 54 _fillCategoryTab: function(category) { 55 var categoryMap = this._dataMap[category]; 56 if (!categoryMap._filled) { 57 this._busy(); 58 categoryMap._filled = true; 59 store.query('_design/default/_view/questions', {reduce:true,group:true,group_level:2,startkey:[category],endkey:[category,{}]}) 60 .forPairs(lang.hitch(this,function(value,key){ 61 this._createTopicSelector(key[1],category,value); 62 })).then(lang.hitch(this,function(){ 63 this._done(); 64 })); 65 } 66 }, 67 _createTopicSelector: function(topic,category,count){ 68 var categoryMap = this._dataMap[category]; 69 if (categoryMap[topic] === undefined) { 70 var w = new Selector({ 71 __category: category, 72 __topic: topic, 73 title: (topic || '[No topic]')+" ("+count+")", 74 selectedActions: this.selectedActions, 75 itemActions: this.itemActions 76 }).placeAt(categoryMap._widget.containerNode); 77 w.startup(); 78 categoryMap[topic] = { 79 _widget: w 80 }; 81 this._fillTopicSelector(topic,category); 82 } 83 }, 84 _fillTopicSelector: function(topic,category) { 85 var categoryMap = this._dataMap[category]; 86 var topicMap = categoryMap[topic]; 87 if (!topicMap._filled) { 88 topicMap._filled = true; 89 this._busy(); 90 store.query('_design/default/_view/questions', {reduce:false,include_docs:true,key:[category,topic]}) 91 .forEach(lang.hitch(this,function(value){ 92 topicMap._widget.addItem(value); 93 })).then(lang.hitch(this,function(){ 94 this._done(); 95 })); 96 } 97 }, 98 _busy: function() { 99 if ( this._busyCount === 0 ) { 100 this._busyWidget.show(); 101 } 102 this._busyCount++; 103 }, 104 _done: function() { 105 if ( this._busyCount > 0 ) { 106 this._busyCount--; 107 if ( this._busyCount === 0 ) { 108 this._busyWidget.hide(); 109 } 110 } else { 111 console.warn('_done() was called more times than _busy().'); 112 } 113 }, 114 destroy: function() { 115 this._busyWidget.destroyRecursive(); 116 this.inherited(arguments); 118 } else { 119 console.warn('_done() was called more times than _busy().'); 117 120 } 118 }); 121 }, 122 destroy: function() { 123 this._busyWidget.destroyRecursive(); 124 this.inherited(arguments); 125 } 119 126 }); 127 }); -
Dev/branches/rest-dojo-ui/client/rft/ui/ThresholdFilteringSelect.js
r407 r410 16 16 } 17 17 }); 18 }) 18 }); -
Dev/branches/rest-dojo-ui/client/rft/view.js
r407 r410 1 1 require([ 2 'dojo/hash', 2 3 'dojo/parser', 3 'rft/stddeps', 4 'dojo/domReady!' 5 ],function(parser) { 4 'rft/app/Content', 5 'rft/app/Page', 6 'rft/pages/viewSurvey', 7 'dojo/domReady!', 8 'rft/stddeps' 9 ],function(hash,parser,Content,Page,viewSurvey) { 6 10 parser.parse(); 11 Content.startup(); 12 13 var match = /^!\/(\w+)$/g.exec(hash()); 14 if ( !match ) { 15 Content.set(new Page({ 16 templateString: "<div>Something is wrong with the URL, don't know what survey to show you. Sorry.</div>" 17 })); 18 return; 19 } 20 var surveyId = match[1]; 21 7 22 // read options from hash/url 23 // 8 24 // authenticate 9 // set content 10 // go for it 25 26 Content.set(new viewSurvey({ 27 surveyId: surveyId 28 })); 11 29 }); -
Dev/branches/rest-dojo-ui/client/view.html
r407 r410 9 9 <script type="text/javascript" src="dojo/dojo.js" data-dojo-config="async: true, parseOnLoad: false, isDebug: true"></script> 10 10 <script type="text/javascript" src="rft/view.js"></script> 11 <div class="page" data-dojo-type="dijit/layout/BorderContainer" data-dojo-props="region:'center'" style="width: 100%; height: 100%;">11 <div id="content" class="page" data-dojo-type="dijit/layout/BorderContainer" data-dojo-props="region:'center'" style="width: 100%; height: 100%;"> 12 12 <div class="topbar" data-dojo-type="dijit/layout/ContentPane" data-dojo-props="region:'top'"> 13 13 <h1>Survey</h1> 14 </div>15 <div id="content" class="content" data-dojo-type="dijit/layout/ContentPane" data-dojo-props="region:'center'">16 14 </div> 17 15 </div> -
Dev/branches/rest-dojo-ui/docs/jsonformat.txt
r384 r410 2 2 ======== 3 3 { 4 type: 'SessionTemplate' ,5 title: '' ,6 description: '' ,7 plannedDate: '' ,/* ISO UTC datetime */4 type: 'SessionTemplate' 5 title: '' 6 description: '' 7 plannedDate: '' /* ISO UTC datetime */ 8 8 accounts: [ /* Account ids */ ] 9 9 } 10 10 11 11 { 12 type: 'SessionInstance' ,13 title: '' ,14 description: '' ,15 publishedDate: '' ,/* ISO UTC datetime */12 type: 'SessionInstance' 13 title: '' 14 description: '' 15 publishedDate: '' /* ISO UTC datetime */ 16 16 accounts: [ /* Account ids */ ] 17 17 } … … 21 21 { 22 22 type: 'Survey' 23 title: '' ,24 description: '' ,23 title: '' 24 description: '' 25 25 questions: [ /* Question ids */ ] 26 publishedDate: '' 27 } 28 29 { 30 type: 'SurveyInstance' 31 surveyId: '' // String 32 publishedDate: '' // ISO datetime 33 startDate: '' // can fill in after 34 endDate: '' // can fill in until 26 35 } 27 36 … … 30 39 { 31 40 type: 'Question' 32 title: '' ,33 description: '' ,34 topic: '' ,35 categories: [] ,41 title: '' 42 description: '' 43 topic: '' 44 categories: [] 36 45 content: [{ type:'contentTypeId', /* custom content element fields */ } /* and more ... */] 37 46 }
Note: See TracChangeset
for help on using the changeset viewer.