remove nested forms from moderate comments view. rewrite jquery code for comment delete and publish.
svn path=/plone.app.discussion/trunk/; revision=27750
This commit is contained in:
		
							parent
							
								
									15b7347626
								
							
						
					
					
						commit
						2e04461162
					
				@ -3,47 +3,78 @@ jq(document).ready(function() {
 | 
			
		||||
    /*****************************************************************
 | 
			
		||||
     * Check or uncheck all checkboxes
 | 
			
		||||
     *****************************************************************/
 | 
			
		||||
	jq("input[name='check_all']").click(function(){
 | 
			
		||||
	      if(jq(this).val()==0){
 | 
			
		||||
	        jq(this).parents("table")
 | 
			
		||||
	               .find("input:checkbox")
 | 
			
		||||
	               .attr("checked","checked");
 | 
			
		||||
		    jq(this).val("1");
 | 
			
		||||
	      }
 | 
			
		||||
	      else{
 | 
			
		||||
	        jq(this).parents("table")
 | 
			
		||||
	               .find("input:checkbox")
 | 
			
		||||
	               .attr("checked","");
 | 
			
		||||
    jq("input[name='check_all']").click(function(){
 | 
			
		||||
          if(jq(this).val()==0){
 | 
			
		||||
            jq(this).parents("table")
 | 
			
		||||
                   .find("input:checkbox")
 | 
			
		||||
                   .attr("checked","checked");
 | 
			
		||||
            jq(this).val("1");
 | 
			
		||||
          }
 | 
			
		||||
          else{
 | 
			
		||||
            jq(this).parents("table")
 | 
			
		||||
                   .find("input:checkbox")
 | 
			
		||||
                   .attr("checked","");
 | 
			
		||||
            jq(this).val("0");
 | 
			
		||||
	      }
 | 
			
		||||
          }
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    /*****************************************************************
 | 
			
		||||
     * Comment actions (delete, publish)
 | 
			
		||||
     * Delete comment
 | 
			
		||||
     *****************************************************************/
 | 
			
		||||
    jq('form.background-form').submit(function(e) {
 | 
			
		||||
    jq("input[name='form.button.Delete']").click(function(e) {
 | 
			
		||||
        e.preventDefault();
 | 
			
		||||
        var form = jq(this);
 | 
			
		||||
        var target = jq(this).attr('action');
 | 
			
		||||
        var params = jq(this).serialize();
 | 
			
		||||
        var cell = jq(this).parent().get(0);
 | 
			
		||||
        var row = jq(cell).parent().get(0);
 | 
			
		||||
        var currentFilter = jq(this).find("[name='form.button.Filter']").attr("value");
 | 
			
		||||
        var currentAction = jq(this).attr("class");
 | 
			
		||||
        var publishButton = jq(this).find(".comment-publish-button");
 | 
			
		||||
        jq.post(target, params, function(data) {
 | 
			
		||||
			if (currentAction == 'background-form workflow_action' && currentFilter == '') {
 | 
			
		||||
				// remove the publish button
 | 
			
		||||
                jq(publishButton).fadeOut("normal", function(){
 | 
			
		||||
                    jq(form).remove();
 | 
			
		||||
        var button = jq(this);
 | 
			
		||||
        var row = jq(this).parent().parent();
 | 
			
		||||
        var form = jq(row).parents("form");
 | 
			
		||||
        var path = jq(row).find("input:checkbox").attr("value");
 | 
			
		||||
		var target = path + "/@@moderate-delete-comment";
 | 
			
		||||
        var comment_id = jq(this).attr("id");
 | 
			
		||||
        jq.ajax({
 | 
			
		||||
            type: "GET",
 | 
			
		||||
            url: target,
 | 
			
		||||
            success: function(msg){
 | 
			
		||||
                // fade out row
 | 
			
		||||
                jq(row).fadeOut("normal", function(){
 | 
			
		||||
                    jq(this).remove();
 | 
			
		||||
                });
 | 
			
		||||
			} else {
 | 
			
		||||
				// remove the entire row
 | 
			
		||||
				jq(row).fadeOut("normal", function(){
 | 
			
		||||
					jq(this).remove();
 | 
			
		||||
				});
 | 
			
		||||
			}
 | 
			
		||||
            },
 | 
			
		||||
			error: function(msg){
 | 
			
		||||
                alert("Error sending AJAX request:" + target);
 | 
			
		||||
            },
 | 
			
		||||
        });
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    /*****************************************************************
 | 
			
		||||
     * Publish comment
 | 
			
		||||
     *****************************************************************/
 | 
			
		||||
    jq("input[name='form.button.Publish']").click(function(e) {
 | 
			
		||||
        e.preventDefault();
 | 
			
		||||
        var button = jq(this);
 | 
			
		||||
        var row = jq(this).parent().parent();
 | 
			
		||||
        var form = jq(row).parents("form");
 | 
			
		||||
        var path = jq(row).find("input:checkbox").attr("value");
 | 
			
		||||
        var target = path + "/@@moderate-publish-comment";
 | 
			
		||||
        var currentFilter = jq(form).find("[name='form.button.Filter']").attr("value");
 | 
			
		||||
        jq.ajax({
 | 
			
		||||
            type: "GET",
 | 
			
		||||
            url: target,
 | 
			
		||||
            success: function(msg){
 | 
			
		||||
				if (currentFilter == 'pending') {
 | 
			
		||||
                    // fade out row
 | 
			
		||||
                    jq(row).fadeOut("normal", function(){
 | 
			
		||||
                        jq(this).remove();
 | 
			
		||||
                    });
 | 
			
		||||
				} else {
 | 
			
		||||
					// fade out button
 | 
			
		||||
					jq(button).fadeOut("normal", function(){
 | 
			
		||||
						jq(this).remove();
 | 
			
		||||
					});
 | 
			
		||||
				}
 | 
			
		||||
            },
 | 
			
		||||
            error: function(msg){
 | 
			
		||||
                alert("Error sending AJAX request:" + target);
 | 
			
		||||
            },
 | 
			
		||||
        });
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
@ -51,49 +82,50 @@ jq(document).ready(function() {
 | 
			
		||||
    /*****************************************************************
 | 
			
		||||
     * Bulk actions (delete, publish)
 | 
			
		||||
     *****************************************************************/
 | 
			
		||||
    jq('form.bulkactions').submit(function(e) {
 | 
			
		||||
    jq("input[name='form.button.BulkAction']").click(function(e) {
 | 
			
		||||
        e.preventDefault();
 | 
			
		||||
        var target = jq(this).attr('action');
 | 
			
		||||
        var params = jq(this).serialize();
 | 
			
		||||
		var valArray = jq('input:checkbox:checked');
 | 
			
		||||
        var currentFilter = jq(this).find("[name='form.button.Filter']").attr("value");
 | 
			
		||||
		var currentAction = jq(this).find("[name='form.select.BulkAction']").val();
 | 
			
		||||
		var selectField = jq(this).find("[name='form.select.BulkAction']");
 | 
			
		||||
        var form = jq(this).parents("form")
 | 
			
		||||
        var target = jq(form).attr('action');
 | 
			
		||||
        var params = jq(form).serialize();
 | 
			
		||||
        var valArray = jq('input:checkbox:checked');
 | 
			
		||||
        var currentFilter = jq(form).find("[name='form.button.Filter']").attr("value");
 | 
			
		||||
        var currentAction = jq(form).find("[name='form.select.BulkAction']").val();
 | 
			
		||||
        var selectField = jq(form).find("[name='form.select.BulkAction']");
 | 
			
		||||
        if (valArray.length) {
 | 
			
		||||
            jq.post(target, params, function(data) {
 | 
			
		||||
                valArray.each(function () {
 | 
			
		||||
					// if bulkaction is delete, or the current filter is
 | 
			
		||||
					// pending (because then publish also removes the comment),
 | 
			
		||||
					// remove all selected comments.
 | 
			
		||||
                    // if bulkaction is delete, or the current filter is
 | 
			
		||||
                    // pending (because then publish also removes the comment),
 | 
			
		||||
                    // remove all selected comments.
 | 
			
		||||
                    if (currentAction == 'delete' || currentFilter == 'pending') {
 | 
			
		||||
                        var row = jq(this).parent().parent();
 | 
			
		||||
                        row.fadeOut("normal", function() {
 | 
			
		||||
                           row.remove();
 | 
			
		||||
                        });
 | 
			
		||||
                    }
 | 
			
		||||
					// bulkaction is publish and there is no current filter
 | 
			
		||||
					if (currentAction == 'publish' && currentFilter == '') {
 | 
			
		||||
						// remove the publish button
 | 
			
		||||
                    // bulkaction is publish and there is no current filter
 | 
			
		||||
                    if (currentAction == 'publish' && currentFilter == '') {
 | 
			
		||||
                        // remove the publish button
 | 
			
		||||
                        var row = jq(this).parent().parent();
 | 
			
		||||
						var form = row.find("form.workflow_action");
 | 
			
		||||
                        var form = row.find("form.workflow_action");
 | 
			
		||||
                        var publishButton = row.find(".comment-publish-button");
 | 
			
		||||
						var selectField = row.find("input:checkbox");
 | 
			
		||||
		                jq(publishButton).fadeOut("normal", function(){
 | 
			
		||||
		                    jq(form).remove();
 | 
			
		||||
		                });
 | 
			
		||||
						// reset the select fields
 | 
			
		||||
						selectField.attr("checked","");
 | 
			
		||||
					}
 | 
			
		||||
                        var selectField = row.find("input:checkbox");
 | 
			
		||||
                        jq(publishButton).fadeOut("normal", function(){
 | 
			
		||||
                            jq(form).remove();
 | 
			
		||||
                        });
 | 
			
		||||
                        // reset the select fields
 | 
			
		||||
                        selectField.attr("checked","");
 | 
			
		||||
                    }
 | 
			
		||||
                });
 | 
			
		||||
            });
 | 
			
		||||
        } else {
 | 
			
		||||
			// The user has submitted a bulk action, but no comment
 | 
			
		||||
			// was selected.
 | 
			
		||||
			// Todo: nicer and translated message
 | 
			
		||||
            // The user has submitted a bulk action, but no comment
 | 
			
		||||
            // was selected.
 | 
			
		||||
            // Todo: nicer and translated message
 | 
			
		||||
            alert("You haven't selected anything for this bulk action.");
 | 
			
		||||
        }
 | 
			
		||||
		// reset the bulkaction select
 | 
			
		||||
		selectField.find("option[value='-1']").attr( 'selected', 'selected' );
 | 
			
		||||
        // reset the bulkaction select
 | 
			
		||||
        selectField.find("option[value='-1']").attr( 'selected', 'selected' );
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
});
 | 
			
		||||
@ -115,32 +115,23 @@
 | 
			
		||||
 | 
			
		||||
                            <td tal:content="structure python:view.cook(item.Description)" />
 | 
			
		||||
                            <td style="width: 11em;">
 | 
			
		||||
                                <form action=""
 | 
			
		||||
                                      class="background-form workflow_action"
 | 
			
		||||
                                      method="post"
 | 
			
		||||
                                      tal:attributes="action string:${item/getURL}/@@moderate-publish-comment"
 | 
			
		||||
                                      tal:condition="python:item.review_state == 'pending'">
 | 
			
		||||
                                    <input type="hidden" name="comment_id" tal:attributes="value item/getId" />
 | 
			
		||||
                                    <input type="hidden" name="workflow_action" tal:attributes="value view/transition" />
 | 
			
		||||
                                    <input type="hidden" name="form.button.Filter" tal:attributes="value filter" value="" />
 | 
			
		||||
                                    <input class="context comment-publish-button"
 | 
			
		||||
                                           type="submit"
 | 
			
		||||
                                           value="Publish"
 | 
			
		||||
                                           i18n:attributes="value label_publish"
 | 
			
		||||
                                           />
 | 
			
		||||
                                </form>
 | 
			
		||||
                                <form action=""
 | 
			
		||||
                                      method="post"
 | 
			
		||||
                                      class="background-form delete"
 | 
			
		||||
                                      tal:attributes="action string:${item/getURL}/@@moderate-delete-comment">
 | 
			
		||||
                                    <input type="hidden" name="comment_id" tal:attributes="value item/getId" />
 | 
			
		||||
                                    <input type="hidden" name="form.button.Filter" tal:attributes="value filter" value="" />
 | 
			
		||||
                                    <input class="destructive comment-delete-button"
 | 
			
		||||
                                           type="submit"
 | 
			
		||||
                                           value="Delete"
 | 
			
		||||
                                           i18n:attributes="value label_delete;"
 | 
			
		||||
                                           />
 | 
			
		||||
                                </form>
 | 
			
		||||
                                <input id=""
 | 
			
		||||
                                       class="context comment-publish-button"
 | 
			
		||||
                                       type="submit"
 | 
			
		||||
                                       value="Publish"
 | 
			
		||||
                                       name="form.button.Publish"
 | 
			
		||||
                                       i18n:attributes="value label_publish"
 | 
			
		||||
                                       tal:attributes="id item/id"
 | 
			
		||||
                                       tal:condition="python:item.review_state == 'pending'"
 | 
			
		||||
                                       />
 | 
			
		||||
                                <input id=""
 | 
			
		||||
                                       class="destructive comment-delete-button"
 | 
			
		||||
                                       type="submit"
 | 
			
		||||
                                       value="Delete"
 | 
			
		||||
                                       name="form.button.Delete"
 | 
			
		||||
                                       i18n:attributes="value label_delete;"
 | 
			
		||||
                                       tal:attributes="id item/id"
 | 
			
		||||
                                       />
 | 
			
		||||
                            </td>
 | 
			
		||||
                        </tr>
 | 
			
		||||
                    </tal:block>
 | 
			
		||||
 | 
			
		||||
@ -104,7 +104,8 @@ class PublishComment(BrowserView):
 | 
			
		||||
        comment = aq_inner(self.context)
 | 
			
		||||
        comment_id = self.context.id
 | 
			
		||||
 | 
			
		||||
        workflow_action = self.request.form['workflow_action']
 | 
			
		||||
        #workflow_action = self.request.form['workflow_action']
 | 
			
		||||
        workflow_action = 'publish'
 | 
			
		||||
        portal_workflow = getToolByName(comment, 'portal_workflow')
 | 
			
		||||
        portal_workflow.doActionFor(comment, workflow_action)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -79,12 +79,12 @@ ul.filter {
 | 
			
		||||
	margin: 0.45em 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
form.workflow_action {
 | 
			
		||||
.comment-publish-button {
 | 
			
		||||
    float: left;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
form.delete {
 | 
			
		||||
	float: right;
 | 
			
		||||
.comment-delete-button {
 | 
			
		||||
    float: right;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#review-comments {
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user