Annotation of modules/damieng/graphical_editor/loncapa_daxe/web/nodes/section.dart, revision 1.1
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 HTML section, with a possible simple UI.
! 22: * Jaxe display type: 'section'.
! 23: */
! 24: class Section extends LCDBlock {
! 25:
! 26: static List<String> simpleUIAttributes = ['class'];
! 27: bool displaySimpleButton = true;
! 28:
! 29: Section.fromRef(x.Element elementRef) : super.fromRef(elementRef) {
! 30: }
! 31:
! 32: Section.fromNode(x.Node node, DaxeNode parent) : super.fromNode(node, parent) {
! 33: if (node.ownerDocument.documentElement != null) {
! 34: if (simpleUIPossibleNoThrow())
! 35: setupSimpleUI();
! 36: }
! 37: }
! 38:
! 39: @override
! 40: bool simpleUIPossible() {
! 41: for (DaxeAttr att in attributes) {
! 42: if (!simpleUIAttributes.contains(att.name))
! 43: throw new SimpleUIException('section: ' + LCDStrings.get('attribute_problem') + ' ' + att.name);
! 44: }
! 45: if (firstChild != null && firstChild is! H1)
! 46: return false;
! 47: return true;
! 48: }
! 49:
! 50: @override
! 51: h.Element html() {
! 52: if (!simpleUI)
! 53: return super.html();
! 54: h.DivElement div = new h.DivElement();
! 55: div.id = "$id";
! 56: div.classes.add('dn');
! 57: if (!valid)
! 58: div.classes.add('invalid');
! 59: div.classes.add('section');
! 60: setStyle(div);
! 61: DaxeNode dn = firstChild;
! 62: while (dn != null) {
! 63: h.Element he = dn.html();
! 64: if (dn is DNHiddenP && dn.firstChild == null && dn.previousSibling is H1 &&
! 65: dn.previousSibling.previousSibling == null && dn.nextSibling == null) {
! 66: he.style.position = 'relative';
! 67: h.SpanElement span = new h.SpanElement();
! 68: span.style.position = 'absolute';
! 69: span.style.color = '#CCC';
! 70: span.appendText(LCDStrings.get('section_contents'));
! 71: he.append(span);
! 72: }
! 73: div.append(he);
! 74: dn = dn.nextSibling;
! 75: }
! 76: if (lastChild == null || lastChild.nodeType == DaxeNode.TEXT_NODE)
! 77: div.appendText('\n');
! 78: return(div);
! 79: }
! 80:
! 81: void setupRestrictions() {
! 82: for (int i=0; i<attRefs.length; i++) {
! 83: x.Element refAttr = attRefs[i];
! 84: if (!simpleUIAttributes.contains(doc.cfg.attributeName(refAttr))) {
! 85: attRefs.removeAt(i);
! 86: i--;
! 87: }
! 88: }
! 89: }
! 90:
! 91: @override
! 92: void setupSimpleUI() {
! 93: simpleUI = true;
! 94: setupRestrictions();
! 95: fixChildrenForSimpleUI();
! 96: state = 0;
! 97: }
! 98:
! 99: @override
! 100: void newNodeCreationUI(ActionFunction okfct) {
! 101: setupSimpleUI();
! 102: okfct();
! 103: }
! 104:
! 105: @override
! 106: h.Element getHTMLContentsNode() {
! 107: if (!simpleUI)
! 108: return super.getHTMLContentsNode();
! 109: return getHTMLNode();
! 110: }
! 111:
! 112: H1 newH1() {
! 113: List<x.Element> h1Refs = doc.cfg.elementReferences('h1');
! 114: x.Element h1Ref = doc.cfg.findSubElement(ref, h1Refs);
! 115: H1 h1 = NodeFactory.create(h1Ref);
! 116: h1.state = 1;
! 117: return h1;
! 118: }
! 119:
! 120: /**
! 121: * This inserts simpleUI children if missing.
! 122: */
! 123: void fixChildrenForSimpleUI() {
! 124: bool foundH1 = (firstChild is H1 && firstChild.nodeName == 'h1');
! 125: if (!foundH1) {
! 126: if (firstChild == null)
! 127: appendChild(newH1());
! 128: else
! 129: insertBefore(newH1(), firstChild);
! 130: }
! 131: }
! 132:
! 133: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>