// Copyright (c) 2012 Web Notes Technologies Pvt Ltd (http://erpnext.com) // // MIT License (MIT) // // Permission is hereby granted, free of charge, to any person obtaining a // copy of this software and associated documentation files (the "Software"), // to deal in the Software without restriction, including without limitation // the rights to use, copy, modify, merge, publish, distribute, sublicense, // and/or sell copies of the Software, and to permit persons to whom the // Software is furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A // PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF // CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE // OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // // // Form Input // ====================================================================================== _f.ColumnBreak = function() { this.set_input = function() { }; } _f.ColumnBreak.prototype.make_body = function() { this.cell = this.frm.layout.addcell(this.df.width); $y(this.cell.wrapper, {padding: '8px'}); _f.cur_col_break_width = this.df.width; var fn = this.df.fieldname || this.df.label; // header if(this.df&&this.df.label){ this.label = $a(this.cell.wrapper, 'h4', '', '', wn._(this.df.label)); if(this.df.description) $('
").appendTo(this.input_area).get(0); this.input = {}; this.myid = wn.dom.set_unique_id(this.pre); this.editor = ace.edit(this.myid); if(me.df.options=='Markdown' || me.df.options=='HTML') { wn.require('lib/js/lib/ace/mode-html.js'); var HTMLMode = require("ace/mode/html").Mode; me.editor.getSession().setMode(new HTMLMode()); } else if(me.df.options=='Javascript') { wn.require('lib/js/lib/ace/mode-javascript.js'); var JavascriptMode = require("ace/mode/javascript").Mode; me.editor.getSession().setMode(new JavascriptMode()); } else if(me.df.options=='Python') { wn.require('lib/js/lib/ace/mode-python.js'); var PythonMode = require("ace/mode/python").Mode; me.editor.getSession().setMode(new PythonMode()); } this.input.set_input = function(v) { // during field refresh in run trigger, set_input is called // if called during on_change, setting doesn't make sense // and causes cursor to shift back to first position if(me.changing_value) return; me.setting_value = true; me.editor.getSession().setValue(v==null ? "" : v); me.setting_value = false; } this.get_value = function() { return me.editor.getSession().getValue(); // tinyMCE } $(cur_frm.wrapper).bind('render_complete', function() { me.editor.resize(); me.editor.getSession().on('change', function() { if(me.setting_value) return; var val = me.get_value(); if(locals[cur_frm.doctype][cur_frm.docname][me.df.fieldname] != val) { me.set(me.get_value()); me.changing_value = true; me.run_trigger(); me.changing_value = false; } }) }); this.onrefresh = function() { me.editor && me.editor.resize(); } } } _f.CodeField.prototype.init_editor = function() { // attach onchange methods var me = this; this.editor = tinymce.get(this.myid); this.editor.onKeyUp.add(function(ed, e) { me.set(ed.getContent()); }); this.editor.onPaste.add(function(ed, e) { me.set(ed.getContent()); }); this.editor.onSetContent.add(function(ed, e) { me.set(ed.getContent()); }); // reset content var c = locals[cur_frm.doctype][cur_frm.docname][this.df.fieldname]; if(cur_frm && c) { this.editor.setContent(c); } } _f.CodeField.prototype.set_disp = function(val) { $y(this.disp_area, {width:'90%'}) if(this.df.fieldtype=='Text Editor') { this.disp_area.innerHTML = val; } else { this.disp_area.innerHTML = ''; } } // ======================================================================================