{% comment %}
<!--
  Copyright (C) 2012 University of Dundee & Open Microscopy Environment.
  All rights reserved.

  This program is free software: you can redistribute it and/or modify
  it under the terms of the GNU Affero General Public License as
  published by the Free Software Foundation, either version 3 of the
  License, or (at your option) any later version.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU Affero General Public License for more details.

  You should have received a copy of the GNU Affero General Public License
  along with this program.  If not, see <http://www.gnu.org/licenses/>.
-->
{% endcomment %}

<script>

$(document).ready(function() {
    
    $("#split_view_panel").omeroweb_center_plugin({
        plugin_index: {{ forloop.counter }},        // since we're in a Django template loop
        load_plugin_content: function(selected, dtype, oid){
            var split_view_url;
            if (dtype=="image") {
                var iids = [];
                for (var i=0; i<selected.length; i++) {
                    var dtype = selected[i]['id'].split("-")[0];
                    if (dtype == "image") {
                        iids.push(selected[i]['id'].split("-")[1]);
                    };
                }
                split_view_url = '{% url 'webtest_split_view_figure_plugin' %}?imageIds='+ iids.join(",") + "&width=120";
            // if it's a dataset, show 2 rendering settings side by side.
            } else if (dtype=="dataset") {
                split_view_url = '{% url 'webtest_index' %}dataset_split_view/'+oid+'/';
            }
            $(this).load(split_view_url);
        },
        plugin_enabled: function(selected){
            if (selected.length == 0) return false;
            var dtype = selected[0]['id'].split('-')[0];
            if (selected.length > 1) {
                return (dtype == "image");
            } else {
                return ($.inArray(dtype, ["image", "dataset"]) > -1);
            }
        }
    })
});

</script>