﻿<!--
    function commentComponent(mediaId, applicationSubPath) {    
        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 + '/Portal/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') == 'true') {
                hide();
                document.getElementById('taCommentBody').value = '';
                retrieve('false');
                alert('Dodano nowy komentarz.');                
            } else {
                alert('Wystąpił błąd.');
            }        
        }                     
        
        function retrieve(all) {  
            wsComponent.sendRequest(applicationSubPath + '/Portal/WebServices/CommentService.asmx', 'Get', '<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;
    }   
//-->
