javascript editor fixed

This commit is contained in:
Erik Amaru Ortiz
2011-01-25 22:38:27 +00:00
parent 6cdb6caf94
commit 98b67535df
3 changed files with 70 additions and 64 deletions

View File

@@ -25,9 +25,9 @@
*/
/**
* Author Erik Amaru Ortiz
* Date Aug 26th, 2009
* Description This class is a Dynaform handler for modify directly into file
* @author Erik Amaru Ortiz <erik@colosa.com>
* @date Aug 26th, 2009
* @description This class is a Dynaform handler for modify directly into file
* @package gulliver.system
*/
@@ -169,18 +169,32 @@ class dynaFormHandler
* @param array $childs_childs
* @return void
*/
function replace($replaced, $name, $attributes, $childs, $childs_childs=null)
function replace($replaced, $name, $attributes, $childs=null, $childs_childs=null)
{
$element = $this->root->getElementsByTagName($replaced)->item(0);
$this->root->replaceChild($this->dom->createElement($name), $element);
$newnode = $element = $this->root->getElementsByTagName($name)->item(0);
if( isset($attributes['#text']) ) {
$newnode->appendChild($this->dom->createTextNode($attributes['#text']));
unset($attributes['#text']);
}
if( isset($attributes['#cdata']) ) {
$newnode->appendChild($this->dom->createCDATASection($attributes['#cdata']));
unset($attributes['#cdata']);
}
foreach($attributes as $att_name => $att_value) {
$newnode->setAttribute($att_name, $att_value);
}
if(is_array($childs)){
foreach($childs as $child_name => $child_text) {
$newnode_child = $newnode->appendChild($this->dom->createElement($child_name));
if( is_string($child_text) )
$newnode_child->appendChild($this->dom->createTextNode($child_text));
else if( is_array($child_text) && isset($child_text['cdata']) )
$newnode_child->appendChild($this->dom->createCDATASection($child_text));
if($childs_childs != null and is_array($childs_childs)){
foreach($childs_childs as $cc) {
$ccmode = $newnode_child->appendChild($this->dom->createElement($cc['name']));
@@ -191,7 +205,7 @@ class dynaFormHandler
}
}
}
} else {
} else if( isset($childs) ){
$text_node = $childs;
$newnode->appendChild($this->dom->createTextNode($text_node));
}

View File

@@ -648,12 +648,18 @@ class dynaformEditorAjax extends dynaformEditor implements iDynaformEditorAjax
try {
$sCode = rtrim($sCode);
$file = G::decrypt( $A , URL_KEY );
$dbc2 = new DBConnection( PATH_DYNAFORM . $file . '.xml' ,'','','','myxml' );
/*$dbc2 = new DBConnection( PATH_DYNAFORM . $file . '.xml' ,'','','','myxml' );
$ses2 = new DBSession($dbc2);
$ses2->execute(G::replaceDataField("UPDATE dynaForm SET XMLNODE_VALUE = @@CODE WHERE XMLNODE_NAME = @@FIELDNAME ", array('FIELDNAME'=>$fieldName,'CODE'=>$sCode), "myxml" ));
*/
G::LoadSystem('dynaformhandler');
$dynaform = new dynaFormHandler(PATH_DYNAFORM."{$file}.xml");
$dynaform->replace($fieldName, $fieldName, Array('type'=>'javascript', '#cdata'=>$sCode));
return 0;
}
catch(Exception $e) {
} catch(Exception $e) {
return (array) $e;
}
}

View File

