﻿<!--
    function communityBlogEntryCommentComponent(communityId, blogEntryId, applicationSubPath) {
        this.communityId = communityId;
        this.blogEntryId = blogEntryId;
        this.applicationSubPath = applicationSubPath;
        
        function show() {
            openDiv('divBlogEntryCommentEditor');
            //focus
            document.getElementById('taBlogEntryCommentBody').focus();
        }
        
        function hide() {
            closeDiv('divBlogEntryCommentEditor');
        }
        
        function add() {  
            var eleBlogEntryCommentBody = document.getElementById('taBlogEntryCommentBody');

            if (eleBlogEntryCommentBody.value.length == 0 || eleBlogEntryCommentBody.value == null) {                
                alert('Proszę wprowadzić komentarz.');
                eleBlogEntryCommentBody.focus();
                return;
            }  
        
            if (eleBlogEntryCommentBody.value.length > 1000) {                
                alert('Komentarz nie może być dłuższy niż 1000 znaków.');
                eleBlogEntryCommentBody.focus();
                return;
            }  

            document.getElementById('btnBlogEntryCommentAdd').disabled = 'true';
            wsComponent.sendRequest(applicationSubPath + '/Portal/WebServices/CommunityBlogEntryCommentService.asmx', 'Add', '<blogEntryId>' + blogEntryId + '</blogEntryId><body>' + encodeURIComponent(eleBlogEntryCommentBody.value) + '</body>', true, wsComponent.execOnSuccess(addCallback));
        }
        
        function addCallback(xmlHttpReq) {
            document.getElementById('btnBlogEntryCommentAdd').disabled = '';
            if (wsComponent.getNodeValue(xmlHttpReq, 'AddResult') == 'Accepted') {
                hide();
                document.getElementById('taBlogEntryCommentBody').value = '';
                retrieve();
            } else if (wsComponent.getNodeValue(xmlHttpReq, 'AddResult') == 'Waiting') {
                hide();
                document.getElementById('taBlogEntryCommentBody').value = '';
                alert('Komentarz oczekuje na moderację.');
            } else {
                alert('Wystąpił błąd.');
            }  
        }
        
        function retrieve() {  
            wsComponent.sendRequest(applicationSubPath + '/Portal/WebServices/CommunityBlogEntryCommentService.asmx', 'Get', '<communityId>' + communityId + '</communityId><blogEntryId>' + blogEntryId + '</blogEntryId>', true, wsComponent.execOnSuccess(retrieveCallback));
        }
        
        function retrieveCallback(xmlHttpReq) {
            nodeValue = wsComponent.getNodeValue(xmlHttpReq, 'GetResult').replace(/&lt;/g, '<').replace(/&gt;/g, '>').replace(/&amp;/g, '&');
            if (nodeValue != null && nodeValue != '') {
                document.getElementById('divBlogEntryCommentViewer').innerHTML = nodeValue;                
            }            
        }
    
        this.show = show;
        this.hide = hide;
        this.add = add;
        this.retrieve = retrieve;
    }   
//-->

