Changeset 303 for Dev/branches/rest-dojo-ui
- Timestamp:
- 03/04/12 15:48:42 (13 years ago)
- Location:
- Dev/branches/rest-dojo-ui
- Files:
-
- 2 added
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
Dev/branches/rest-dojo-ui/client/rft/pages/questions.js
r288 r303 1 1 define(['dojo/_base/declare','dojo/_base/lang','dojo/_base/array','dojo/_base/event', 2 'dojo/_base/Deferred','dojo/dom-construct',' dojo/store/JsonRest','dijit/layout/ContentPane','dijit/TitlePane',2 'dojo/_base/Deferred','dojo/dom-construct','rft/store','dijit/TitlePane', 3 3 'rft/ui/_Page','rft/ui/LineWithActionsWidget'], 4 function(declare,lang,array,event,Deferred,domConstruct, JsonRest,ContentPane,TitlePane,_Page,LineWithActionsWidget) {4 function(declare,lang,array,event,Deferred,domConstruct,store,TitlePane,_Page,LineWithActionsWidget) { 5 5 return declare('rft.pages.questions',[_Page],{ 6 6 constructor: function() { … … 9 9 }, 10 10 onVisit: function() { 11 this._store = new JsonRest({ 12 target:"../server/api.php/data/Question/", 13 idProperty: 'uid' 14 }); 11 this._store = store.getStore('Question'); 15 12 this._refresh(true); 16 13 }, 17 14 _refresh: function(initial) { 18 Deferred.when( this._store.query() ).then(lang.hitch(this,function(results){ 15 Deferred.when( this._store.query() ) 16 .then(lang.hitch(this,function(results){ 19 17 array.forEach(results,lang.hitch(this,'_addQuestion')); 20 18 initial && this.accordion.selectChild(true); … … 22 20 }, 23 21 _addQuestion: function(q) { 24 var uid = q. uid;22 var uid = q.getUid(); 25 23 var question = this.questions[uid]; 26 24 if ( !question ) { … … 54 52 var placeNode = this.accordion.domNode; 55 53 var placePos = 'last'; 56 array.some(widgets,lang.hitch(this,function(widget ,idx) {54 array.some(widgets,lang.hitch(this,function(widget) { 57 55 if ( widget.title == category ) { 58 56 containerWidget = widget; -
Dev/branches/rest-dojo-ui/client/rft/pages/sessions.html
r274 r303 24 24 var submitHandler = lang.hitch(that,function(evt){ 25 25 var newObj = this.form.get('value'); 26 debugger;27 26 // mixin newObj in obj. 28 27 // store.put(newObj); -
Dev/branches/rest-dojo-ui/client/rft/pages/survey.html
r292 r303 1 1 <div data-dojo-type="rft.pages.survey"> 2 2 <h1 data-rft-attach-point="header">(default)</h1> 3 <div>Created by <span data-rft-attach-point="creator"></span><div> 3 4 <form data-dojo-type="dijit.form.Form" data-rft-attach-point="form" data-rft-attach-event="onSubmit:onSave"> 4 5 <div style="display: block; clear: both;"> -
Dev/branches/rest-dojo-ui/client/rft/pages/survey.js
r292 r303 1 define(['dojo/_base/declare','dojo/_base/lang','dojo/_base/event','dojo/_base/Deferred',' dojo/store/JsonRest','rft/ui/_Page'],2 function(declare,lang,event,Deferred, JsonRest,_Page){1 define(['dojo/_base/declare','dojo/_base/lang','dojo/_base/event','dojo/_base/Deferred','rft/store','rft/ui/_Page'], 2 function(declare,lang,event,Deferred,store,_Page){ 3 3 return declare('rft.pages.survey',[_Page],{ 4 4 object: null, 5 5 postCreate: function() { 6 6 this.inherited(arguments); 7 this._store = new JsonRest({ 8 target:"../server/api.php/data/Survey/", 9 idProperty: 'uid' 10 }); 7 this._store = store.getStore('Survey'); 11 8 }, 12 9 onVisit: function() { … … 16 13 this.object = obj; 17 14 this.setFields(obj); 15 return Deferred.when( obj.creator && store.dereference(obj.creator) ); 16 })) 17 .then(lang.hitch(this,function(obj){ 18 this.creator.innerHTML = (obj && obj.email) || 'unknown'; 18 19 })); 19 20 } else { -
Dev/branches/rest-dojo-ui/client/rft/pages/surveys.js
r292 r303 1 define(['dojo/_base/declare','dojo/_base/lang','dojo/ store/JsonRest','dojo/data/ObjectStore','rft/content','rft/ui/_Page'],2 function(declare,lang, JsonRest,ObjectStore,content,_Page){1 define(['dojo/_base/declare','dojo/_base/lang','dojo/_base/Deferred','dojo/data/ObjectStore','rft/auth','rft/store','rft/content','rft/ui/_Page'], 2 function(declare,lang,Deferred,ObjectStore,auth,store,content,_Page){ 3 3 return declare('rft.pages.surveys',[_Page],{ 4 4 selectedObject: null, 5 5 postCreate: function() { 6 this._store = new JsonRest({ 7 target:"../server/api.php/data/Survey/", 8 idProperty: 'uid' 9 }); 6 this._store = store.getStore('Survey'); 10 7 }, 11 8 onVisit: function() { … … 14 11 this.grid.on('rowclick',lang.hitch(this,function(evt){ 15 12 this.selectedObject = evt.grid.getItem(evt.rowIndex); 16 this.btnEdit.set('disabled',! !this.selectedObject);13 this.btnEdit.set('disabled',!this.selectedObject); 17 14 })); 18 15 19 16 this.grid.on('rowdblclick',lang.hitch(this,function(evt){ 20 17 var obj = evt.grid.getItem(evt.rowIndex); 21 content.goTo('/survey',{uid:obj. uid});18 content.goTo('/survey',{uid:obj.getUid()}); 22 19 })); 23 20 24 21 this.btnNew.on('click',lang.hitch(this,function(){ 25 this._store.add({},function(obj) { 26 content.goTo('/survey',{uid:this.selectedObject.uid}); 22 Deferred.when( this._store.add({'creator':auth.getUser()}) ) 23 .then(function(obj) { 24 content.goTo('/survey',{uid:obj.getUid()}); 27 25 }); 28 26 })); … … 30 28 this.btnEdit.on('click',lang.hitch(this,function(){ 31 29 if ( this.selectedObject ) { 32 content.goTo('/survey',{uid:this.selectedObject. uid});30 content.goTo('/survey',{uid:this.selectedObject.getUid()}); 33 31 } 34 32 -
Dev/branches/rest-dojo-ui/client/rft/ui/QuestionWidget.js
r288 r303 1 define(['dojo/_base/declare','dojo/ dom-construct','dijit/_WidgetBase',1 define(['dojo/_base/declare','dojo/_base/lang','dojo/dom-construct','dijit/_WidgetBase', 2 2 'dijit/_TemplatedMixin','dijit/_WidgetsInTemplateMixin', 3 3 'dojo/text!./templates/QuestionWidget.html','dijit/form/TextBox', 4 4 'dijit/form/Textarea','./MultipleChoiceWidget'], 5 function(declare, domConstruct,_WidgetBase,_TemplatedMixin,_WidgetsInTemplateMixin,templateString,TextBox,Textarea,MultipleChoiceWidget){5 function(declare,lang,domConstruct,_WidgetBase,_TemplatedMixin,_WidgetsInTemplateMixin,templateString,TextBox,Textarea,MultipleChoiceWidget){ 6 6 return declare('rft.ui.QuestionWidget',[_WidgetBase,_TemplatedMixin,_WidgetsInTemplateMixin],{ 7 7 templateString: templateString, 8 8 mode: 'view', // view || edit 9 9 name: '', 10 value: null, 10 11 _type: null, 11 12 _widgetCache: null, 12 13 constructor: function() { 13 14 this.inherited(arguments); 15 this.value = {}; 14 16 this._widgetCache = {}; 15 17 }, 16 18 postCreate: function() { 19 this._resetValue = this.value; 17 20 this.typeSelector.set('disabled', this.mode == 'edit'); 18 21 }, 19 22 _setValueAttr: function(value) { 20 value.type && this._onTypeChange(value.type); 23 this.value = value; 24 this._onTypeChange(value.type || 'string'); 21 25 this.ourForm.set('value',value); 22 26 }, 23 27 _getValueAttr: function() { 24 return this.ourForm.get('value'); 28 var value = this.ourForm.get('value'); 29 lang.mixin(this.value,value); 30 return this._question; 25 31 }, 26 32 _onTypeChange: function(type) { … … 60 66 } 61 67 return widget; 68 }, 69 reset: function() { 70 this.ourForm.reset(); 71 this._setValueAttr(this._resetValue); 62 72 } 63 73 }); -
Dev/branches/rest-dojo-ui/client/rft/ui/templates/QuestionWidget.html
r288 r303 2 2 <form data-dojo-type="dijit.form.Form" data-dojo-attach-point="ourForm"> 3 3 <fieldset> 4 <input data-dojo-type="dijit.form.TextBox" name="uid" type="text" class="dijitHidden" />5 4 <label for="code" class="loginLabel">Code</label> 6 5 <input data-dojo-type="dijit.form.TextBox" name="code" type="text" class="loginInput" /> -
Dev/branches/rest-dojo-ui/server/api.php
r292 r303 4 4 ini_set('display_errors', True); 5 5 6 define("RDFAPI_INCLUDE_DIR", "rdfapi/"); 6 7 require_once 'tonic/lib/tonic.php'; 8 require_once 'classes/Model.php'; 7 9 require_once 'classes/master.php'; 8 10 … … 13 15 14 16 function set_session_cookie($response, $user) { 15 $response->addHeader('Set-Cookie', 'rft_uid=' . $user-> uid. '; Max-Age: 3600; Path=' . $response->request->baseUri);17 $response->addHeader('Set-Cookie', 'rft_uid=' . $user->getUid() . '; Max-Age: 3600; Path=' . $response->request->baseUri); 16 18 } 17 19 … … 87 89 class DataResource extends Resource { 88 90 89 function getTypeAndUid($request) {91 private function getTypeAndUid($request) { 90 92 $uri = get_clean_uri($request); 91 93 $path = explode('/', $uri); … … 155 157 $object->$key = $val; 156 158 } 157 if (isset($object->creator)) { 158 $object->creator = $user; 159 } 160 if (!$object->save()) { 161 throw new ResponseException("Save failed", Response::INTERNALSERVERERROR); 162 } 159 $object->save(); 163 160 164 161 $response->body = $object; -
Dev/branches/rest-dojo-ui/server/classes/Auth.php
r274 r303 7 7 public static function register($email, $password) { 8 8 $user_results = User::get(array("email" => $email)); 9 if ( !empty($user_results)) {9 if (!empty($user_results)) { 10 10 throw new Exception("User with email $email already exists."); 11 11 } 12 12 $salt = rand(); 13 $user = new User(null,$email,sha1($password.$salt),$salt); 13 $user = new User(null, array( 14 'email' => $email, 15 'passwordHash' => sha1($password . $salt), 16 'passwordSalt' => $salt)); 14 17 $user->save(); 15 18 return $user; 16 19 } 17 20 18 21 public static function login($email, $password) { 19 22 $user_results = User::get(array("email" => $email)); … … 22 25 } 23 26 $user = $user_results[0]; 24 if (sha1($password .$user->passwordSalt) != $user->passwordHash) {27 if (sha1($password . $user->passwordSalt) != $user->passwordHash) { 25 28 throw new Exception("Wrong password."); 26 29 } … … 35 38 return $user_results[0]; 36 39 } 37 40 38 41 } 39 42 -
Dev/branches/rest-dojo-ui/server/classes/Marshaller.php
r274 r303 4 4 5 5 const OBJ_TYPE = '__objectType'; 6 const OBJ_UID = '__objectUid'; 7 const REF_TYPE = '__referenceType'; 8 const REF_UID = '__referenceUid'; 6 9 7 10 private static function isWrappedObject($obj) { … … 9 12 } 10 13 14 private static function isWrappedReference($obj) { 15 return isset($obj[self::REF_TYPE]); 16 } 17 11 18 public static function marshall($obj) { 12 19 switch (gettype($obj)) { 13 20 case 'array': 14 return array_map(array('Marshaller', 'marshall'), $obj);21 return array_map(array('Marshaller', 'marshall'), $obj); 15 22 case 'object': 16 23 return static::wrapObject($obj); … … 24 31 if ($objectType == 'DateTime') { 25 32 return array(self::OBJ_TYPE => 'DateTime', 'timestamp' => $obj->getTimestamp()); 33 } else if ($obj instanceof RdfObject) { 34 $array = array( 35 self::OBJ_TYPE => $obj->getType(), 36 self::OBJ_UID => $obj->getUid() 37 ); 38 foreach ($obj as $prop => $val) { 39 $array[$prop] = static::marshall($val); 40 } 41 return $array; 42 } else if ($obj instanceof RdfPointer) { 43 return array( 44 self::REF_TYPE => $obj->getType(), 45 self::REF_UID => $obj->getUid() 46 ); 26 47 } else { 27 $newObj = static::marshall((array) $obj); 28 $newObj[self::OBJ_TYPE] = get_class($obj); 29 return $newObj; 48 return static::marshall((array) $obj); 30 49 } 31 50 } … … 38 57 if (static::isWrappedObject($obj)) { 39 58 return static::unwrapObject($obj); 59 } else if (static::isWrappedReference($obj)) { 60 return static::unwrapReference($obj); 40 61 } else { 41 return array_map(array('Marshaller', 'unmarshall'), $obj);62 return array_map(array('Marshaller', 'unmarshall'), $obj); 42 63 } 43 64 default: … … 47 68 48 69 private static function unwrapObject($obj) { 49 $objectType = $obj[self::OBJ_TYPE]; 50 unset($obj[self::OBJ_TYPE]); 70 if (isset($obj[self::OBJ_TYPE])) { 71 $objectType = $obj[self::OBJ_TYPE]; 72 unset($obj[self::OBJ_TYPE]); 73 } 74 if (isset($obj[self::OBJ_UID])) { 75 $objectUid = $obj[self::OBJ_UID]; 76 unset($obj[self::OBJ_UID]); 77 } 51 78 if ($objectType == 'DateTime') { 52 79 $date = new DateTime(); 53 80 $date->setTimestamp($obj['timestamp']); 54 81 return $date; 55 } else if (is_subclass_of($objectType, 'ResearchToolObjectInterface')) { 56 return $objectType::create((object)static::unmarshall($obj)); 82 } else if (is_subclass_of($objectType, 'RdfObject')) { 83 $rdfObject = new $objectType($objectUid); 84 foreach ($obj as $prop => $val) { 85 $rdfObject->$prop = static::unmarshall($val); 86 } 87 return $rdfObject; 57 88 } else { 58 89 return $obj; … … 60 91 } 61 92 93 private static function unwrapReference($ref) { 94 $refType = $ref[self::REF_TYPE]; 95 $refUid = $ref[self::REF_UID]; 96 return new RdfPointer(RdfObject::typeAndUidToResourceUri($refType, $refUid)); 97 } 98 62 99 } 63 100 -
Dev/branches/rest-dojo-ui/server/classes/master.php
r256 r303 8 8 * @author fpvanagthoven 9 9 */ 10 // Determine our absolute document root11 define('DOC_ROOT', realpath(dirname(__FILE__) . '/../'));12 10 13 11 function __autoload($class_name) { 14 12 if (file_exists('classes/' . $class_name . '.php')) 15 require 'classes/' . $class_name . '.php'; 16 else if (file_exists('classes/models/' . $class_name . '.php')) 17 require 'classes/models/' . $class_name . '.php'; 18 else if (file_exists('classes/widgets/' . $class_name . '.php')) 19 require 'classes/widgets/' . $class_name . '.php'; 20 else if (file_exists('classes/styles/' . $class_name . '.php')) 21 require 'classes/styles/' . $class_name . '.php'; 13 require_once 'classes/' . $class_name . '.php'; 22 14 } 23 15 -
Dev/branches/rest-dojo-ui/server/rdfapi/syntax/RdfSerializer.php
r256 r303 196 196 } 197 197 // check if model is empty 198 if ($model->size() == 0) return "<". $this->rdf_qname_prefix . RDF_RDF ." xmlns:rdf='".RDF_NAMESPACE_URI."' />"; 198 if ($model->size() == 0) { 199 $elementStr = "<". $this->rdf_qname_prefix . RDF_RDF ." xmlns:rdf='".RDF_NAMESPACE_URI."' />"; 200 return $elementStr; 201 } 199 202 200 203 foreach($nsps as $ns => $pre){
Note: See TracChangeset
for help on using the changeset viewer.