﻿

Type.registerNamespace("ScriptLibrary");

ScriptLibrary.GModuleInfo = function(element) {
    ScriptLibrary.GModuleInfo.initializeBase(this, [element]);
    
    ScriptLibrary.GModuleInfo.createProperty("gmi");
    //ScriptLibrary.GModuleInfo.createProperty("closeLink");
    //ScriptLibrary.GModuleInfo.createProperty("editLink");
    ScriptLibrary.GModuleInfo.createProperty("weditLink");
    ScriptLibrary.GModuleInfo.createProperty("Editable");
    
    //ScriptLibrary.GModuleInfo.createProperty("saveLink");
    //ScriptLibrary.GModuleInfo.createProperty("txtEditContent");
    ScriptLibrary.GModuleInfo.createProperty("TableName");
    ScriptLibrary.GModuleInfo.createProperty("ContentFieldName");
    ScriptLibrary.GModuleInfo.createProperty("KeyFieldName");
    ScriptLibrary.GModuleInfo.createProperty("KeyFieldValue");
//    ScriptLibrary.GModuleInfo.createProperty("ShowEditor");
    ScriptLibrary.GModuleInfo.createProperty("ShowHtml");
    ScriptLibrary.GModuleInfo.createProperty("withBorder");
    ScriptLibrary.GModuleInfo.createProperty("editorPath");


    ScriptLibrary.GModuleInfo.createProperty("ContentBackgroundColor");
    ScriptLibrary.GModuleInfo.createProperty("CaptionBackgroundColor");
    
    
}

ScriptLibrary.GModuleInfo.prototype = {
    initialize: function() {
        ScriptLibrary.GModuleInfo.callBaseMethod(this, 'initialize');
        
        if ( this._withBorder == true )
        {        
            RoundedTopElement(this._gmi,"#FFF",this._CaptionBackgroundColor);
            RoundedBottomElement(this._gmi,"#FFF",this._ContentBackgroundColor);
        }
        
		//$addHandlers(this._editLink, {'click':this._onEditLinkClicked}, this);
		//$addHandlers(this._closeLink, {'click':this._onCloseLinkClicked}, this);
		if ( this._Editable )
    		$addHandlers(this._weditLink, {'click':this._onWEditLinkClicked}, this);
		//$addHandlers(this._saveLink, {'click':this._onSaveLinkClicked}, this);
        
        // Add custom initialization here
    },
    dispose: function() {        
        //Add custom dispose actions here
        ScriptLibrary.GModuleInfo.callBaseMethod(this, 'dispose');
    },
/*    
	_onEditLinkClicked : function(e) {
	
		  e.preventDefault();
	      //var oEditor = FCKeditorAPI.GetInstance(this._txtEditContent.id);
	      //oEditor.SetHTML( this._ShowHtml.innerHTML ) ;
	      this._ShowHtml.style.display = 'none';
//	      this._ShowEditor.style.display = 'inline-block';
	      this._editLink.style.display = 'none';
	      this._saveLink.style.display = 'inline-block';
	      this._closeLink.style.display = 'inline-block';
	      this._weditLink.style.display = 'none';
	      
		                        
		  //alert(test);
	},
*/	
	_onWEditLinkClicked : function(e) {
	
		  e.preventDefault();
          //window.open('ModuleEditor.aspx?TN=' + this._TableName + '&CFN=' + this._ContentFieldName + '&UIDFN=' + this._KeyFieldName + '&UIDFV=' + this._KeyFieldValue); 
          
          window.open(this._editorPath + '?TN=' + this._TableName + '&CFN=' + this._ContentFieldName + '&UIDFN=' + this._KeyFieldName + '&UIDFV=' + this._KeyFieldValue); 
                          
	}
/*	
	_onCloseLinkClicked : function(e) {
	
		  e.preventDefault();
          this._ShowHtml.style.display = 'inline-block';
//	      this._ShowEditor.style.display = 'none';
	      this._weditLink.style.display = 'none';
	      this._editLink.style.display = 'inline-block';
	      this._weditLink.style.display = 'inline-block';
	      this._saveLink.style.display = 'none';
	      this._closeLink.style.display = 'none';
	},
	
	_onSaveLinkClicked : function(e) {
	
		  e.preventDefault();
	      //var oEditor = FCKeditorAPI.GetInstance(this._txtEditContent.id);
	      //this._ShowHtml.innerHTML = oEditor.GetHTML();
		  
		  ModuleContent.SaveModuleContent(
		                        this._TableName, 
		                        this._ContentFieldName, 
		                        this._ShowHtml.innerHTML, 
		                        this._KeyFieldName, 
		                        this._KeyFieldValue,
                				Function.createDelegate(this, this._onSaveContentComplete),
                				Function.createDelegate(this, this._onSaveContentFailed)	
		                        );
		  //alert(test);
	},
	_onSaveContentComplete : function(result) {
	
          this._ShowHtml.style.display = 'inline-block';
//	      this._ShowEditor.style.display = 'none';
//	      this._editLink.style.display = 'inline-block';
	      this._weditLink.style.display = 'inline-block';
//	      this._saveLink.style.display = 'none';
//	      this._closeLink.style.display = 'none';
	},

	_onSaveContentFailed : function(result) {
	      //this._txtEditContent.innerHTML = "Web method _onSaveContentComplete failed";  
	}
*/	
	
    	
}

ScriptLibrary.GModuleInfo.registerClass('ScriptLibrary.GModuleInfo', Sys.UI.Control);

if (typeof(Sys) !== 'undefined') Sys.Application.notifyScriptLoaded();





