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

View File

@@ -648,12 +648,18 @@ class dynaformEditorAjax extends dynaformEditor implements iDynaformEditorAjax
try { try {
$sCode = rtrim($sCode); $sCode = rtrim($sCode);
$file = G::decrypt( $A , URL_KEY ); $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 = new DBSession($dbc2);
$ses2->execute(G::replaceDataField("UPDATE dynaForm SET XMLNODE_VALUE = @@CODE WHERE XMLNODE_NAME = @@FIELDNAME ", array('FIELDNAME'=>$fieldName,'CODE'=>$sCode), "myxml" )); $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; return 0;
} } catch(Exception $e) {
catch(Exception $e) {
return (array) $e; return (array) $e;
} }
} }

View File

@@ -1,4 +1,6 @@
var xmlEditor = null; var xmlEditor = null;
var jsEditor = null;
var clientWinSize = null; var clientWinSize = null;
if (typeof(dynaformEditor)==="undefined") if (typeof(dynaformEditor)==="undefined")
@@ -59,15 +61,6 @@ var dynaformEditor={
url='dynaforms_Saveas'; url='dynaforms_Saveas';
popupWindow('Save as', url+'?DYN_UID='+this.dynUid+'&AA='+this.A , 500, 350); 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() close:function()
{ {
var modified=this.ajax.is_modified(this.A,this.dynUid); var modified=this.ajax.is_modified(this.A,this.dynUid);
@@ -118,7 +111,7 @@ var dynaformEditor={
}, },
saveXmlCode:function() saveXmlCode:function()
{ {
// var xmlCode = getField("XML").value; //var xmlCode = getField("XML").value;
var xmlCode = this.getXMLCode(); var xmlCode = this.getXMLCode();
var todoRefreshXmlCode = xmlCode === null; var todoRefreshXmlCode = xmlCode === null;
if (todoRefreshXmlCode) return; if (todoRefreshXmlCode) return;
@@ -137,6 +130,7 @@ var dynaformEditor={
{ {
var field=getField("JS_LIST","dynaforms_JSEditor"); var field=getField("JS_LIST","dynaforms_JSEditor");
var code=this.getJSCode(); var code=this.getJSCode();
if (field.value) if (field.value)
{ {
var res=this.ajax.set_javascript(this.A,field.value,code.replace(/\+/g, '%2B')); var res=this.ajax.set_javascript(this.A,field.value,code.replace(/\+/g, '%2B'));
@@ -166,17 +160,11 @@ var dynaformEditor={
}, },
changeToXmlCode:function() changeToXmlCode:function()
{ {
//to adecuate the view perspective @Neyek
content_div = getElementByPMClass('panel_content___processmaker') content_div = getElementByPMClass('panel_content___processmaker')
content_div.style.overflow='auto'; content_div.style.overflow='auto';
this.refresh_xmlcode(); this.refresh_xmlcode();
this.currentView="xmlcode"; this.currentView="xmlcode";
//if (this.loadPressLoaded && !XMLCodePress)
//{
//startXMLCodePress(); -> removing codepress editor
//}
if( ! xmlEditor ) { if( ! xmlEditor ) {
clientWinSize = getClientWindowSize(); clientWinSize = getClientWindowSize();
@@ -216,9 +204,9 @@ var dynaformEditor={
var field=getField("JS_LIST","dynaforms_JSEditor"); var field=getField("JS_LIST","dynaforms_JSEditor");
var res=this.ajax.get_javascripts(this.A,field.value); var res=this.ajax.get_javascripts(this.A,field.value);
this.currentView="javascripts"; this.currentView="javascripts";
this.refreshJavascripts(); this.refreshJavascripts();
if(field.value!='' || typeof(res.aOptions[0])!='undefined'){ if(field.value!='' || typeof(res.aOptions[0])!='undefined'){
hideRowById('JS_TITLE'); hideRowById('JS_TITLE');
showRowById('JS'); showRowById('JS');
@@ -230,15 +218,25 @@ var dynaformEditor={
//this.currentView="javascripts"; //this.currentView="javascripts";
//this.refreshJavascripts(); //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{ } else {
showRowById('JS_TITLE'); showRowById('JS_TITLE');
hideRowById('JS'); hideRowById('JS');
hideRowById('JS_LIST'); hideRowById('JS_LIST');
} }
}, },
changeToProperties:function() changeToProperties:function()
@@ -364,21 +362,24 @@ var dynaformEditor={
}, },
getJSCode:function() getJSCode:function()
{ {
if (JSCodePress) //if (JSCodePress)
if(jsEditor)
{ {
return JSCodePress.getCode(); //return JSCodePress.getCode();
jsEditor.save();
return getField("JS","dynaforms_JSEditor").value;
} }
else else
{ {
xmlEditor.save();
return getField("JS","dynaforms_JSEditor").value; return getField("JS","dynaforms_JSEditor").value;
} }
}, },
setJSCode:function(newCode) setJSCode:function(newCode)
{ {
if (JSCodePress) //if (JSCodePress)
{ if( jsEditor ) {
JSCodePress.setCode(newCode); jsEditor.setCode(newCode);
//JSCodePress.edit(newCode,"javascript");
} }
else else
{ {
@@ -388,33 +389,18 @@ var dynaformEditor={
}, },
getXMLCode:function() getXMLCode:function()
{ {
/*if (XMLCodePress) if (xmlEditor) {
{
return XMLCodePress.getCode();
}
else
{*/
//alert(getField("XML","dynaforms_XmlEditor").value);
xmlEditor.save(); xmlEditor.save();
}
return getField("XML","dynaforms_XmlEditor").value; return getField("XML","dynaforms_XmlEditor").value;
//}
}, },
setXMLCode:function(newCode) setXMLCode:function(newCode)
{ {
//if (XMLCodePress) if( xmlEditor ) {
//{
//XMLCodePress.setCode(newCode);
//XMLCodePress.edit(newCode,"xmlform");
//}
if( xmlEditor )
{
xmlEditor.setCode(newCode); xmlEditor.setCode(newCode);
} } else {
else var code = getField("XML","dynaforms_XmlEditor");
{ code.value = newCode;
var code=getField("XML","dynaforms_XmlEditor");
code.value=newCode;
//xmlEditor.toTextArea();
} }
}, },
setEnableTemplate:function(value) setEnableTemplate:function(value)
@@ -476,10 +462,10 @@ var dynaformEditor={
hideRowById('JS_TITLE'); hideRowById('JS_TITLE');
showRowById('JS'); showRowById('JS');
showRowById('JS_LIST'); showRowById('JS_LIST');
if (this.loadPressLoaded && !JSCodePress) //if (this.loadPressLoaded && !JSCodePress)
{ //{
startJSCodePress(); //startJSCodePress();
} //}
}else{ }else{
showRowById('JS_TITLE');hideRowById('JS_LIST');hideRowById('JS');} showRowById('JS_TITLE');hideRowById('JS_LIST');hideRowById('JS');}