incubator-isis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From danhayw...@apache.org
Subject svn commit: r1233258 - in /incubator/isis/trunk/examples/onlinedemo/webapp/src/main/webapp/mobile: app.js generic.js index.html util.js
Date Thu, 19 Jan 2012 09:08:20 GMT
Author: danhaywood
Date: Thu Jan 19 09:08:19 2012
New Revision: 1233258

URL: http://svn.apache.org/viewvc?rev=1233258&view=rev
Log:
ISIS-170: more on the onlinedemo jqmobile app

Modified:
    incubator/isis/trunk/examples/onlinedemo/webapp/src/main/webapp/mobile/app.js
    incubator/isis/trunk/examples/onlinedemo/webapp/src/main/webapp/mobile/generic.js
    incubator/isis/trunk/examples/onlinedemo/webapp/src/main/webapp/mobile/index.html
    incubator/isis/trunk/examples/onlinedemo/webapp/src/main/webapp/mobile/util.js

Modified: incubator/isis/trunk/examples/onlinedemo/webapp/src/main/webapp/mobile/app.js
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/examples/onlinedemo/webapp/src/main/webapp/mobile/app.js?rev=1233258&r1=1233257&r2=1233258&view=diff
==============================================================================
--- incubator/isis/trunk/examples/onlinedemo/webapp/src/main/webapp/mobile/app.js (original)
+++ incubator/isis/trunk/examples/onlinedemo/webapp/src/main/webapp/mobile/app.js Thu Jan
19 09:08:19 2012
@@ -1,39 +1,12 @@
-renderTasks = function(list, title) {
-  var items = $.map(list, function(value, i) {
-    return {
-      "hrefUrlEncoded" : urlencode(value.href),
-      "title" : value.title,
-      "href" : value.href
-    }
-  });
-
-  var page = $("#home");
-
-  var header = page.children(":jqmData(role=header)");
-  var content = page.children(":jqmData(role=content)");
-
-  header.find("h1").html(title);
-
-  var div = page.find("ul.tasks");
-  var templateDiv = page.find(".tmpl");
-  
-  applyTemplateDiv(items, div, templateDiv);
-  page.page();
-
-  div.listview("refresh");
-  
-  return page;
-}
-
-todaysTasksPage = function() {
-  $.ajax({
-    url : "/services/toDoItems/actions/toDosForToday/invoke",
-    dataType : 'json',
-    success : function(json, str, xhr) {
-      renderTasks(json.result.value, "Today's Tasks")
-    }
-  });
-};
+//cloneGenericView = function(pageBaseId) {
+//  cloneAndInsertPage(pageBaseId, pageBaseId + "-template")
+//}
+//
+//cloneGenericViews = function() {
+//  cloneGenericView("genericDomainObjectView")
+//  cloneGenericView("genericObjectCollectionView")
+//  cloneGenericView("genericListView")
+//}
 
 
 $(function() {
@@ -50,6 +23,17 @@ $(function() {
     });
   });
 
-
   $(document).bind("pagebeforechange", submitRenderAndNavigate);
+
+  //cloneGenericViews();
+  
+  // if user manually refreshes page for domain object, then re-retrieve
+  var locationHref = location.href;
+  if(locationHref.indexOf("genericDomainObjectView") != -1) {
+    var urlHref = extract(locationHref);
+    submitAndRender(urlHref, "pop");
+  } else {
+    $.mobile.changePage($("#home"))
+  }
+  
 });

