Annotation of modules/damieng/graphical_editor/loncapa_daxe/web/nodes/h1.dart, revision 1.5
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: */
1.4 damieng 24: class H1 extends LCDBlockNoNewline {
1.1 damieng 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;
1.5 ! damieng 64: roleImg.onMouseDown.listen((h.MouseEvent e) {
! 65: (parent as Section).showRolesMenu(e.client);
! 66: e.preventDefault();
! 67: });
1.2 damieng 68: div.append(roleImg);
69: } else if (cl == null) {
70: h.SelectElement select = new h.SelectElement();
71: (parent as Section).fillSelectWithRoles(select);
72: div.append(select);
1.1 damieng 73: }
74: if (firstChild == null) {
75: div.style.position = 'relative';
76: h.SpanElement span = new h.SpanElement();
77: span.style.position = 'absolute';
78: span.style.color = '#CCC';
79: span.appendText(LCDStrings.get('section_title'));
80: div.append(span);
81: }
82: DaxeNode dn = firstChild;
83: while (dn != null) {
84: div.append(dn.html());
85: dn = dn.nextSibling;
86: }
87: if (lastChild == null || lastChild.nodeType == DaxeNode.TEXT_NODE)
88: div.appendText('\n');
89: return(div);
90: }
91:
92: @override
93: h.Element getHTMLContentsNode() {
94: if (!simpleUI)
95: return super.getHTMLContentsNode();
1.2 damieng 96: h.Element he = getHTMLNode();
97: if (he.nodes.first is h.ImageElement || he.nodes.first is h.SelectElement)
98: return he.nodes[1];
99: else
100: return he.nodes.first;
1.1 damieng 101: }
102:
103: @override
104: void updateHTMLAfterChildrenChange(List<DaxeNode> changed) {
105: if (!simpleUI)
106: super.updateHTMLAfterChildrenChange(changed);
107: updateHTML();
108: }
109:
110: void setupRestrictions() {
111: attRefs = [];
112: restrictedInserts = ['m','lm','chem','num','i','sup','sub'];
113: }
114:
115: @override
116: void setupSimpleUI() {
117: simpleUI = true;
118: setupRestrictions();
119: }
120:
1.3 damieng 121: @override
122: void attributeDialog([ActionFunction okfct]) {
123: // this is called by the contextual menu
124: if (simpleUI) {
125: AttributeDialog dlg = new AttributeDialog(this, okfct);
126: dlg.show();
127: } else {
128: super.attributeDialog(okfct);
129: }
130: }
131:
132: @override
133: void updateAttributes() {
134: if (!simpleUI)
135: super.updateAttributes();
136: // currently changing the attributes (even the style attribute)
137: // has no effect with simple UI
138: }
1.1 damieng 139: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>