0

Problem

CODE
var DetailView = new KONtx.Class({

ClassName: 'DetailView',



Extends: KONtx.system.SidebarView,



config: {




Feed_XML: false, //A simple holder for our XMl Feed that also acts a Network success indicator

},

createView: function() {
var self = this;

var movieID = this.persist.movieID;
var countRatingsUrl='http://123.45.67.89/MoviesWS/Service.asmx/countStars?movieID'+ movieID;
self.grabXML(countRatingsUrl);

this.controls.backButton = new KONtx.control.BackButton({

label: "Back",

guid: "back_button",

styles: {

width: this.width

}

}).appendTo(this);

var drawingArea = new KONtx.element.Container({

styles: {

width: this.width,

height: 365,

vOffset: this.controls.backButton.outerHeight,

backgroundColor: '#e5f4f9'



}

}).appendTo(this);

this.controls.title = new KONtx.element.Text({



styles: {

color: '#000000',

fontSize: KONtx.utility.scale(14),

fontWeight: 'bold',

hAlign: 'left',

width: this.width - 120,

wrap: true,

vOffset: 10,

hOffset: 110

}

}).appendTo(drawingArea);







this.controls.description = new KONtx.element.Text({



styles: {

color: '#121212',

fontSize: KONtx.utility.scale(12),

hAlign: 'left',

width: this.width-20,

wrap: true,

vOffset: 175,

hOffset: 10

}

}).appendTo(drawingArea);

this.controls.openingtime = new KONtx.element.Text({



styles: {

color: '#121212',

fontSize: KONtx.utility.scale(12),

hAlign: 'left',

width: this.width-110,

wrap: true,

vOffset: 30,

hOffset: 110

}

}).appendTo(drawingArea);

this.controls.director = new KONtx.element.Text({



styles: {

color: '#121212',

fontSize: KONtx.utility.scale(12),

hAlign: 'left',

width: this.width-110,

wrap: true,

vOffset: 45,

hOffset: 110

}

}).appendTo(drawingArea);

this.controls.cast = new KONtx.element.Text({



styles: {

color: '#121212',

fontSize: KONtx.utility.scale(12),

hAlign: 'left',

width: this.width-110,

wrap: true,

vOffset: 60,

hOffset: 110

}

}).appendTo(drawingArea);

this.controls.language = new KONtx.element.Text({



styles: {

color: '#121212',

fontSize: KONtx.utility.scale(12),

hAlign: 'left',

width: this.width-20,

wrap: true,

vOffset: 135,

hOffset: 10

}

}).appendTo(drawingArea);





this.controls.image = new KONtx.element.Image({

styles: {

'hAlign': 'top',

'vAlign': 'left',

width: 95,

height: 120,

backgroundColor: '#EEEEEE',

hOffset: 10,

vOffset: 10

}

}).appendTo(drawingArea);

this.controls.ratings = new KONtx.element.Text({

styles: {

color: '#000000',

fontSize: KONtx.utility.scale(14),

fontWeight: 'bold',

hAlign: 'left',

width: this.width - 120,

wrap: true,

vOffset: 210,

hOffset: 110

}

}).appendTo(drawingArea);

this.controls.stars = new KONtx.element.Image({



styles: {

'hAlign': 'top',

'vAlign': 'left',

width: 60,

height: 20,

backgroundColor: '#000000',

hOffset: 230,

vOffset: 340





},





}).appendTo(drawingArea);



this.controls.movieID = new KONtx.element.Text({





})



this.controls.videoURL = new KONtx.element.Text({

styles: {



}

})





updateView: function() {

this.getRatings;
this.controls.ratings.setText(avgRatings);

this.controls.title.setText(this.persist.title);

this.controls.movieID.setText(this.persist.movieID);

this.controls.description.setText(this.persist.description);

this.controls.director.setText(this.persist.director);

this.controls.cast.setText(this.persist.cast);

this.controls.language.setText(this.persist.language);

this.controls.openingtime.setText(this.persist.openingtime);

this.controls.image.setSource(this.persist.image);

this.controls.videoURL.setText(this.persist.videoURL);

if(this.controls.ratings.data==1)

{

this.controls.stars.setSource('image/star.png')

}

else if(this.controls.ratings.data==2)

{

this.controls.stars.setSource('image/star2.png')

}

else if(this.controls.ratings.data==3)

{

this.controls.stars.setSource('image/star3.png')

}

else if(this.controls.ratings.data==4)

{

this.controls.stars.setSource('image/star4.png')

}

else if(this.controls.ratings.data==5)

{

this.controls.stars.setSource('image/star5.png')

}

},

getRatings:function(){





//Let's create a new object

var avgRatings = this.config.Feed_XML.evaluate('string(int)');



},

grabXML: function(url){

//We are activating the Loading Indicator for the widgets so that we can alert the user to the fact we are loading data.

KONtx.utility.LoadingOverlay.on();

//Again we need a reference to the view while we seto out into the Network Object

var self = this;

//We are send a Network Request

Network.send(url,self.finishXML,{view:self, mess:'Feed Loaded '});

//NOTE: We are passing the reference to this view through the object in the Third Value slot

},



finishXML: function(response,extra){

//ALWAYS wrap your parse statements in a try{}catch(e){} statement -> ALWAYS

try{

print('Parsing the XML Feed\n'+response+'\n'); //We will be showing the Response Data in the terminal

extra.view.config.Feed_XML = XMLDOM.parse( response ); //If we get a valid reponse back we need to parse out the XML

}

catch(e)

{

print('DANGER: We could not parse the XML Feed');

extra.view.config.Feed_XML = false; //This kills the updateView check below

}



//We are kill the Loading Indicator for the widgets so that we can alert the user to the fact we are done loading data.

KONtx.utility.LoadingOverlay.off();



//Now we only want to update the Feed if we have a valid XML object

if(extra.view.config.Feed_XML) //Check to make sure we were able to parse the XML feed

{

print(extra.mess); //This information comes from the third item in the Network.send() and is passed back in the second value of this.finishXML()

extra.view.updateView(); //Now let's update the View with the new information

}

else //If the Feed fails to Load, show an error dialog

{

extra.view._showErrorDialog();

}

},



_showErrorDialog: function() {

//Setup an interval View Reference

var self = this;

//Create the Error Dialog

this._errorDialog = new KONtx.dialogs.Alert({

title: 'Could Not Load XML Feed',

message: 'We are sorry the XML Feed requested could not be loaded.',

buttons: [

{ label: 'OK', callback: function() {

self._errorDialog.hide(); //Hide the Error Dialog after the User confirms the loading error

} }

]

});

this._errorDialog.show(); //Show the Error Dialog

},



});

Above are part of my codes.
The countRatingsUrl returns an integer value but I somehow cannot get the integer value.

An example of the XML value is

CODE
<int>3</int>

by
5 Replies
  • What does you XML look like? I am pretty sure you are not using the XPath correctly.
    0
  • QUOTE (WidgetRealm @ May 8 2011, 06:52 PM) <{POST_SNAPBACK}>
    What does you XML look like? I am pretty sure you are not using the XPath correctly.

    This is the xml.
    CODE
    <int>3</int>
    0
  • Ok.... That is not a valid XML document.

    It should look like this:
    CODE
    >xml>
    <int>3</int>
    </xml>



    You then pull it out like this:
    CODE
    var avgRatings = this.config.Feed_XML.evaluate('int(xml/int)');
    0
  • QUOTE (WidgetRealm @ May 9 2011, 06:30 AM) <{POST_SNAPBACK}>
    Ok.... That is not a valid XML document.

    It should look like this:
    CODE
    >xml>
    <int>3</int>
    </xml>



    You then pull it out like this:
    CODE
    var avgRatings = this.config.Feed_XML.evaluate('int(xml/int)');


    Thanks but I still have a question. I tried 'int(xml/int)' and it returns an undefined value, but when i change to 'string(xml/int)', it returns a string value of the integer which i do not want, hence may i ask is there anything wrong with the code?
    0
  • Then do this:

    CODE
    var avgRatings = parseInt(this.config.Feed_XML.evaluate('string(xml/int)'));
    0

Recent Posts

in Getting Started / Beginners - Yahoo! TV Widgets