Modified: incubator/isis/trunk/examples/onlinedemo/webapp/src/main/webapp/mobile/generic.js
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/examples/onlinedemo/webapp/src/main/webapp/mobile/generic.js?rev=1233258&r1=1233257&r2=1233258&view=diff
==============================================================================
--- incubator/isis/trunk/examples/onlinedemo/webapp/src/main/webapp/mobile/generic.js (original)
+++ incubator/isis/trunk/examples/onlinedemo/webapp/src/main/webapp/mobile/generic.js Thu
Jan 19 09:08:19 2012
@@ -1,20 +1,34 @@
-clonePage = function(pageTemplateId, discriminator) {
+cloneTemplatePage = function(pageBaseId, urlHref, dataOptions) {
 
-  var id = pageTemplateId + "-" + urlencode(discriminator);
-  var page = $(pageTemplateId).clone().attr("id", id);
-  page.appendTo("#pageHolder");
+  var urlHrefEncoded = urlencode(urlHref);
 
+  var pageId = pageBaseId + "-" + urlHrefEncoded;
+  removePage(pageId);
+
+  var page = cloneAndInsertPage(pageBaseId, pageId)
+  
+  dataOptions.dataUrl = pageBaseId + "?url=" + urlHrefEncoded
   return page;
 }
 
+extract = function(urlHref) {
+  var regex = /.*?url=(.*)/
+  var matches = regex.exec(urlHref)
+  var url = matches && matches[1]
+  if(url) {
+    return urldecode(url)
+  }
+  return urlHref
+}
+
 handleDomainObjectRepresentation = function(urlHref, dataOptions, json, xhr) {
   
-  var page = clonePage("#domainObjectView", json.oid);
-  $(page).data("urlHref", urlHref);
+  var page = cloneTemplatePage("genericDomainObjectView", urlHref, dataOptions);
   
   var header = page.children(":jqmData(role=header)");
   header.find("h1").html(json.title);
 
+  // value properties
   var valueProperties = json.members.filter(function(item) {
     return item.memberType === "property" && !item.value.href;
   });
@@ -23,6 +37,7 @@ handleDomainObjectRepresentation = funct
   applyTemplateDiv(valueProperties, valuePropertiesDiv, valuePropertiesTemplateDiv);
 
   
+  // reference properties
   var referenceProperties = json.members.filter(function(item) {
     return item.memberType === "property" && item.value.href;
   });
@@ -41,27 +56,26 @@ handleDomainObjectRepresentation = funct
     }
   });
 
+  // collections
   var collectionsList = page.children(":jqmData(role=content)").find(".collections");
   var collectionsTemplateDiv = page.children(".collections-tmpl");
   applyTemplateDiv(collections, collectionsList, collectionsTemplateDiv);
 
+
+  // refresh
   page.page();
   page.trigger("create");
   
   referencePropertiesList.listview("refresh");
   collectionsList.listview("refresh");
   
-  dataOptions.dataUrl="#object?url=" + urlencode(urlHref)
-
   return page
 } 
 
 
