Annotation of modules/damieng/graphical_editor/loncapa_daxe/web/nodes/textfield.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 the textfield element, for simple UI (some attributes are displayed like attributes of the parent).
! 22: * Jaxe display type: 'textfield'.
! 23: */
! 24: class Textfield extends LCDBlock {
! 25:
! 26: static List<String> simpleUIAttributes = ['spellcheck', 'rows', 'cols'];
! 27:
! 28: Textfield.fromRef(x.Element elementRef) : super.fromRef(elementRef);
! 29:
! 30: Textfield.fromNode(x.Node node, DaxeNode parent) : super.fromNode(node, parent) {
! 31: if (simpleParent())
! 32: simpleUI = true;
! 33: }
! 34:
! 35: @override
! 36: bool simpleUIPossible() {
! 37: if (attributes.length != 0) {
! 38: // accept any spellcheck, rows, columns, but no addchars
! 39: for (DaxeAttr att in attributes) {
! 40: if (!simpleUIAttributes.contains(att.name)) {
! 41: throw new SimpleUIException('textfield: ' + LCDStrings.get('attribute_problem') + att.name);
! 42: }
! 43: }
! 44: }
! 45: if (firstChild != null)
! 46: return false;
! 47: return true;
! 48: }
! 49:
! 50: bool simpleParent() {
! 51: return (parent is LCDBlock && (parent as LCDBlock).simpleUI) &&
! 52: (parent is EssayResponse);
! 53: }
! 54:
! 55: @override
! 56: h.Element html() {
! 57: simpleUI = simpleParent();
! 58: if (!simpleUI)
! 59: return super.html();
! 60:
! 61: // the whole textfield node is reduced to its attributes
! 62: h.TableElement table = new h.TableElement();
! 63: table.classes.add('expand');
! 64: table.id = id;
! 65: for (x.Element refAttr in attRefs) {
! 66: String name = doc.cfg.attributeQualifiedName(ref, refAttr);
! 67: if (simpleUIAttributes.contains(name)) {
! 68: h.TableRowElement tr = attributeHTML(refAttr);
! 69: table.append(tr);
! 70: }
! 71: }
! 72: return(table);
! 73: }
! 74:
! 75: @override
! 76: void updateAttributes() {
! 77: if (!simpleUI) {
! 78: super.updateAttributes();
! 79: return;
! 80: }
! 81: parent.updateHTML();
! 82: }
! 83: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>