File:  [LON-CAPA] / modules / damieng / graphical_editor / loncapa_daxe / web / nodes / jsme_dialog.dart
Revision 1.1: download - view: text, annotated - select for diffs
Thu May 7 20:59:30 2015 UTC (9 years, 1 month ago) by damieng
Branches: MAIN
CVS tags: HEAD
added organicresponse and reactionresponse

/*
  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;

/**
 * JSME modal dialog for organicresponse.
 */
class JSMEDialog {
  ActionFunction _okfct;
  js.JsObject jsmeApplet;
  String jmeString;
  String smiles;
  
  JSMEDialog(this._okfct, {this.jmeString});
  
  void show() {
    h.DivElement div1 = new h.DivElement();
    div1.id = 'dlg1';
    div1.classes.add('dlg1');
    h.DivElement div2 = new h.DivElement();
    div2.classes.add('dlg2');
    h.DivElement div3 = new h.DivElement();
    div3.classes.add('dlg3');
    div3.style.minWidth = '400px';
    
    h.DivElement jsmeDiv = new h.DivElement();
    jsmeDiv.id = 'jsme_container';
    div3.append(jsmeDiv);
    
    h.FormElement form = new h.FormElement();
    h.DivElement div_buttons = new h.DivElement();
    div_buttons.classes.add('buttons');
    h.ButtonElement bCancel = new h.ButtonElement();
    bCancel.attributes['type'] = 'button';
    bCancel.appendText(Strings.get("button.Cancel"));
    bCancel.onClick.listen((h.MouseEvent event) => div1.remove());
    div_buttons.append(bCancel);
    h.ButtonElement bOk = new h.ButtonElement();
    bOk.attributes['type'] = 'submit';
    bOk.appendText(Strings.get("button.OK"));
    bOk.onClick.listen((h.MouseEvent event) => ok(event));
    div_buttons.append(bOk);
    form.append(div_buttons);
    
    div3.append(form);
    div2.append(div3);
    div1.append(div2);
    h.document.body.append(div1);
    
    startApplet();
  }
  
  void ok(h.MouseEvent event) {
    h.querySelector('div#dlg1').remove();
    if (event != null)
      event.preventDefault();
    if (_okfct != null)
      _okfct();
  }
  
  void startApplet() {
    //jsmeApplet = new JSApplet.JSME("jsme_container", "380px", "340px");
    jsmeApplet = new js.JsObject(js.context['JSApplet']['JSME'], ['jsme_container', '380px', '340px']);
    
    if (jmeString != null) {
      //jsmeApplet.readMolecule(jmeString);
      jsmeApplet.callMethod('readMolecule', [jmeString]);
    }
  }
  
  String getSMILES() {
    return jsmeApplet.callMethod('smiles');
  }
  
  String getJMEString() {
    return jsmeApplet.callMethod('jmeFile');
  }
}

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