expertiza/expertiza

View on GitHub
app/views/sign_up_sheet/_add_topics.html.erb

Summary

Maintainability
Test Coverage
<% if @sign_up_topics.count == 0%>

    <%= link_to 'New topic',
                {
                    :controller => 'sign_up_sheet',
                    :action => 'new',
                    :id => params[:id]
                },
                :confirm => "You are adding a topic to this assignment.  Students will now have to select a topic before they submit their work.",
                :topic => @topics,
                :method => :get%> |

    <%= link_to 'Import topics',
                {
                    :controller => 'import_file',
                    :action => 'start',
                    :model => 'SignUpTopic',
                    :id => params[:id],
                    :expected_fields => 'Topic Identifier' +
                        '&nbsp&nbsp|&nbsp&nbsp' +
                        'Topic Name' +
                        '&nbsp&nbsp|&nbsp&nbsp' +
                        'Max Choosers' +
                        '&nbsp&nbsp|&nbsp&nbsp' +
                        'Topic Category <em>(optional)</em>' +
                        '&nbsp&nbsp|&nbsp&nbsp' +
                        'Topic Description <em>(optional)</em>' +
                        '&nbsp&nbsp|&nbsp&nbsp' +
                        'Topic Link <em>(optional)</em>'
                },
                :confirm => "You are adding topics to this assignment.  Students will now have to select a topic before they submit their work.",
                :topic => @topics,
                :method => :get %> |

<% else %>

    <%= link_to 'New topic',
                :controller => 'sign_up_sheet',
                :action => 'new',
                :id => params[:id]%> |

    <%= link_to 'Import topics',
                :controller=>'import_file',
                :action=>'start',
                :model => 'SignUpTopic',
                :id => params[:id],
                :expected_fields => 'Topic Identifier' +
                    '&nbsp&nbsp|&nbsp&nbsp' +
                    'Topic Name' +
                    '&nbsp&nbsp|&nbsp&nbsp' +
                    'Max Choosers' +
                    '&nbsp&nbsp|&nbsp&nbsp' +
                    'Topic Category <em>(optional)</em>' +
                    '&nbsp&nbsp|&nbsp&nbsp' +
                    'Topic Description <em>(optional)</em>' +
                    '&nbsp&nbsp|&nbsp&nbsp' +
                    'Topic Link <em>(optional)</em>' %> |

    <input type="button" value="Delete selected topics" onclick="deleteTopics()" />|
    <input type="button" value="Delete all topics" onclick="deleteAllTopics()" />|
<% end %>

<script>
    // javascript Function to delete all selected topics
    function deleteTopics() {
        var msg = 'Are you sure? It will delete all selected topics';
        if (confirm(msg)) {
            var topic_identifiers = []
            $("#topics input[type=checkbox]:checked").each(function() {
                var topic_id = $(this).closest('tr').find('#topic_id').text();
                topic_identifiers.push(topic_id);
                
            });
            jQuery.ajax({
                url: '/sign_up_sheet/delete_all_selected_topics',
                method: 'POST',
                data: {
                    topic_ids: topic_identifiers,
                    assignment_id: <%= @assignment.id %>  
                },
                success: function() {
                    location.reload();
                }
            });
        } else {
            window.location.href = '<%= edit_assignment_path(@assignment.id) + "#tabs-2" %>';
        }
    }
    function deleteAllTopics() {
        var msg = 'Are you sure? It will delete all topics';
        if (confirm(msg)) {
            var topic_identifiers = []
            $("#topics tr").each(function(topic) {
                var topic_id = $(this).closest('tr').find('#topic_id').text();
                topic_identifiers.push(topic_id);
            });
            jQuery.ajax({
                url: '/sign_up_sheet/delete_all_selected_topics',
                method: 'POST',
                data: {
                    topic_ids: topic_identifiers,
                    assignment_id: <%= @assignment.id %>  
                },
                success: function() {
                    location.reload();
                }
            });
        } else {
            window.location.href = '<%= edit_assignment_path(@assignment.id) + "#tabs-2" %>';
        }
    }
</script>