-listRepresentation = 0;
 handleListRepresentation = function(urlHref, dataOptions, json, xhr) {
   
-  var page = clonePage("#listView", listRepresentation++);
-  $(page).data("urlHref", urlHref);
+  var page = cloneTemplatePage("genericListView", urlHref, dataOptions);
   
   var items = $.map(json, function(value, i) {
     return {
@@ -80,25 +94,18 @@ handleListRepresentation = function(urlH
   var templateDiv = page.find(".tmpl");
   
   applyTemplateDiv(items, div, templateDiv);
-  page.page();
-
-  div.listview("refresh");
   
-  dataOptions.dataUrl="#list?num=" + listRepresentation
+  // no longer needed?
+  //page.page();
+  //div.listview("refresh");
   
   return page;
 }
 
-grepLink = function(links, relStr) {
-  return $.grep(links, function(v) { return v.rel === relStr } )[0]
-}
-
-objectCollectionRepresentation = 0;
 handleObjectCollectionRepresentation = function(urlHref, dataOptions, json, xhr) {
   
-  var page = clonePage("#objectCollectionView", objectCollectionRepresentation++);
-  $(page).data("urlHref", urlHref);
-
+  var page = cloneTemplatePage("genericObjectCollectionView", urlHref, dataOptions);
+  
   var items = $.map(json.value, function(value, i) {
     return {
       "hrefUrlEncoded" : urlencode(value.href),
@@ -110,20 +117,8 @@ handleObjectCollectionRepresentation = f
   var header = page.children(":jqmData(role=header)");
   var content = page.children(":jqmData(role=content)");
 
-  var parentHref = grepLink(json.links, "up").href
-  var parentOid;
-  var parentTitle;
+  var parentTitle = grepLink(json.links, "up").title
   
-  $.ajax({
-    url : parentHref,
-    dataType : 'json',
-    async: false,
-    success : function(json, str, xhr) {
-      parentOid = json.oid;
-      parentTitle = json.title;
-    }
-  })
-
   var collectionId = json.id;
   header.find("h1").html(collectionId + " for " + parentTitle);
 
@@ -131,13 +126,10 @@ handleObjectCollectionRepresentation = f
   var templateDiv = page.find(".tmpl");
   
   applyTemplateDiv(items, div, templateDiv);
-  page.page();
-
   
-  
-  div.listview("refresh");
-  
-  dataOptions.dataUrl="#collection?url=" + urlencode(urlHref)
+  // no longer needed?
+  //page.page();
+  //div.listview("refresh");
   
   return page;
 }
@@ -156,9 +148,13 @@ handleActionResultRepresentation = funct
 
 handlers = {
     "application/json;profile=\"urn:org.restfulobjects/domainobject\"": handleDomainObjectRepresentation,
+    "application/json; profile=\"urn:org.restfulobjects/domainobject\"": handleDomainObjectRepresentation,
     "application/json;profile=\"urn:org.restfulobjects/list\"": handleListRepresentation,
+    "application/json; profile=\"urn:org.restfulobjects/list\"": handleListRepresentation,
     "application/json;profile=\"urn:org.restfulobjects/objectcollection\"": handleObjectCollectionRepresentation,
-    "application/json;profile=\"urn:org.restfulobjects/actionresult\"": handleActionResultRepresentation
+    "application/json; profile=\"urn:org.restfulobjects/objectcollection\"": handleObjectCollectionRepresentation,
+    "application/json;profile=\"urn:org.restfulobjects/actionresult\"": handleActionResultRepresentation,
+    "application/json; profile=\"urn:org.restfulobjects/actionresult\"": handleActionResultRepresentation
 }
 
 submitAndRender = function(urlHref, dataOptions) {
@@ -174,10 +170,6 @@ submitAndRender = function(urlHref, data
       } 
       var page = handler(urlHref, dataOptions, json, xhr)
 
-      if(dataOptions) {
-        dataOptions.dataUrl = urlHref;
-      }
-  
       $.mobile.changePage(page, dataOptions);
     }
   })

Modified: incubator/isis/trunk/examples/onlinedemo/webapp/src/main/webapp/mobile/index.html
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/examples/onlinedemo/webapp/src/main/webapp/mobile/index.html?rev=1233258&r1=1233257&r2=1233258&view=diff
==============================================================================
--- incubator/isis/trunk/examples/onlinedemo/webapp/src/main/webapp/mobile/index.html (original)
+++ incubator/isis/trunk/examples/onlinedemo/webapp/src/main/webapp/mobile/index.html Thu
Jan 19 09:08:19 2012
@@ -41,18 +41,14 @@
             </li>
         </script>
         
-        <!-- workaround? http://stackoverflow.com/questions/7544023/how-to-initialize-pages-in-jquery-mobile-pageinit-not-firing
-->
         <script type="text/javascript">
-        
             $("#home button").click(function(){
                 $.mobile.changePage("/services/toDoItems/actions/toDosForToday/invoke", "pop")
             });
-            
-            /*$(document).delegate("#home", "pageinit", todaysTasksPage);*/
         </script>
 	</div>
 
-    <div data-role="page" id="listView">
+    <div data-role="page" id="genericListView">
 
         <div data-role="header">
             <a data-icon="back" data-rel="back">Back</a>
@@ -71,7 +67,7 @@
         </script>
     </div>
 
-    <div data-role="page" id="objectCollectionView">
+    <div data-role="page" id="genericObjectCollectionView">
 
         <div data-role="header">
             <a data-icon="back" data-rel="back">Back</a>
@@ -90,7 +86,7 @@
         </script>
     </div>
 
-    <div data-role="page" id="domainObjectView">
+    <div data-role="page" id="genericDomainObjectView">
 
         <div data-role="header">
             <a data-icon="back" data-rel="back">Back</a>

Modified: incubator/isis/trunk/examples/onlinedemo/webapp/src/main/webapp/mobile/util.js
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/examples/onlinedemo/webapp/src/main/webapp/mobile/util.js?rev=1233258&r1=1233257&r2=1233258&view=diff
==============================================================================
--- incubator/isis/trunk/examples/onlinedemo/webapp/src/main/webapp/mobile/util.js (original)
+++ incubator/isis/trunk/examples/onlinedemo/webapp/src/main/webapp/mobile/util.js Thu Jan
19 09:08:19 2012
@@ -1,3 +1,28 @@
+findPage = function(id) {
+  var page = $("#pageHolder").find("#"+id);
+  if(page[0]) {
+    return page[0];
+  }
+  return null
+}
+
+removePage = function(id) {
+  var page = findPage(id)
+  if(page) {
+    page.remove();
+  }
+}
+
+cloneAndInsertPage = function(sourceId, targetId) {
+  var page = $("#"+sourceId).clone().attr("id", targetId);
+  page.appendTo("#pageHolder");
+  return page
+}
+
+grepLink = function(links, relStr) {
+  return $.grep(links, function(v) { return v.rel === relStr } )[0]
+}
+
 queryParamsFor = function (href) {
     var vars = [], hash;
     var hashes = href.slice(href.indexOf('?') + 1).split('&');



Mime
View raw message