|
|
| Welcome to the Mac Forums forums. Please read the FAQ if you have questions. Register to participate. |
|
|||||||
| TouchArcade.com - iPhone Game Reviews and News |
![]() |
|
|
Thread Tools | Search this Thread | Display Modes |
|
|
#1 |
|
macrumors regular
|
iPhone WebApp Developing question about Javascript
Hello.
When I launch DashCode to develop an webapp and choose the browser sample, I can only change the text but their details are all the same except for representedObject (like The snow conditions in "representedObject" are great.). How can I change that and allow each text to go to a completely different detail? Thanks.
__________________
Macbook White 2.16 C2D / 160GB / 2GB iPhone 8GB Unlocked 1.1.322" LCD Viewsonic 250GB Time Machine RAID 1: Double-500GB Drives |
|
|
|
|
|
#2 |
|
Thread Starter
macrumors regular
|
Anyone?
__________________
Macbook White 2.16 C2D / 160GB / 2GB iPhone 8GB Unlocked 1.1.322" LCD Viewsonic 250GB Time Machine RAID 1: Double-500GB Drives |
|
|
|
|
|
#3 |
|
macrumors member
Join Date: Feb 2008
Location: NY
|
I just started programming a web version of my application and I am having lots of questions myself. There is not much of help available in adc too(other than that presentation by Mark Malone)
__________________
ASUS C90S - Intel Conroe and 2 GB RAM Samsung Q1p UMPC 15 inch Macbook Pro Zune 30 GB "We are what we repeatedly do" |
|
|
|
|
|
#4 | |
|
macrumors member
Join Date: Feb 2008
Location: NY
|
Quote:
__________________
ASUS C90S - Intel Conroe and 2 GB RAM Samsung Q1p UMPC 15 inch Macbook Pro Zune 30 GB "We are what we repeatedly do" |
|
|
|
|
|
|
#5 |
|
Thread Starter
macrumors regular
|
Here is the code. What can I change to each object load to a different page?
Code:
var listController = {
_rowData: [
"Alta",
"Aspen",
"Big Bear",
"Boreal",
"Brundage Mountain",
"Heavenly",
"Kirkwood",
"Mammoth",
"Northstar",
"Park City",
"Snowbird",
"Squaw Valley",
"Sugar Bowl",
"Sun Valley",
"Vail",
],
numberOfRows: function() {
return this._rowData.length;
},
prepareRow: function(rowElement, rowIndex, templateElements) {
if (templateElements.rowTitle) {
templateElements.rowTitle.innerText = this._rowData[rowIndex];
}
// We also assign an onclick handler that will cause the browser to go to the detail page.
var self = this;
var handler = function() {
var resort = self._rowData[rowIndex];
detailController.setRepresentedObject(resort);
var browser = document.getElementById('browser').object;
// The Browser's goForward method is used to make the browser push down to a new level. Going back to previous levels is handled automatically.
browser.goForward(document.getElementById('detailLevel'), resort);
};
rowElement.onclick = handler;
}
};
var detailController = {
// This object acts as a controller for the detail UI.
setRepresentedObject: function(representedObject) {
this._representedObject = representedObject;
var detailText = document.getElementById('detailText');
detailText.innerHTML = "The snow conditions in " + representedObject + " are awesome!";
}
};
function load()
{
setupParts();
}
__________________
Macbook White 2.16 C2D / 160GB / 2GB iPhone 8GB Unlocked 1.1.322" LCD Viewsonic 250GB Time Machine RAID 1: Double-500GB Drives |
|
|
|
|
|
#6 |
|
macrumors newbie
Join Date: Sep 2007
|
I'd like to know the same thing. If it were Dreamweaver, I could simply make a home screen that each led to a different page of mere text in a few minutes. Thats all I want to do, but I spent well over an hour with nothing to show for it.
So does anyone know how to use this yet? Obviously, I'm no coder, but this seems like it should be able to function as a decent WYSIWYG, but I'm not getting it. |
|
|
|
|
|
#7 |
|
macrumors newbie
Join Date: Mar 2008
|
I've got it working using a dynamic xmlhttp source from my website; unfortunately, I can't post the example, as it's video site (and the login stuff isn't working yet).
Here's what I have figured out though:
Here's my code: Code:
// This file was generated by Dashcode from Apple Inc.
// You may edit this file to customize your web application.
var listController = {
// This object acts as a controller for the list UI.
// It implements the dataSource methods for the list.
// This dataSource uses fixed data for the content of the list. Some applications may have such static data for their lists, others will want to replace this with information fetched remotely via XMLHttpRequest.
_rowData: null,
loadCategoryData : function() {
// Values you provide
var feedURL = "some url here....";
// XMLHttpRequest setup code
var xmlRequest = new XMLHttpRequest();
xmlRequest.onreadystatechange= function()
{
var result= null;
switch(xmlRequest.readyState)
{
case 4:
if(xmlRequest.status==200)
{
// parse it...
// dumpResponseXML(responseXML);
listController._rowData= new Array();
var nodelist= xmlRequest.responseXML.getElementsByTagName('ResultItem');
for(var ii= 0; ii<nodelist.length; ii++)
{
listController._rowData.push(new ResultItem(
nodelist[ii].getAttribute('Title'),
nodelist[ii].getAttribute('Description'),
nodelist[ii].getAttribute('OnClick'),
nodelist[ii].getAttribute('HREF'),
nodelist[ii].getAttribute('ImageHREF'),
nodelist[ii].getAttribute('MediaType')));
}
// now tell us to reload!
var list= document.getElementById('list');
list.object.reloadData();
}
break;
case 3:
break;
default:
break;
}
}
xmlRequest.open("POST", feedURL);
xmlRequest.setRequestHeader("Content-type", "text/xml; charset=utf-8");
xmlRequest.setRequestHeader("SOAPAction", "SOAP Request header info here...");
xmlRequest.send(buildXMLRequest('cat', 'XXXX', '', '', ''));
},
numberOfRows: function() {
// The List calls this dataSource method to find out how many rows should be in the list.
if(this._rowData==null)
{
return 1; // Loading text...
} else {
return this._rowData.length;
}
},
prepareRow: function(rowElement, rowIndex, templateElements) {
if(this._rowData != null)
{
// The List calls this dataSource method for every row. templateElements contains references to all elements inside the template that have an id. We use it to fill in the text of the rowTitle element.
if (templateElements.rowTitle) {
templateElements.rowTitle.innerText = this._rowData[rowIndex].Title;
}
// We also assign an onclick handler that will cause the browser to go to the detail page.
var self = this;
var handler = function() {
var resort = self._rowData[rowIndex];
categoryController.setRepresentedObject(resort);
var browser = document.getElementById('browser').object;
// The Browser's goForward method is used to make the browser push down to a new level. Going back to previous levels is handled automatically.
browser.goForward(document.getElementById('categoryLevel'), resort.Title);
/*
detailController.setRepresentedObject(resort);
var browser = document.getElementById('browser').object;
// The Browser's goForward method is used to make the browser push down to a new level. Going back to previous levels is handled automatically.
browser.goForward(document.getElementById('detailLevel'), resort);
*/
};
rowElement.onclick = handler;
} else {
if (templateElements.rowTitle) {
templateElements.rowTitle.innerText = "Loading...";
}
}
}
};
var detailController = {
// This object acts as a controller for the detail UI.
setRepresentedObject: function(representedObject) {
this._representedObject = representedObject; // a ResultItem.
// load the list for this here...
// categoryObject is a node...
// Values you provide
var feedURL = "asmx service feed is here....";
// XMLHttpRequest setup code
var xmlRequest = new XMLHttpRequest();
xmlRequest.onreadystatechange= function()
{
var result= null;
switch(xmlRequest.readyState)
{
case 4:
if(xmlRequest.status==200)
{
// parse it...
// dumpResponseXML(responseXML);
detailController._rowData= new Array();
var nodelist= xmlRequest.responseXML.getElementsByTagName('ResultItem');
for(var ii= 0; ii<nodelist.length; ii++)
{
detailController._rowData.push(new ResultItem(
nodelist[ii].getAttribute('Title'),
nodelist[ii].getAttribute('Description'),
nodelist[ii].getAttribute('OnClick'),
nodelist[ii].getAttribute('HREF'),
nodelist[ii].getAttribute('ImageHREF'),
nodelist[ii].getAttribute('MediaType')));
}
// now tell us to reload!
// we don't have to reload, we just have to change out our fields...
// var list= document.getElementById('categoryList');
// list.object.reloadData();
// When the represented object is set, this controller also updates the DOM for the detail page appropriately. As you customize the design for the detail page, you will want to extend this code to make sure that the correct information is populated into the detail UI.
r= detailController._rowData[0];
var parts= r.Title.split("|");
var detailText = document.getElementById('detailText');
detailText.innerHTML = parts[0];
var authorText = document.getElementById('authorText');
authorText.innerHTML = parts[1];
var durationText = document.getElementById('durationText');
durationText.innerHTML = parts[2];
var descriptionText = document.getElementById('descriptionText');
descriptionText.innerHTML= r.Description;
var videoBox= document.getElementById('videoBox');
videoBox.innerHTML= '<embed src="'+r.ImageHREF+'" href="'+r.HREF+
'" type="video/x-m4v" target="myself" scale="1" width="128px" height="128px" />';
}
break;
case 3:
break;
default:
break;
}
}
xmlRequest.open("POST", feedURL);
xmlRequest.setRequestHeader("Content-type", "text/xml; charset=utf-8");
xmlRequest.setRequestHeader("SOAPAction", "blam blam blam");
var parameters= representedObject.OnClick.split("|");
xmlRequest.send(buildXMLRequest(parameters[0], parameters[1],
parameters[2], parameters[3], parameters[4]));
}
};
//
// Function: load()
// Called by HTML body element's onload event when the web application is ready to start
//
function load()
{
setupParts();
listController.loadCategoryData();
}
// This object implements the dataSource methods for the list.
var categoryController = {
// Sample data for the content of the list.
// Your application may also fetch this data remotely via XMLHttpRequest.
_rowData: null,
// The List calls this method to find out how many rows should be in the list.
numberOfRows: function() {
if(this._rowData==null)
{
return 1;
} else {
return this._rowData.length;
}
},
setRepresentedObject: function(categoryObject)
{
// load the list for this here...
// categoryObject is a node...
// Values you provide
var feedURL = "SOAP service feed url here.";
// XMLHttpRequest setup code
var xmlRequest = new XMLHttpRequest();
xmlRequest.onreadystatechange= function()
{
var result= null;
switch(xmlRequest.readyState)
{
case 4:
if(xmlRequest.status==200)
{
// parse it...
// dumpResponseXML(responseXML);
categoryController._rowData= new Array();
var nodelist= xmlRequest.responseXML.getElementsByTagName('ResultItem');
for(var ii= 0; ii<nodelist.length; ii++)
{
categoryController._rowData.push(new ResultItem(
nodelist[ii].getAttribute('Title'),
nodelist[ii].getAttribute('Description'),
nodelist[ii].getAttribute('OnClick'),
nodelist[ii].getAttribute('HREF'),
nodelist[ii].getAttribute('ImageHREF'),
nodelist[ii].getAttribute('MediaType')));
}
// now tell us to reload!
var list= document.getElementById('categoryList');
list.object.reloadData();
}
break;
case 3:
break;
default:
break;
}
}
// voodoo.
xmlRequest.open("POST", feedURL);
xmlRequest.setRequestHeader("Content-type", "text/xml; charset=utf-8");
xmlRequest.setRequestHeader("SOAPAction", "Soap action header here.");
var parameters= categoryObject.OnClick.split("|");
xmlRequest.send(buildXMLRequest(parameters[0], parameters[1],
parameters[2], parameters[3], parameters[4]));
},
// The List calls this method once for every row.
prepareRow: function(rowElement, rowIndex, templateElements) {
var title= "";
if(this._rowData!=null)
{
title= this._rowData[rowIndex].Title;
// Assign a click event handler for the row.
var self = this;
rowElement.onclick = function(event) {
// Do something interesting
var resort = self._rowData[rowIndex];
detailController.setRepresentedObject(resort);
var browser = document.getElementById('browser').object;
// The Browser's goForward method is used to make the browser push down to a new level. Going back to previous levels is handled automatically.
browser.goForward(document.getElementById('detailLevel'), resort.Title);
}
} else {
title= "Loading..."
}
// templateElements contains references to all elements that have an id in the template row.
// Ex: set the value of an element with id="label".
if (templateElements.label) {
templateElements.label.innerText = title;
}
}
};
function buildXMLRequest(verb, companyCode, category, searchString, showCode)
{
return "<?xml version=\"1.0\" encoding=\"utf-8\"?>"+
"<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" "+
"xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\""+" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">"+
"<soap:Body>"+
"<GetResults xmlns=\"blahblahblah/\">"+
"<password>XXX</password>"+
"<verb>"+verb+"</verb>"+ // cat
"<companyCode>"+companyCode+"</companyCode>"+
"<category>"+category+"</category>"+
"<searchString>"+searchString+"</searchString>"+
"<showCode>"+showCode+"</showCode>"+
"</GetResults>"+
"</soap:Body>"+
"</soap:Envelope>";
}
function ResultItem(title, description, onclick, href, imagehref, result_type)
{
this.Title= title;
this.Description= description;
this.OnClick= onclick;
this.HREF= href;
this.ImageHREF= imagehref;
this.Type= result_type;
return this;
}
|
|
|
|
|
|
#8 |
|
macrumors newbie
Join Date: Mar 2008
|
1. Add some list values to _rowData (like "Settings" and "Players") and make sure they appear.
2. Add some corresponding new views to the stackLayout and give them names, like "PaneSettings" and "PanePlayers". 3. Rename the "resort" var to "pane" to make it more generic. 4. Then in the listController object's "handler" function, add a switch statement like this: switch (pane) { case "Settings": browser.goForward(document.getElementById('PaneSettings'), pane); break; case "Players": browser.goForward(document.getElementById('PanePlayers'), pane); break; default: browser.goForward(document.getElementById('detailLevel'), pane); } Note that the line after "default:" was already there. I left it here so you can find it. Wrap that call up in this switch statement, or get rid of that call once you've replaced its functionality. Hope this helps... |
|
|
|
|
|
#9 | |
|
macrumors newbie
Join Date: Aug 2007
|
A little confused...
Quote:
Code:
list.reloadData(); Why do I need the list.object.reloadData? It appears that the list object itself is within the element named "list" as opposed to being what is returned from document.getElementById("list"). Even realizing that I needed to go to the DOM to get the list object in the first place wasn't readily obvious. Perhaps its my lack of understanding of the delineations between Dashcode, it's generated JS and the DOM that adding to my confusion. |
|
|
|
|
| stankyfish |
| View Public Profile |
| Find More Posts by stankyfish |
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|