File:  [LON-CAPA] / modules / damieng / graphical_editor / loncapa_daxe / web / nodes / textfield.dart
Revision 1.2: download - view: text, annotated - select for diffs
Tue Feb 28 20:40:59 2017 UTC (7 years, 8 months ago) by damieng
Branches: MAIN
CVS tags: HEAD
updates following changes in Daxe Config API

/*
  This file is part of LONCAPA-Daxe.

  LONCAPA-Daxe is free software: you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation, either version 3 of the License, or
  (at your option) any later version.

  LONCAPA-Daxe is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with Daxe.  If not, see <http://www.gnu.org/licenses/>.
*/

part of loncapa_daxe;

/**
 * Display for the textfield element, for simple UI (some attributes are displayed like attributes of the parent).
 * Jaxe display type: 'textfield'.
 */
class Textfield extends LCDBlock {
  
  static List<String> simpleUIAttributes = ['spellcheck', 'rows', 'cols'];
  
  Textfield.fromRef(x.Element elementRef) : super.fromRef(elementRef);
  
  Textfield.fromNode(x.Node node, DaxeNode parent) : super.fromNode(node, parent) {
    if (simpleParent())
      simpleUI = true;
  }
  
  @override
  bool simpleUIPossible() {
    if (attributes.length != 0) {
      // accept any spellcheck, rows, columns, but no addchars
      for (DaxeAttr att in attributes) {
        if (!simpleUIAttributes.contains(att.name)) {
          throw new SimpleUIException('textfield: ' + LCDStrings.get('attribute_problem') + att.name);
        }
      }
    }
    if (firstChild != null)
      return false;
    return true;
  }
  
  bool simpleParent() {
    return (parent is LCDBlock && (parent as LCDBlock).simpleUI) &&
        (parent is EssayResponse);
  }
  
  @override
  h.Element html() {
    simpleUI = simpleParent();
    if (!simpleUI)
      return super.html();
    
    // the whole textfield node is reduced to its attributes
    h.TableElement table = new h.TableElement();
    table.classes.add('expand');
    table.id = id;
    for (x.Element refAttr in attRefs) {
      String name = doc.cfg.attributeName(refAttr);
      if (simpleUIAttributes.contains(name)) {
        h.TableRowElement tr = attributeHTML(refAttr);
        table.append(tr);
      }
    }
    return(table);
  }
  
  @override
  void updateAttributes() {
    if (!simpleUI) {
      super.updateAttributes();
      return;
    }
    parent.updateHTML();
  }
}

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