594fd229d03d7079ea586f72f87e91ac5e1fdb4f
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
= new Array();
31 var divs
= wdgtNode
.getElementsByTagName('div');
33 for (var 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 with (descriptions
[itemSelector
.value
].style
) {
48 visibility
= 'visible';
51 this.selectedItem
= itemSelector
.value
;
53 addListener(itemSelector
, 'change', function(evt
){thisCart
.selectItem(evt
)})
56 CartWidget
.prototype.selectItem = function(evt
) {
57 with(this.descriptions
[this.selectedItem
].style
) {
58 visibility
= 'hidden';
61 var name
= this.itemSelector
.value
;
63 with (this.descriptions
[name
].style
) {
64 visibility
= 'visible';
67 this.selectedItem
= name
;
70 CartWidget
.prototype.onBeforeSubmit = function(fm
, evt
) {
71 if (fm
.submitButton
.name
== 'cancel') {
73 return 'cancelSubmit';
77 CartWidget
.prototype.loadResponse = function(req
) {
78 var doc
= req
.responseXML
.documentElement
;
79 switch(doc
.nodeName
) {
81 var slide
= this.slide
;
82 slide
.removeChild(this.wdgtNode
);
84 var text
= doc
.firstChild
.nodeValue
;
85 var confirm
= document
.createElement('div');
86 confirm
.className
= 'confirm-message';
87 confirm
.innerHTML
= text
;
88 slide
.appendChild(confirm
);
90 var duration
= parseInt(doc
.getAttribute('duration')) * 1000;
93 setTimeout(function(){
94 slide
.removeChild(confirm
);
95 thisCart
.onAfterConfirm();
103 alert(doc
.firstChild
.nodeValue
);
109 CartWidget
.prototype.onCancel = function() {
110 this.wdgtNode
.parentNode
.removeChild(this.wdgtNode
);
113 CartWidget
.prototype.onAfterConfirm = function(){};