Skip to content

Instantly share code, notes, and snippets.

@dmachi
dmachi / pintura-titanium-index.html
Created April 15, 2010 19:52
Pintura on Titanium Example
<html>
<head>
<title>Pintura Startup</title>
</head>
<body>
<script type="text/javascript">
require=Titanium.CommonJS.require;
print = Titanium.API.info;
var pintura = require("pintura");
dojo.require("dijit.Tree");
dojo.extend(dijit.Tree, {
childWidgetType: "dijit._TreeNode",
_createTreeNode: function(args){
if (typeof this.childWidgetType == 'string') {
this.childWidgetType = dojo.getObject(this.childWidgetType);
}
return new this.childWidgetType(args);
}
});
jsonTemplate: [{dojoType: dijit.layout.ContentPane, params: {}, attachPoint: "foo"}],
postCreate: function(){
this.inherited(arguments);
dojo.forEach(this.jsonTemplate, this.instantiateChild, this);
}
instantiateChild: function(child){
var w=new child.dojoType(child.params);
this.addChild(w);
Class({
id: "MailingList",
properties: {
name: {optional: true},
mboxFileName: {optional: true}
},
prototype: {
getMailFolder: function(){
this.messages =[];
var mboxPath = "mstor:/path/to/mbox";
javascript:(function(){function serializer(rootNode){if(!rootNode){throw new Error("Node to serialize required");}if (rootNode.nodeType==3){this.text=rootNode.nodeValue}else if(rootNode.tagName=="SCRIPT"||!rootNode.tagName){}else{this.tagName=rootNode.tagName;if(rootNode.style){ this.style=(rootNode.style.cssText+"").toLowerCase();}this.attributes={};dojo.forEach(rootNode.attributes,function(attr){if(attr.nodeValue){this.attributes[attr.nodeName]=attr.nodeValue;}},this);this.children=[];dojo.forEach(rootNode.childNodes,function(node){this.children.push(new serializer(node));},this);}}var obj = new serializer(dojo.body());var notice=document.createElement("div");dojo.style(notice,{left:0,top:0,height:"200px",width:"450px",position:"absolute",overflow:"auto",zIndex:1000,background:"#fff",border:"2px solid green"});notice.innerHTML=dojo.toJson(obj);document.body.appendChild(notice);dojo.connect(dojo.body(),"onkeydown",function(e){if(e.keyCode=='68'){dojo.destroy(notice)}})})();
//this is a little store wrapper. Pass in an existing store, a filter method, and optionally a query
//adaptor, and it will pass through all requests to the store, except the fetch, which it will perform and
//then pass through the filter before calling the callbacks. Example after the declare. Small console only
//demo currently located at: http://dmachi.dojotoolkit.org/filterstore.html
dojo.declare("FilteringStore", null, {
constructor: function(store, filter, query){
this.store = store;
for (var i in this.store){
//ttrenka's connection counting function
(function(){
var connect = 0, disconnect = 0;
dojo.connect(dojo, "connect", function(){ connect++; });
dojo.connect(dojo, "disconnect", function(){ disconnect++; });
dojo.__getConnectCount = function(){
console.log("dojo.connect has run: ", connect);
console.log("dojo.disconnect has run: ", disconnect);
console.log("Total current connections: ", (connect - disconnect));
};
// Defines the data model for the given user by request
pinturaConfig.getDataModel = function(request){
var user = request.remoteUser;
if(user){
if(admins.indexOf(user)>-1){
return fullModel; // admin users can directly access the data model without facets
}
return getUserModel(user, publicModel);
}
var nodes = multiNode.listen({port: settings.port || 8080, nodes: settings.processes || 1},
require( "http" ).createServer(
require("jsgi-node").Listener(
// uncomment this to enable compression with node-compress
//require("pintura/jsgi/compress").Compress(
// make the root url redirect to /Page/Root
require("pintura/jsgi/rewriter").Rewriter("\/$", "/page/test",
require("pintura/jsgi/cascade").Cascade([
// cascade from static to pintura REST handling
// the main place for static files accessible from the web
if (response.status > 400) {
//print("Error Response: " + response.status);
template = templateEngine.compile("/error/"+response.status);
}else{
template = templateEngine.compile(templateId, (mediaParams && mediaParams.template));
}
return {