(function(){"use strict";var a=this;a.define(["backbone","communicator","hbs!tmpl/SelectionManager","hbs!tmpl/SelectionTemplate","underscore","lm"],function(a,b,c,d){var e=a.Marionette.ItemView.extend({tagName:"div",className:"panel panel-default selectionManager not-selectable",template:{type:"handlebars",template:c},initialize:function(a){},onShow:function(a){this.$(".close").on("click",_.bind(this.onClose,this)),this.$el.draggable({containment:"#content",scroll:!1,handle:".panel-heading"}),this.renderList()},renderList:function(){$("#selection-list").empty(),_.each(localStorage.getObject("selections"),function(a,b){_.extend(a,{id:b});var c=$(d(a));$("#selection-list").append(c)},this)},events:{"change #upload-selection":"onUploadSelectionChanged","click #btn-export-selection":"onExportSelectionClicked","click #btn-save-selection":"onSaveSelectionClicked","click .delete-selection":"onDeleteSelection",'change input[type="radio"]':"onSelectionSelected"},onUploadSelectionChanged:function(a){var c=new FileReader;c.onloadend=function(a){b.mediator.trigger("map:load:geojson",a.target.result)},c.readAsText(a.target.files[0])},onExportSelectionClicked:function(){b.mediator.trigger("map:export:geojson")},onSaveSelectionClicked:function(){var a=prompt("Please enter a name for the selection","Selection");if(null!=a&&""!=a){var c=localStorage.getObject("selections");c||(c=[]);var d=b.reqres.request("get:selection:json");console.log(new Date),""!=d&&null!=d&&(c.push({name:a,date:(new Date).toUTCString(),content:d}),localStorage.setObject("selections",c),this.renderList())}},onDeleteSelection:function(a){var b=$(a.target),c=b.parent().parent().parent().find("input").val();if(c>-1){var d=localStorage.getObject("selections");d&&(d.splice(c,1),console.log(d),localStorage.setObject("selections",d),this.renderList())}},onSelectionSelected:function(a){var c=$("input[type=radio]:checked").val();b.mediator.trigger("map:load:geojson",localStorage.getObject("selections")[c].content)},onClose:function(){b.mediator.trigger("ui:close","selectionManager"),this.close()}});return{SelectionManagerView:e}})}).call(this);