﻿<!--
    function userCommentEditorComponent(commentedUserId, applicationSubPath) {    
        this.commentedUserId = commentedUserId;
        this.applicationSubPath = applicationSubPath;
        function show() {
            openDiv('divUserCommentEditor');
            //focus
            document.getElementById('taUserCommentBody').focus();
        }
        
        function hide() {
            closeDiv('divUserCommentEditor');
        }
        
        function add() {  
            var eleUserCommentBody = document.getElementById('taUserCommentBody');

            if (eleUserCommentBody.value.length == 0 || eleUserCommentBody.value == null) {                
                alert('Proszę wprowadzić komentarz.');
                eleUserCommentBody.focus();
                return;
            }  
        
            if (eleUserCommentBody.value.length >= 1000) {                
                alert('Komentarz nie może być dłuższy niż 1000 znaków.');
                eleUserCommentBody.focus();
                return;
            }  

            document.getElementById('btnUserCommentAdd').disabled = 'true';
            wsComponent.sendRequest(applicationSubPath + '/Portal/WebServices/UserCommentService.asmx', 'Add', '<commentedUserId>' + commentedUserId + '</commentedUserId><body>' + encodeURIComponent(eleUserCommentBody.value) + '</body>', true, wsComponent.execOnSuccess(addCallback));
        }
        
        function addCallback(xmlHttpReq) {
            document.getElementById('btnUserCommentAdd').disabled = '';
            if (wsComponent.getNodeValue(xmlHttpReq, 'AddResult') == 'true') {
                hide();
                document.getElementById('taUserCommentBody').value = '';
                retrieve();
                alert('Dodano nowy komentarz.');            
            } else {
                alert('Wystąpił błąd.');
            }            
        }
        
        function retrieve() {  
            wsComponent.sendRequest(applicationSubPath + '/Portal/WebServices/UserCommentService.asmx', 'Get', '<commentedUserId>' + commentedUserId + '</commentedUserId>', 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('divUserCommentViewer').innerHTML = nodeValue;                
            }            
        }
    
        this.show = show;
        this.hide = hide;
        this.add = add;
        this.retrieve = retrieve;
    }   
//-->
