Back to PhocaGalleryCommentImage class

Method renderCommentImageJS

public static
renderCommentImageJS
()

Method renderCommentImageJS - Source code

public static function renderCommentImageJS()
{
    // We only use refresh task (it means to get answer)
    // pgRequest uses pgRequestRefresh site
    $document = Factory::getDocument();
    $url = 'index.php?option=com_phocagallery&view=commentimga&task=commentimg&format=json&' . Session::getFormToken() . '=1';
    $urlRefresh = 'index.php?option=com_phocagallery&view=commentimga&task=refreshcomment&format=json&' . Session::getFormToken() . '=1';
    $imgLoadingUrl = Uri::base() . 'media/com_phocagallery/images/icon-loading3.gif';
    $imgLoadingHTML = '<img src="' . $imgLoadingUrl . '" alt="" />';
    //$js  = '<script type="text/javascript">' . "\n";
    //$js .= 'window.addEvent("domready",function() {
    $js = '
		function pgCommentImage(id, m, container) {
		
			var result 			= "#pg-cv-comment-img-box-result" + id;
			
			var commentTxtArea	= "#pg-cv-comments-editor-img" + id;
			var comment			= jQuery(commentTxtArea).val();
			data = {"commentId": id, "commentValue": comment, "format":"json"};
			
			pgRequest = jQuery.ajax({
                type: "POST",
                url: "' . $urlRefresh . '",
                async: "false",
                cache: "false",
                data: data,
                dataType:"JSON",
                
                beforeSend: function(){
                    jQuery(result).html("' . addslashes($imgLoadingHTML) . '");
                    if (m == 2) {
                        var wall = new Masonry(document.getElementById(container));
                    }
                },
                
                success: function(data){
                    if (data.status == 1){
                        jQuery(result).html(data.message);
                    } else if(data.status == 0){
                        jQuery(result).html(data.error);
                    } else {
                        jQuery(result).text("' . Text::_('COM_PHOCAGALLERY_ERROR_REQUESTING_ITEM') . '");
                    }
                    
                    if (m == 2) {
					    var wall = new Masonry(document.getElementById(container));
				    }
                },
                
                error: function(){
                    jQuery(result).text( "' . Text::_('COM_PHOCAGALLERY_ERROR_REQUESTING_ITEM') . '");
				
				    if (m == 2) {
					    var wall = new Masonry(document.getElementById(container));
				    }
                }

            })
        }';
    $document->addScriptDeclaration($js);
    //})';
    /*
    			if (r) {
    					if (r.error == false) {
    jQuery(result).set("html", jsonObj.message);
    					} else {
    jQuery(result).set("html", r.error);
    					}
    				} else {
    					jQuery(result).set("text", "'.Text::_('COM_PHOCAGALLERY_ERROR_REQUESTING_ITEM').'");
    				}
    
    				if (m == 2) {
    					var wall = new Masonry(document.getElementById(container));
    				}
    
    
    
    			var pgRequest = new Request.JSON({
    			url: "'.$urlRefresh.'",
    			method: "post",
    
    			onRequest: function(){
    				jQuery(result).set("html", "'.addslashes($imgLoadingHTML).'");
    				if (m == 2) {
    					var wall = new Masonry(document.getElementById(container));
    				}
    			  },
    
    			onComplete: function(jsonObj) {
    				try {
    					var r = jsonObj;
    				} catch(e) {
    					var r = false;
    				}
    
    				if (r) {
    					if (r.error == false) {
    jQuery(result).set("html", jsonObj.message);
    					} else {
    jQuery(result).set("html", r.error);
    					}
    				} else {
    					jQuery(result).set("text", "'.Text::_('COM_PHOCAGALLERY_ERROR_REQUESTING_ITEM').'");
    				}
    
    				if (m == 2) {
    					var wall = new Masonry(document.getElementById(container));
    				}
    			},
    
    			onFailure: function() {
    				jQuery(result).set("text", "'.Text::_('COM_PHOCAGALLERY_ERROR_REQUESTING_ITEM').'");
    
    				if (m == 2) {
    					var wall = new Masonry(document.getElementById(container));
    				}
    			}
    
    			})
    
    			pgRequest.send({
    				data: {"commentId": id, "commentValue": comment, "format":"json"},
    			});
    
    		};';
    
    		//$js .= '});';
    
    
    		/*
    		var resultcomment 	= "pg-cv-comment-img-box-newcomment" + id;
    		// Refreshing Voting
    var pgRequestRefresh = new Request.JSON({
    	url: "'.$urlRefresh.'",
    	method: "post",
    
    	onComplete: function(json2Obj) {
    		try {
    			var rr = json2Obj;
    		} catch(e) {
    			var rr = false;
    		}
    
    		if (rr) {
    			$(resultcomment).set("html", json2Obj.message);
    		} else {
    			$(resultcomment).set("text", "'.Text::_('COM_PHOCAGALLERY_ERROR_REQUESTING_ITEM').'");
    		}
    	},
    
    	onFailure: function() {
    		$(resultcomment).set("text", "'.Text::_('COM_PHOCAGALLERY_ERROR_REQUESTING_ITEM').'");
    	}
    })
    
    pgRequestRefresh.send({
    	data: {"commentId": id, "commentValue": comment, "format":"json"}
    });
    //End refreshing comments
    */
    //$js .= "\n" .'</script>';
}