Annotation of modules/damieng/graphical_editor/loncapa_daxe/web/nodes/h1.dart, revision 1.3
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: * Used for section's h1 (as first child).
22: * As the first child in a section, display the class icon and the title in bold.
23: */
24: class H1 extends LCDBlock {
25:
26: H1.fromRef(x.Element elementRef) : super.fromRef(elementRef);
27:
28: H1.fromNode(x.Node node, DaxeNode parent) : super.fromNode(node, parent);
29:
30: @override
31: bool simpleUIPossible() {
32: if (previousSibling != null)
33: return false;
34: if (attributes.length != 0)
35: return false;
36: if (firstChild != null && firstChild is! DNText)
37: return false;
38: if (firstChild != null && firstChild.nextSibling != null)
39: return false;
40: return true;
41: }
42:
43: @override
44: h.Element html() {
45: simpleUI = parent is Section && (parent as Section).simpleUI && previousSibling == null;
46: if (!simpleUI)
47: return super.html();
48: setupRestrictions();
49:
50: h.DivElement div = new h.DivElement();
51: div.id = "$id";
52: div.classes.add('dn');
53: if (!valid)
54: div.classes.add('invalid');
55: div.classes.add('section-title');
56: setStyle(div);
57: String cl = parent.getAttribute('class');
58: if (cl != null && cl.startsWith('role-')) {
1.2 damieng 59: h.ImageElement roleImg = new h.ImageElement();
1.1 damieng 60: String role = cl.substring(5);
1.2 damieng 61: roleImg.src = "images/section_icons/$role.png";
62: roleImg.width = 35;
63: roleImg.height = 35;
64: roleImg.onMouseDown.listen((h.MouseEvent e) => (parent as Section).showRolesMenu(e.client));
65: div.append(roleImg);
66: } else if (cl == null) {
67: h.SelectElement select = new h.SelectElement();
68: (parent as Section).fillSelectWithRoles(select);
69: div.append(select);
1.1 damieng 70: }
71: if (firstChild == null) {
72: div.style.position = 'relative';
73: h.SpanElement span = new h.SpanElement();
74: span.style.position = 'absolute';
75: span.style.color = '#CCC';
76: span.appendText(LCDStrings.get('section_title'));
77: div.append(span);
78: }
79: DaxeNode dn = firstChild;
80: while (dn != null) {
81: div.append(dn.html());
82: dn = dn.nextSibling;
83: }
84: if (lastChild == null || lastChild.nodeType == DaxeNode.TEXT_NODE)
85: div.appendText('\n');
86: return(div);
87: }
88:
89: @override
90: h.Element getHTMLContentsNode() {
91: if (!simpleUI)
92: return super.getHTMLContentsNode();
1.2 damieng 93: h.Element he = getHTMLNode();
94: if (he.nodes.first is h.ImageElement || he.nodes.first is h.SelectElement)
95: return he.nodes[1];
96: else
97: return he.nodes.first;
1.1 damieng 98: }
99:
100: @override
101: void updateHTMLAfterChildrenChange(List<DaxeNode> changed) {
102: if (!simpleUI)
103: super.updateHTMLAfterChildrenChange(changed);
104: updateHTML();
105: }
106:
107: void setupRestrictions() {
108: attRefs = [];
109: restrictedInserts = ['m','lm','chem','num','i','sup','sub'];
110: }
111:
112: @override
113: void setupSimpleUI() {
114: simpleUI = true;
115: setupRestrictions();
116: }
117:
1.3 ! damieng 118: @override
! 119: void attributeDialog([ActionFunction okfct]) {
! 120: // this is called by the contextual menu
! 121: if (simpleUI) {
! 122: AttributeDialog dlg = new AttributeDialog(this, okfct);
! 123: dlg.show();
! 124: } else {
! 125: super.attributeDialog(okfct);
! 126: }
! 127: }
! 128:
! 129: @override
! 130: void updateAttributes() {
! 131: if (!simpleUI)
! 132: super.updateAttributes();
! 133: // currently changing the attributes (even the style attribute)
! 134: // has no effect with simple UI
! 135: }
1.1 damieng 136: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>