Annotation of modules/damieng/graphical_editor/loncapa_daxe/web/nodes/hintgroup.dart, revision 1.4
1.1 damieng 1: /*
2: This file is part of LONCAPA-Daxe.
3:
4: LONCAPA-Daxe is free software: you can redistribute it and/or modify
5: it under the terms of the GNU General Public License as published by
6: the Free Software Foundation, either version 3 of the License, or
7: (at your option) any later version.
8:
9: LONCAPA-Daxe is distributed in the hope that it will be useful,
10: but WITHOUT ANY WARRANTY; without even the implied warranty of
11: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12: GNU General Public License for more details.
13:
14: You should have received a copy of the GNU General Public License
15: along with Daxe. If not, see <http://www.gnu.org/licenses/>.
16: */
17:
18: part of loncapa_daxe;
19:
20: /**
21: * This is used by RadioResponse for simple UI.
22: */
23: class Hintgroup extends LCDBlock {
24:
25: Hintgroup.fromRef(x.Element elementRef) : super.fromRef(elementRef) {
26: }
27:
28: Hintgroup.fromNode(x.Node node, DaxeNode parent) : super.fromNode(node, parent) {
29: if (parent is LCDBlock && (parent as LCDBlock).simpleUI)
30: simpleUI = true;
31: }
32:
1.2 damieng 33: @override
1.1 damieng 34: bool simpleUIPossible() {
1.3 damieng 35: for (DaxeAttr att in attributes)
36: if (att.name != 'showoncorrect' || att.value != 'no')
37: throw new SimpleUIException('hintgroup: ' + LCDStrings.get('attribute_problem') + att.name);
1.1 damieng 38: // check if there is a single hintpart with on="default" and simple content inside
39: bool hintpartok = false;
40: bool othernode = false;
41: for (DaxeNode dn in childNodes) {
42: if (dn.nodeType == DaxeNode.ELEMENT_NODE && dn.nodeName == 'hintpart' &&
43: dn.getAttribute('on') == 'default' && dn.attributes.length == 1 &&
44: SimpleUIText.checkNodeContents(dn))
45: hintpartok = true;
46: else if (dn.nodeType != DaxeNode.TEXT_NODE || dn.nodeValue.trim() != '')
47: othernode = true;
48: }
49: if (hintpartok && !othernode)
50: return true;
51: // otherwise just check the contents
52: return SimpleUIText.checkNodeContents(this);
53: }
54:
1.2 damieng 55: @override
56: h.Element html() {
57: simpleUI = parent is LCDBlock && (parent as LCDBlock).simpleUI;
58: if (!simpleUI)
59: return super.html();
60: setupRestrictions();
1.4 ! damieng 61: h.TableElement table = new h.TableElement();
! 62: table.id = id;
! 63: table.classes.add('hintgroup');
! 64: h.TableRowElement tr = new h.TableRowElement();
! 65: h.TableCellElement td = new h.TableCellElement();
1.2 damieng 66: h.SpanElement titleSpan = new h.SpanElement();
67: titleSpan.appendText(LCDStrings.get('hint') + ' ');
1.4 ! damieng 68: td.append(titleSpan);
! 69: tr.append(td);
! 70: td = new h.TableCellElement();
! 71: td.id = 'contents-' + id;
1.2 damieng 72: h.SpanElement contentsSpan = new h.SpanElement();
73: for (DaxeNode dn=firstChild; dn!= null; dn=dn.nextSibling) {
74: contentsSpan.append(dn.html());
75: }
1.4 ! damieng 76: td.append(contentsSpan);
! 77: tr.append(td);
! 78: table.append(tr);
! 79: return table;
1.2 damieng 80: }
81:
82: @override
83: h.Element getHTMLContentsNode() {
84: if (!simpleUI)
85: return super.getHTMLContentsNode();
1.4 ! damieng 86: return(h.document.getElementById('contents-' + id));
1.2 damieng 87: }
88:
89: void setupRestrictions() {
90: if (restrictedInserts == null)
91: restrictedInserts = SimpleUIText.possibleDescendants;
92: }
93:
94: @override
95: void setupSimpleUI() {
96: simpleUI = true;
97: setupRestrictions();
98: fixChildrenForSimpleUI();
99: }
100:
101: void fixChildrenForSimpleUI() {
1.1 damieng 102: // remove hintpart (but keep its content)
103: for (DaxeNode dn in childNodes) {
104: if (dn.nodeType == DaxeNode.ELEMENT_NODE && dn.nodeName == 'hintpart') {
105: removeChild(dn);
106: // remove spaces inside this node
107: normalize();
108: if (firstChild is DNText && firstChild.nodeValue.trim() == '' &&
109: firstChild.nextSibling == null)
110: removeChild(firstChild);
111: // remove left and right spaces inside hintpart
112: if (dn.firstChild.nodeType == DaxeNode.TEXT_NODE) {
113: if (dn.firstChild.nodeValue.trim() == '')
114: dn.removeChild(dn.firstChild);
115: else
116: dn.firstChild.nodeValue = dn.firstChild.nodeValue.trimLeft();
117: }
118: if (dn.lastChild.nodeType == DaxeNode.TEXT_NODE) {
119: if (dn.lastChild.nodeValue.trim() == '')
120: dn.removeChild(dn.lastChild);
121: else
122: dn.lastChild.nodeValue = dn.lastChild.nodeValue.trimRight();
123: }
124: // append hintpart content
125: for (DaxeNode dn2=dn.firstChild; dn2!=null; dn2=dn.firstChild) {
126: dn.removeChild(dn2);
127: appendChild(dn2);
128: }
129: break;
130: }
131: }
132: }
133:
134: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>