2 * © 2009 Luxia SAS. All rights reserved.
4 * — Benoît Pin <pinbe@luxia.fr>
15 CartWidget = function(slide
, url
) {
18 var req
= new XMLHttpRequest();
19 url
= url
+ '?ajax=1';
20 req
.open("GET", url
, false);
25 if (req
.status
!= 200){
29 var doc
= req
.responseXML
.documentElement
;
30 var wdgtNode
= this.wdgtNode
= getCopyOfNode(doc
);
31 slide
.appendChild(wdgtNode
);
33 var descriptions
= this.descriptions
= new Array();
34 var divs
= wdgtNode
.getElementsByTagName('div');
36 for (var i
=0; i
<divs
.length
; i
++) {
38 if (d
.className
=='ppt-description') {
39 descriptions
[d
.getAttribute('name')] = d
;
43 var form
= this.form
= this.wdgtNode
.getElementsByTagName('form')[0];
44 var itemSelector
= this.itemSelector
= form
.elements
[0];
45 var fm
= this.fm
= new FormManager(form
);
47 fm
.onBeforeSubmit = function(fm
, evt
){return thisCart
.onBeforeSubmit(fm
, evt
);};
48 fm
.onResponseLoad = function(req
){return thisCart
.loadResponse(req
);};
50 with (descriptions
[itemSelector
.value
].style
) {
51 visibility
= 'visible';
54 this.selectedItem
= itemSelector
.value
;
56 addListener(itemSelector
, 'change', function(evt
){thisCart
.selectItem(evt
)})
59 CartWidget
.prototype.selectItem = function(evt
) {
60 with(this.descriptions
[this.selectedItem
].style
) {
61 visibility
= 'hidden';
64 var name
= this.itemSelector
.value
;
66 with (this.descriptions
[name
].style
) {
67 visibility
= 'visible';
70 this.selectedItem
= name
;
73 CartWidget
.prototype.onBeforeSubmit = function(fm
, evt
) {
74 if (fm
.submitButton
.name
== 'cancel') {
76 return 'cancelSubmit';
80 CartWidget
.prototype.loadResponse = function(req
) {
81 var doc
= req
.responseXML
.documentElement
;
82 switch(doc
.nodeName
) {
84 var slide
= this.slide
;
85 slide
.removeChild(this.wdgtNode
);
87 var text
= doc
.firstChild
.nodeValue
;
88 var confirm
= document
.createElement('div');
89 confirm
.className
= 'confirm-message';
90 confirm
.innerHTML
= text
;
91 slide
.appendChild(confirm
);
93 var duration
= parseInt(doc
.getAttribute('duration')) * 1000;
96 setTimeout(function(){
97 slide
.removeChild(confirm
);
98 thisCart
.onAfterConfirm();
106 alert(doc
.firstChild
.nodeValue
);
112 CartWidget
.prototype.onCancel = function() {
113 this.wdgtNode
.parentNode
.removeChild(this.wdgtNode
);
116 CartWidget
.prototype.onAfterConfirm = function(){};