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

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) {
1.6     ! damieng    38:         if (!((att.name == 'size' && parent is! OrganicResponse) ||
        !            39:             (att.name == 'readonly' && (att.value == 'no' || parent is OrganicResponse ||
        !            40:             parent is ReactionResponse)))) {
1.4       damieng    41:           throw new SimpleUIException('textline: ' + LCDStrings.get('attribute_problem') + att.name);
                     42:         }
                     43:       }
                     44:     }
                     45:     if (firstChild != null)
                     46:       return false;
                     47:     return true;
                     48:   }
                     49:   
1.2       damieng    50:   bool simpleParent() {
                     51:     return (parent is LCDBlock && (parent as LCDBlock).simpleUI) &&
1.6     ! damieng    52:         (parent is NumericalResponse || parent is FormulaResponse || parent is StringResponse ||
        !            53:             parent is MathResponse || parent is OrganicResponse || parent is ReactionResponse);
1.2       damieng    54:   }
                     55:   
1.1       damieng    56:   @override
                     57:   h.Element html() {
1.2       damieng    58:     simpleUI = simpleParent();
1.1       damieng    59:     if (!simpleUI)
                     60:       return super.html();
                     61:     
1.3       damieng    62:     // the whole textline node is reduced to its size attribute
1.6     ! damieng    63:     // or readonly attribute for organicresponse
        !            64:     // or size+readonly for reactionresponse
        !            65:     h.TableElement table = new h.TableElement();
        !            66:     if (parent is! OrganicResponse) {
        !            67:       x.Element sizeRef = null;
        !            68:       for (x.Element refAttr in attRefs) {
        !            69:         String name = doc.cfg.attributeQualifiedName(ref, refAttr);
        !            70:         if (name == 'size') {
        !            71:           sizeRef = refAttr;
        !            72:           break;
        !            73:         }
        !            74:       }
        !            75:       assert(sizeRef != null);
        !            76:       
        !            77:       h.TableRowElement tr = attributeHTML(sizeRef);
        !            78:       tr.id = id;
        !            79:       tr.childNodes[1].text = LCDStrings.get('field_size');
        !            80:       table.append(tr);
        !            81:     }
        !            82:     if (parent is OrganicResponse || parent is ReactionResponse) {
        !            83:       x.Element readonlyRef = null;
        !            84:       for (x.Element refAttr in attRefs) {
        !            85:         String name = doc.cfg.attributeQualifiedName(ref, refAttr);
        !            86:         if (name == 'readonly') {
        !            87:           readonlyRef = refAttr;
        !            88:           break;
        !            89:         }
1.3       damieng    90:       }
1.6     ! damieng    91:       assert(readonlyRef != null);
        !            92:       
        !            93:       h.TableRowElement tr = attributeHTML(readonlyRef);
        !            94:       tr.id = id;
        !            95:       tr.childNodes[1].text = LCDStrings.get('readonly_field');
        !            96:       table.append(tr);
1.3       damieng    97:     }
1.6     ! damieng    98:     if (table.childNodes.length == 1)
        !            99:       return table.firstChild;
        !           100:     else
        !           101:       return(table);
1.1       damieng   102:   }
                    103:   
1.2       damieng   104:   @override
                    105:   void updateAttributes() {
                    106:     if (!simpleUI) {
                    107:       super.updateAttributes();
                    108:       return;
                    109:     }
                    110:     parent.updateHTML();
                    111:   }
1.1       damieng   112: }

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