@@ -1,4 +1,6 @@
var xmlEditor = null;
var jsEditor = null;
var clientWinSize = null;
if (typeof(dynaformEditor)==="undefined")
@@ -59,15 +61,6 @@ var dynaformEditor={
url='dynaforms_Saveas';
popupWindow('Save as', url+'?DYN_UID='+this.dynUid+'&AA='+this.A , 500, 350);
},
/*
* @function close
* @author unknow
* @modifier Gustavo Cruz
* @desc this function handles the close of a dynaform editor window
* now whenever a dynaform window is close, if the form wasn't
* saved the function also delete the temporal *_tmp0.xml files
* discarding all the changes that were made, bug 3861.
*/
close:function()
{
var modified=this.ajax.is_modified(this.A,this.dynUid);
@@ -137,6 +130,7 @@ var dynaformEditor={
{
var field=getField("JS_LIST","dynaforms_JSEditor");
var code=this.getJSCode();
if (field.value)
{
var res=this.ajax.set_javascript(this.A,field.value,code.replace(/\+/g, '%2B'));
@@ -166,17 +160,11 @@ var dynaformEditor={
},
changeToXmlCode:function()
{
//to adecuate the view perspective @Neyek
content_div = getElementByPMClass('panel_content___processmaker')
content_div.style.overflow='auto';
this.refresh_xmlcode();
this.currentView="xmlcode";
//if (this.loadPressLoaded && !XMLCodePress)
//{
//startXMLCodePress(); -> removing codepress editor
//}
if( ! xmlEditor ) {
clientWinSize = getClientWindowSize();
@@ -216,9 +204,9 @@ var dynaformEditor={
var field=getField("JS_LIST","dynaforms_JSEditor");
var res=this.ajax.get_javascripts(this.A,field.value);
this.currentView="javascripts";
this.refreshJavascripts();
if(field.value!='' || typeof(res.aOptions[0])!='undefined'){
hideRowById('JS_TITLE');
showRowById('JS');
@@ -230,15 +218,25 @@ var dynaformEditor={
//this.currentView="javascripts";
//this.refreshJavascripts();
if (this.loadPressLoaded && !JSCodePress)
//if (this.loadPressLoaded && !JSCodePress)
if( ! jsEditor )
{
startJSCodePress();
clientWinSize = getClientWindowSize();
//startJSCodePress(); //
jsEditor = CodeMirror.fromTextArea('form[JS]', {
height: (clientWinSize.height - 120) + "px",
width: (_BROWSER.name == 'msie' ? '100%' : '98%'),
parserfile: ["tokenizejavascript.js", "parsejavascript.js"],
stylesheet: ["css/jscolors.css"],
path: "js/",
lineNumbers: true,
continuousScanning: 500
});
}
} else {
showRowById('JS_TITLE');
hideRowById('JS');
hideRowById('JS_LIST');
}
},
changeToProperties:function()
@@ -364,21 +362,24 @@ var dynaformEditor={
},
getJSCode:function()
{
if (JSCodePress)
//if (JSCodePress)
if(jsEditor)
{
return JSCodePress.getCode();
//return JSCodePress.getCode();
jsEditor.save();
return getField("JS","dynaforms_JSEditor").value;
}
else
{
xmlEditor.save();
return getField("JS","dynaforms_JSEditor").value;
}
},
setJSCode:function(newCode)
{
if (JSCodePress)
{
JSCodePress.setCode(newCode);
//JSCodePress.edit(newCode,"javascript");
//if (JSCodePress)
if( jsEditor ) {
jsEditor.setCode(newCode);
}
else
{
@@ -388,33 +389,18 @@ var dynaformEditor={
},
getXMLCode:function()
{
/*if (XMLCodePress)
{
return XMLCodePress.getCode();
}
else
{*/
//alert(getField("XML","dynaforms_XmlEditor").value);
if (xmlEditor) {
xmlEditor.save();
}
return getField("XML","dynaforms_XmlEditor").value;
//}
},
setXMLCode:function(newCode)
{
//if (XMLCodePress)
//{
//XMLCodePress.setCode(newCode);
//XMLCodePress.edit(newCode,"xmlform");
//}
if( xmlEditor )
{
if( xmlEditor ) {
xmlEditor.setCode(newCode);
}
else
{
} else {
var code = getField("XML","dynaforms_XmlEditor");
code.value = newCode;
//xmlEditor.toTextArea();
}
},
setEnableTemplate:function(value)
@@ -476,10 +462,10 @@ var dynaformEditor={
hideRowById('JS_TITLE');
showRowById('JS');
showRowById('JS_LIST');
if (this.loadPressLoaded && !JSCodePress)
{
startJSCodePress();
}
//if (this.loadPressLoaded && !JSCodePress)
//{
//startJSCodePress();
//}
}else{
showRowById('JS_TITLE');hideRowById('JS_LIST');hideRowById('JS');}