function CUEditor_Type()
{
this.CurrentEditor = null;
this.Open = function( url )
{
this.Close();
var a = document.createElement( 'iframe' );
this.CurrentEditor = a;
var sz = getWindowSize();
var scr = getScrollXY();
a.setAttribute('class', 'cui_editor');
a.setAttribute('className', 'cui_editor');
a.style.left = ( sz[0] * 0.2 + scr[0] ) + "px";
a.style.top = ( sz[1] * 0.2 + scr[1] ) + "px";
a.style.width = ( sz[0] * 0.6 ) + "px";
a.style.height = ( sz[1] * 0.6 ) + "px";
var overlay = document.createElement( 'div' );
overlay.setAttribute( 'class', 'cui_overlay' );
overlay.setAttribute( 'className', 'cui_overlay' );
a.Overlay = overlay;
var splash = document.createElement( 'div' );
splash.style.left = a.style.left; splash.style.top = a.style.top;
splash.style.width = a.style.width; splash.style.height = a.style.height;
splash.setAttribute( 'class', 'cui_splash' );
splash.setAttribute( 'className', 'cui_splash' );
splash.innerHTML = "
Loading...";
a.Splash = splash;
document.body.appendChild( splash );
document.body.appendChild( overlay );
document.body.appendChild( a );
a.src = url;
return a;
};
this.OnEditorLoaded = function()
{
document.body.removeChild( CUEditor.CurrentEditor.Splash );
CUEditor.CurrentEditor.Splash = null;
};
this.Close = function( successfull )
{
var a = this.CurrentEditor;
this.CurrentEditor = null;
if ( !a ) return;
a.style.display = 'none';
if ( a.Overlay ) document.body.removeChild( a.Overlay );
if ( a.Splash ) document.body.removeChild( a.Splash );
if ( a.OnClosed ) a.OnClosed( successfull );
setTimeout( 3000, function() { document.body.removeChild( a ); } );
};
}
var CUEditor = new CUEditor_Type();
function openWikiBlockEditor( htmlElement, entityDefinition, blockId, handler )
{
var ed = CUEditor.Open( "/clientui/showEditor.aspx?id=" + blockId + "&entity=" + entityDefinition.EntityName + "&control=" + entityDefinition.ControlPath );
ed.OnClosed = handler;
}
function editWikiBlock( htmlElement, entityDefinition, blockId, callback )
{
openWikiBlockEditor( htmlElement, entityDefinition, blockId,
function( successfull ) {
ping( getEntityTextPath( entityDefinition, blockId ),
( !htmlElement && !callback ) ? null : function( text ) {
if ( callback ) callback( successfull );
if ( htmlElement ) htmlElement.innerHTML = text;
}
);
}
);
}
function createWikiBlock( htmlElement, entityDefinition, menuFunction, callback )
{
openWikiBlockEditor( htmlElement, entityDefinition, "",
function( modalResult, id ) {
if ( !htmlElement )
{
if ( callback ) callback();
return;
}
if ( !id )
{
return;
}
ping( getEntityTextPath( entityDefinition, id ),
function( text ) {
if ( callback ) callback();
var parent = htmlElement.parentElement;
var span = document.createElement( "span" );
span.onmouseover = function() { menuFunction( span, id ) };
span.innerHTML = text;
parent.insertBefore( span, htmlElement );
}
);
}
);
}
function getEntityTextPath( entityDefinition, blockId )
{
var entityName = entityDefinition.EntityName;
var controlPath = entityDefinition.ControlPath;
if ( controlPath != '' )
{
controlPath = "&control=" + controlPath;
}
if ( entityDefinition.HasSeparator )
{
controlPath += "&includeSeparator=1";
}
return "/clientUI/getEntityText.aspx?entity=" + entityName + "&id=" + blockId + controlPath;
}
function deleteWikiBlock( htmlElement, entityDefinition, blockId, callback )
{
ping( '/clientui/deleteEntity.aspx?entity=' + entityDefinition.EntityName + '&id=' + blockId,
function( text )
{
if ( callback ) callback();
var parent = htmlElement.parentElement;
parent.removeChild( htmlElement );
}
);
}