﻿/* ------------------------------------------------------------------------ 
 * CSSnippetLink represents a client side page, holds editable, isdirty, etc.
 * ------------------------------------------------------------------------ */         
var CSSnippetLink = Class.create();

Object.extend(CSSnippetLink.prototype, {  

    initialize: function() 
	{
    },

    HandlerForSaveComplete: function(result, userContext)
    {
        if (result != null)
        {
            window.VDS$CSPage.SetPageDetails(result[0]);  
            
            var index = userContext - 1;
            var editSection = window.VDS$EditSections[index]; 
            editSection.SetSectionDetails(result[1]);   
            
            window.VDS$CSPage.mEditorRestorePoint.Select();                                                       
            RadEditor().control.pasteHtml(result[2].Tag);    
        }    
        
        window.VDS$CSPage.DisplayServerOperation(false);      
    },
        
    HandlerForSaveException: function(result, userContext)
    {   
        window.VDS$CSPage.DisplayServerOperation(false);  
        
        alert(result._message);        
        var index = userContext - 1;
        var editSection = window.VDS$EditSections[userContext];
        
        if (editSection == undefined)            
            return;                    
    },
    
    SaveResourceLink: function(resource, page, section)
    {
        window.VDS$CSPage.DisplayServerOperation(true);
                                         
        var snippet = new VDS.VWeb.ClientSideUI.SnippetLinkDTO();
        snippet.ChildDBID = resource.ChildDBID;
        snippet.ChildDOID = resource.ChildDOID;
        snippet.Url = resource.Url;
        snippet.Title = resource.Title;
                                                                                                                 
        VDS.VWeb.Services.WebContentService.SaveSnippetLink(page, section, snippet, 
            this.HandlerForSaveComplete, 
             this.HandlerForSaveException, section.Index);      
    }
});


