﻿<!--
    function communityCommentComponent(communityId, mediaId, applicationSubPath) {    
        this.communityId = communityId;
        this.mediaId = mediaId;
        this.applicationSubPath = applicationSubPath;
        function show() {
            openDiv('divCommentEditor');
            //focus
            document.getElementById('taCommentBody').focus();
        }
        
        function hide() {
            closeDiv('divCommentEditor');
        }
        
        function add() {  
            var eleCommentBody = document.getElementById('taCommentBody');

            if (eleCommentBody.value.length == 0 || eleCommentBody.value == null) {                
                alert('Proszę wprowadzić komentarz.');
                eleCommentBody.focus();
                return;
            }  
        
            if (eleCommentBody.value.length > 1000) {                
                alert('Komentarz nie może być dłuższy niż 1000 znaków.');
                eleCommentBody.focus();
                return;
            }  

            document.getElementById('btnCommentAdd').disabled = 'true';
            wsComponent.sendRequest(applicationSubPath + '/Community/WebServices/CommentService.asmx', 'Add', '<mediaId>' + mediaId + '</mediaId><body>' + encodeURIComponent(eleCommentBody.value) + '</body>', true, wsComponent.execOnSuccess(addCallback));
        }
        
        
        function addCallback(xmlHttpReq) {
            document.getElementById('btnCommentAdd').disabled = '';
            if (wsComponent.getNodeValue(xmlHttpReq, 'AddResult') == 'Accepted') {
                hide();
                document.getElementById('taCommentBody').value = '';
                retrieve('false');
            } else if (wsComponent.getNodeValue(xmlHttpReq, 'AddResult') == 'Waiting') {
                hide();
                document.getElementById('taCommentBody').value = '';
                alert('Komentarz oczekuje na moderację.');
            } else {
                alert('Wystąpił błąd.');
            }        
        }               
        
        function retrieve(all) {  
            wsComponent.sendRequest(applicationSubPath + '/Community/WebServices/CommentService.asmx', 'Get', '<communityId>' + communityId + '</communityId><mediaId>' + mediaId + '</mediaId><all>' + all + '</all>', 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('divCommentViewer').innerHTML = nodeValue;                
            }              
        }
        
        this.show = show;
        this.hide = hide;
        this.add = add;
        this.retrieve = retrieve;
    }   
//-->

