File:  [LON-CAPA] / modules / damieng / graphical_editor / loncapa_daxe / web / nodes / plot_curve.dart
Revision 1.2: download - view: text, annotated - select for diffs
Wed May 6 19:41:55 2015 UTC (9 years, 1 month ago) by damieng
Branches: MAIN
CVS tags: HEAD
schema and config file improvements, fixed inserting a templates inside a hidden paragraph, fixed some problems with response parameters, added a response template for R and one for images, handling gnuplot default attributes for simple UI, do not display the parameter templates button if there is none

/*
  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 curve title element, for simple UI (the function is displayed like an attribute).
 * Jaxe display type: 'plotcurve'.
 */
class PlotCurve extends LCDBlock {
  
  PlotCurve.fromRef(x.Element elementRef) : super.fromRef(elementRef);
  
  PlotCurve.fromNode(x.Node node, DaxeNode parent) : super.fromNode(node, parent) {
    if (simpleParent())
      simpleUI = true;
  }
  @override
  bool simpleUIPossible() {
    for (DaxeAttr att in attributes) {
      // check if it's a default value
      bool isDefault = false;
      for (x.Element attref in attRefs) {
        if (att.localName == doc.cfg.attributeName(attref) &&
            att.namespaceURI == doc.cfg.attributeNamespace(attref)) {
          String defaultValue = doc.cfg.defaultAttributeValue(attref);
          if (att.value == defaultValue)
            isDefault = true;
          break;
        }
      }
      if (!isDefault)
        throw new SimpleUIException('curve: ' + LCDStrings.get('attribute_problem') + ' ' + att.name);
    }
    if (firstChild != null && !(firstChild is FakeAttributeElement && firstChild.nodeName == 'function'))
      return false;
    if (firstChild != null && firstChild.nextSibling != null)
      return false;
    return true;
  }
  
  bool simpleParent() {
    return (parent is LCDBlock && (parent as LCDBlock).simpleUI);
  }
  
  @override
  h.Element html() {
    simpleUI = simpleParent();
    if (!simpleUI)
      return super.html();
    
    return(firstChild.html());
  }
  
  @override
  void updateHTMLAfterChildrenChange(List<DaxeNode> changed) {
    if (!simpleUI)
      super.updateHTMLAfterChildrenChange(changed);
    parent.updateHTML();
  }
  
  @override
  void setupSimpleUI() {
    simpleUI = true;
    setupRestrictions();
    fixChildrenForSimpleUI();
    state = 1;
  }
  
  void setupRestrictions() {
    attRefs = [];
    restrictedInserts = [];
  }
  
  FakeAttributeElement newFunction() {
    List<x.Element> functionRefs = doc.cfg.elementReferences('function');
    x.Element functionRef = doc.cfg.findSubElement(ref, functionRefs);
    FakeAttributeElement function = NodeFactory.create(functionRef);
    function.state = 1;
    return function;
  }
  
  /**
   * This inserts a function child element if missing.
   */
  void fixChildrenForSimpleUI() {
    bool foundFunction = false;
    for (DaxeNode dn in childNodes) {
      if (dn is FakeAttributeElement && dn.nodeName == 'function')
        foundFunction = true;
    }
    if (!foundFunction)
      appendChild(newFunction());
  }
}

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