﻿/***********************************
    wm-rad.js
    Custom front-end commands for
    using RadControls in Colin.
 ***********************************/

// only load if a Telerik control is on the page
if (typeof Telerik != "undefined")
{
    // *** Editor ***
    if (typeof Telerik.Web.UI.Editor != "undefined")
    {
        Telerik.Web.UI.RadEditor.prototype.old_showDialog = Telerik.Web.UI.RadEditor.prototype.showDialog;
        Telerik.Web.UI.RadEditor.prototype.showDialog = function(name, args, callback)
        {
            if (name != "ImageManager")
            {
                this.old_showDialog(name, args, callback);
            }
            else
            {
               //Check if your dialog needs to be shown, or the original image manager should be called.
               //We assume it is your dialog to be called when there is no arguments.caller object!
               if (!arguments.caller)
               {
                    //Call your own dialog, and provide it with the original callback function!
                    //the function will take care to insert the returned image src in the dialog input field
                    alert("This function is unavailable.\n\nPlease add your image using the File Repository button before editing it here.");             
               }
               else this.old_showDialog(name, args, callback);
            }
        }
    
        // CustomImageManager button
        Telerik.Web.UI.Editor.CommandList["CustomImageManager"] = function(commandName, editor, args)
        {
            // open the Image Manager
            Editor_ImageManager();
        };
        
        // CustomLinkManager button
        Telerik.Web.UI.Editor.CommandList["CustomLinkManager"] = function(commandName, editor, args)
        {
            // open the Image Manager
            Editor_LinkManager();
        };
        
        // CustomDocumentManager button
        Telerik.Web.UI.Editor.CommandList["CustomDocumentManager"] = function(commandName, editor, args)
        {
            // open the Image Manager
            Editor_DocumentManager();
        };
    
        // Cancel button
        Telerik.Web.UI.Editor.CommandList["Cancel"] = function(commandName, editor, args)
        {
            // call cancel
            eval("Cancel_"+editor.get_id()+"();");
        };
        
        // Save button
        Telerik.Web.UI.Editor.CommandList["Save"] = function(commandName, editor, args)
        {
            // populate hidden  
            document.getElementById("radSave").value = editor.get_html(true);
            // call savenode
            eval("SaveNode();");
        };
        
        // Save progress button
        Telerik.Web.UI.Editor.CommandList["SaveProgress"] = function(commandName, editor, args)
        {
            // populate hidden  
            document.getElementById("radSave").value = editor.get_html(true);
            // call savenode
            eval("SaveProgress_"+editor.get_id()+"();");
        };
        
        //MyModule.registerClass('MyModule', Telerik.Web.UI.Editor.Modules.ModuleBase);
    }
    
    /*
    // *** Another Control ***
    if (typeof Telerik.Web.UI.??? != "undefined")
    {
        // do stuff
    }
    */

}
