Annotation of modules/damieng/graphical_editor/loncapa_daxe/web/nodes/textline.dart, revision 1.8
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: * Display for the textline element, for simple UI (the textline size is displayed like an attribute).
22: * Jaxe display type: 'textline'.
23: */
24: class Textline extends LCDBlock {
25:
26: Textline.fromRef(x.Element elementRef) : super.fromRef(elementRef);
27:
28: Textline.fromNode(x.Node node, DaxeNode parent) : super.fromNode(node, parent) {
1.2 damieng 29: if (simpleParent())
1.1 damieng 30: simpleUI = true;
31: }
32:
1.4 damieng 33: @override
34: bool simpleUIPossible() {
35: if (attributes.length != 0) {
36: // accept any size and readonly=no
1.7 damieng 37: // accept spellcheck only with value 'none'
1.4 damieng 38: for (DaxeAttr att in attributes) {
1.6 damieng 39: if (!((att.name == 'size' && parent is! OrganicResponse) ||
40: (att.name == 'readonly' && (att.value == 'no' || parent is OrganicResponse ||
1.7 damieng 41: parent is ReactionResponse)) ||
42: (att.name == 'spellcheck' && (att.value == '' || att.value == 'none')))) {
1.4 damieng 43: throw new SimpleUIException('textline: ' + LCDStrings.get('attribute_problem') + att.name);
44: }
45: }
46: }
47: if (firstChild != null)
48: return false;
49: return true;
50: }
51:
1.2 damieng 52: bool simpleParent() {
53: return (parent is LCDBlock && (parent as LCDBlock).simpleUI) &&
1.6 damieng 54: (parent is NumericalResponse || parent is FormulaResponse || parent is StringResponse ||
55: parent is MathResponse || parent is OrganicResponse || parent is ReactionResponse);
1.2 damieng 56: }
57:
1.1 damieng 58: @override
59: h.Element html() {
1.2 damieng 60: simpleUI = simpleParent();
1.1 damieng 61: if (!simpleUI)
62: return super.html();
63:
1.3 damieng 64: // the whole textline node is reduced to its size attribute
1.6 damieng 65: // or readonly attribute for organicresponse
66: // or size+readonly for reactionresponse
67: h.TableElement table = new h.TableElement();
68: if (parent is! OrganicResponse) {
69: x.Element sizeRef = null;
70: for (x.Element refAttr in attRefs) {
1.8 ! damieng 71: String name = doc.cfg.attributeName(refAttr);
1.6 damieng 72: if (name == 'size') {
73: sizeRef = refAttr;
74: break;
75: }
76: }
77: assert(sizeRef != null);
78:
79: h.TableRowElement tr = attributeHTML(sizeRef);
80: tr.id = id;
81: tr.childNodes[1].text = LCDStrings.get('field_size');
82: table.append(tr);
83: }
84: if (parent is OrganicResponse || parent is ReactionResponse) {
85: x.Element readonlyRef = null;
86: for (x.Element refAttr in attRefs) {
1.8 ! damieng 87: String name = doc.cfg.attributeName(refAttr);
1.6 damieng 88: if (name == 'readonly') {
89: readonlyRef = refAttr;
90: break;
91: }
1.3 damieng 92: }
1.6 damieng 93: assert(readonlyRef != null);
94:
95: h.TableRowElement tr = attributeHTML(readonlyRef);
96: tr.id = id;
97: tr.childNodes[1].text = LCDStrings.get('readonly_field');
98: table.append(tr);
1.3 damieng 99: }
1.6 damieng 100: if (table.childNodes.length == 1)
101: return table.firstChild;
102: else
103: return(table);
1.1 damieng 104: }
105:
1.2 damieng 106: @override
107: void updateAttributes() {
108: if (!simpleUI) {
109: super.updateAttributes();
110: return;
111: }
112: parent.updateHTML();
113: }
1.1 damieng 114: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>