comparison sxe-document.js @ 8:7b2ca4d5af6d

Add a resend-whole-state button and make it works.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Thu, 02 Feb 2012 15:45:25 +0100
parents 24aa8dccb170
children
comparison
equal deleted inserted replaced
7:853dcbe8f06f 8:7b2ca4d5af6d
23 23
24 var Document = function(initiator, name, host, domId, prolog) { 24 var Document = function(initiator, name, host, domId, prolog) {
25 this.initiator = initiator; 25 this.initiator = initiator;
26 this.name = name; 26 this.name = name;
27 this.host = host; 27 this.host = host;
28 this.participants = {};
28 29
29 this.prolog = prolog || 'data:application/xhtml+xml,%3C%3Fxml%20version%3D%271.0%27%3F%3E%0A%3C%21DOCTYPE%20html%3E%0A'; 30 this.prolog = prolog || 'data:application/xhtml+xml,%3C%3Fxml%20version%3D%271.0%27%3F%3E%0A%3C%21DOCTYPE%20html%3E%0A';
30 this.state = 'not-started'; 31 this.state = 'not-started';
31 this.records = {}; 32 this.records = {};
32 this.dom = document.getElementById(domId); 33 this.dom = document.getElementById(domId);
85 }, 86 },
86 processState: function(jid, elements) { 87 processState: function(jid, elements) {
87 var i = 0; 88 var i = 0;
88 var first = elements[0]; 89 var first = elements[0];
89 if (first.localName === 'document-begin') { 90 if (first.localName === 'document-begin') {
90 if (this.state !== 'not-started') 91 /*if (this.state !== 'not-started')
91 return; //TODO: the session has already started. 92 return;*/ //TODO: the session has already started.
92 i = 1; 93 i = 1;
93 this.prolog = first.getAttributeNS(null, 'prolog'); 94 this.prolog = first.getAttributeNS(null, 'prolog');
94 this.state = 'getting-session'; 95 this.state = 'getting-session';
95 } 96 }
96 97
121 root = this.dom; 122 root = this.dom;
122 var children = root.childNodes; 123 var children = root.childNodes;
123 124
124 for (var i = 0; i < children.length; i++) { 125 for (var i = 0; i < children.length; i++) {
125 var child = children[i]; 126 var child = children[i];
126 var element = document.createElementNS(Lightstring.NS.sxe, 'new'); 127 var element = document.createElementNS(Lightstring.ns['sxe'], 'new');
127 var rid = Lightstring.newId('GUID'); 128 var rid = Lightstring.newId('GUID');
128 element.setAttributeNS(null, 'rid', rid); 129 element.setAttributeNS(null, 'rid', rid);
129 130
130 if (parent) 131 if (parent)
131 element.setAttributeNS(null, 'parent', parent); 132 element.setAttributeNS(null, 'parent', parent);
137 element.setAttributeNS(null, 'name', child.localName); 138 element.setAttributeNS(null, 'name', child.localName);
138 state.push(element); 139 state.push(element);
139 140
140 //TODO: move that elsewhere, or make it prettier. 141 //TODO: move that elsewhere, or make it prettier.
141 var convertAttr = function(attr) { 142 var convertAttr = function(attr) {
142 var element = document.createElementNS(Lightstring.NS.sxe, 'new'); 143 var element = document.createElementNS(Lightstring.ns['sxe'], 'new');
143 element.setAttributeNS(null, 'type', 'attr'); 144 element.setAttributeNS(null, 'type', 'attr');
144 var arid = Lightstring.newId('GUID'); 145 var arid = Lightstring.newId('GUID');
145 element.setAttributeNS(null, 'rid', arid); 146 element.setAttributeNS(null, 'rid', arid);
146 element.setAttributeNS(null, 'parent', rid); 147 element.setAttributeNS(null, 'parent', rid);
147 if (attr.namespaceURI) 148 if (attr.namespaceURI)