Annotation of modules/damieng/graphical_editor/loncapa_daxe/web/nodes/textline.dart, revision 1.4

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
        !            37:       for (DaxeAttr att in attributes) {
        !            38:         if (!(att.name == 'size' ||
        !            39:             (att.name == 'readonly' && att.value == 'no'))) {
        !            40:           throw new SimpleUIException('textline: ' + LCDStrings.get('attribute_problem') + att.name);
        !            41:         }
        !            42:       }
        !            43:     }
        !            44:     if (firstChild != null)
        !            45:       return false;
        !            46:     return true;
        !            47:   }
        !            48:   
1.2       damieng    49:   bool simpleParent() {
                     50:     return (parent is LCDBlock && (parent as LCDBlock).simpleUI) &&
                     51:         (parent is NumericalResponse || parent is FormulaResponse || parent is StringResponse);
                     52:   }
                     53:   
1.1       damieng    54:   @override
                     55:   h.Element html() {
1.2       damieng    56:     simpleUI = simpleParent();
1.1       damieng    57:     if (!simpleUI)
                     58:       return super.html();
                     59:     
1.3       damieng    60:     // the whole textline node is reduced to its size attribute
                     61:     x.Element sizeRef = null;
                     62:     for (x.Element refAttr in attRefs) {
                     63:       String name = doc.cfg.attributeQualifiedName(ref, refAttr);
                     64:       if (name == 'size') {
                     65:         sizeRef = refAttr;
                     66:         break;
                     67:       }
                     68:     }
                     69:     assert(sizeRef != null);
1.1       damieng    70:     
1.3       damieng    71:     h.TableRowElement tr = attributeHTML(sizeRef);
                     72:     tr.id = id;
                     73:     tr.childNodes[1].text = LCDStrings.get('field_size');
1.1       damieng    74:     
                     75:     return(tr);
                     76:   }
                     77:   
1.2       damieng    78:   @override
                     79:   void updateAttributes() {
                     80:     if (!simpleUI) {
                     81:       super.updateAttributes();
                     82:       return;
                     83:     }
                     84:     parent.updateHTML();
                     85:   }
1.1       damieng    86: }

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>