2 * 2009 Benoit Pin - MINES ParisTech
12 CartWidget = function(slide
, url
) {
15 var req
= new XMLHttpRequest();
16 url
= url
+ '?ajax=1';
17 req
.open("GET", url
, false);
22 if (req
.status
!== 200){
26 var doc
= req
.responseXML
.documentElement
;
27 var wdgtNode
= this.wdgtNode
= getCopyOfNode(doc
);
28 slide
.appendChild(wdgtNode
);
30 var descriptions
= this.descriptions
= [];
31 var divs
= wdgtNode
.getElementsByTagName('div');
33 for (i
=0; i
<divs
.length
; i
++) {
35 if (d
.className
=== 'ppt-description') {
36 descriptions
[d
.getAttribute('name')] = d
;
40 var form
= this.form
= this.wdgtNode
.getElementsByTagName('form')[0];
41 var itemSelector
= this.itemSelector
= form
.elements
[0];
42 var fm
= this.fm
= new FormManager(form
);
44 fm
.onBeforeSubmit = function(fm
, evt
){return thisCart
.onBeforeSubmit(fm
, evt
);};
45 fm
.onResponseLoad = function(req
){return thisCart
.loadResponse(req
);};
47 descriptions
[itemSelector
.value
].style
.visibility
= 'visible';
48 descriptions
[itemSelector
.value
].style
.display
='block';
49 this.selectedItem
= itemSelector
.value
;
51 addListener(itemSelector
, 'change', function(evt
){thisCart
.selectItem(evt
);});
54 CartWidget
.prototype.selectItem = function(evt
) {
55 this.descriptions
[this.selectedItem
].style
.visibility
= 'hidden';
56 this.descriptions
[this.selectedItem
].style
.display
= 'none';
57 var name
= this.itemSelector
.value
;
59 this.descriptions
[name
].style
.visibility
= 'visible';
60 this.descriptions
[name
].style
.display
='block';
62 this.selectedItem
= name
;
65 CartWidget
.prototype.onBeforeSubmit = function(fm
, evt
) {
66 if (fm
.submitButton
.name
=== 'cancel') {
68 return 'cancelSubmit';
72 CartWidget
.prototype.loadResponse = function(req
) {
73 var doc
= req
.responseXML
.documentElement
;
74 switch(doc
.nodeName
) {
76 var slide
= this.slide
;
77 slide
.removeChild(this.wdgtNode
);
79 var text
= doc
.firstChild
.nodeValue
;
80 var confirm
= document
.createElement('div');
81 confirm
.className
= 'confirm-message';
82 confirm
.innerHTML
= text
;
83 slide
.appendChild(confirm
);
85 var duration
= parseInt(doc
.getAttribute('duration'), 10) * 1000;
88 setTimeout(function(){
89 slide
.removeChild(confirm
);
90 thisCart
.onAfterConfirm();
98 alert(doc
.firstChild
.nodeValue
);
104 CartWidget
.prototype.onCancel = function() {
105 this.wdgtNode
.parentNode
.removeChild(this.wdgtNode
);
108 CartWidget
.prototype.onAfterConfirm = function(){};