|
|
@@ -5,6 +5,7 @@ MWF.CMSDD = MWF.xApplication.cms.DictionaryDesigner;
|
|
|
MWF.require("MWF.widget.Common", null, false);
|
|
|
MWF.xDesktop.requireApp("cms.DictionaryDesigner", "lp."+MWF.language, null, false);
|
|
|
MWF.xDesktop.requireApp("Selector", "package", null, false);
|
|
|
+MWF.require("MWF.widget.JavascriptEditor", null, false);
|
|
|
MWF.xApplication.cms.DictionaryDesigner.Dictionary = new Class({
|
|
|
Extends: MWF.widget.Common,
|
|
|
Implements: [Options, Events],
|
|
|
@@ -68,19 +69,13 @@ MWF.xApplication.cms.DictionaryDesigner.Dictionary = new Class({
|
|
|
this.scriptPage = this.designTab.addTab(this.designTabScriptAreaNode, "JSON");
|
|
|
this.designPage.showTabIm = function(callback){
|
|
|
if( _self.scriptEditor && _self.isChanged){
|
|
|
- try{
|
|
|
- var value = _self.scriptEditor.getValue();
|
|
|
- var v = JSON.parse(value);
|
|
|
-
|
|
|
+ if( _self.getEditorValidData() !== false ){
|
|
|
if (!this.isShow){
|
|
|
this.tab.pages.each(function(page){
|
|
|
if (page.isShow) page.hideIm();
|
|
|
});
|
|
|
this.showIm(callback);
|
|
|
}
|
|
|
-
|
|
|
- }catch (e) {
|
|
|
- _self.designer.notice( _self.designer.lp.notice.jsonParseError, "error", _self.node, {"x": "left", "y": "bottom"});
|
|
|
}
|
|
|
}else{
|
|
|
if (!this.isShow){
|
|
|
@@ -106,18 +101,53 @@ MWF.xApplication.cms.DictionaryDesigner.Dictionary = new Class({
|
|
|
}.bind(this));
|
|
|
this.designPage.addEvent("postShow", function(){
|
|
|
if( this.scriptEditor && this.isChanged){
|
|
|
- try{
|
|
|
- var value = this.scriptEditor.getValue();
|
|
|
- this.data.data = JSON.parse(value);
|
|
|
+ var data = this.getEditorValidData();
|
|
|
+ if( data !== false ){
|
|
|
+ this.data.data = data;
|
|
|
this.reload();
|
|
|
this.isChanged = false;
|
|
|
- }catch (e) {
|
|
|
- this.designer.notice( this.designer.lp.notice.jsonParseError, "error", this.node, {"x": "left", "y": "bottom"});
|
|
|
}
|
|
|
}
|
|
|
this.fireEvent("resize");
|
|
|
}.bind(this));
|
|
|
},
|
|
|
+ getEditorValidData : function( silence ){
|
|
|
+ if( !this.scriptEditor.validated() ){
|
|
|
+ if(!silence)this.designer.notice( this.designer.lp.notice.editorNotValidated, "error", this.node, {"x": "left", "y": "bottom"});
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ try{
|
|
|
+ var value = this.scriptEditor.getValue();
|
|
|
+ var v = JSON.parse(value);
|
|
|
+ if( !this.checkValid(v, silence) ){
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ return v;
|
|
|
+ }catch (e) {
|
|
|
+ if(!silence)this.designer.notice( this.designer.lp.notice.jsonParseError, "error", this.node, {"x": "left", "y": "bottom"});
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ },
|
|
|
+ checkValid( obj, silence ){
|
|
|
+ if( typeOf(obj) !== "object" ){
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ for (var key in obj) {
|
|
|
+ if( !key || key.trim() === "" ){
|
|
|
+ if(!silence)this.designer.notice(this.designer.lp.notice.emptyObjectKey, "error", this.node, {"x": "left", "y": "bottom"});
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ if (!isNaN(parseFloat(key))){
|
|
|
+ if(!silence)this.designer.notice(this.designer.lp.notice.numberObjectKey, "error", this.node, {"x": "left", "y": "bottom"});
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ if( typeOf(obj[key]) === "object" ){
|
|
|
+ if( !this.checkValid( obj[key] ) )return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ },
|
|
|
loadScriptEditor:function(){
|
|
|
var value = JSON.stringify(this.data.data, null, "\t");
|
|
|
this.scriptEditor = new MWF.widget.JavascriptEditor(this.scriptNode, {"option": {"value": value, "mode" : "json" }});
|
|
|
@@ -242,10 +272,11 @@ MWF.xApplication.cms.DictionaryDesigner.Dictionary = new Class({
|
|
|
|
|
|
if( this.scriptPage.isShow ){
|
|
|
if( this.scriptEditor ){
|
|
|
- try{
|
|
|
- var value = this.scriptEditor.getValue();
|
|
|
- this.data.data = JSON.parse(value);
|
|
|
- }catch (e) {
|
|
|
+
|
|
|
+ var data = this.getEditorValidData( true );
|
|
|
+ if( data !== false ){
|
|
|
+ this.data.data = data;
|
|
|
+ }else{
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
|
@@ -283,11 +314,10 @@ MWF.xApplication.cms.DictionaryDesigner.Dictionary = new Class({
|
|
|
|
|
|
if( this.scriptPage.isShow ){
|
|
|
if( this.scriptEditor ){
|
|
|
- try{
|
|
|
- var value = this.scriptEditor.getValue();
|
|
|
- this.data.data = JSON.parse(value);
|
|
|
- }catch (e) {
|
|
|
- this.designer.notice( this.designer.lp.notice.jsonParseError, "error", this.node, {"x": "left", "y": "bottom"});
|
|
|
+ var data = this.getEditorValidData();
|
|
|
+ if( data !== false ){
|
|
|
+ this.data.data = data;
|
|
|
+ }else{
|
|
|
return false;
|
|
|
}
|
|
|
}
|