var a;function SongView(){ListView.call(this);this.name="SongView";this.allDataLoaded=this.songsLoaded=false;this.sortVariable="bezeichnung"}Temp.prototype=ListView.prototype;SongView.prototype=new Temp;songView=new SongView;a=SongView.prototype;
a.getData=function(d){if(d){var c=[];allSongs!=null&&$.each(churchcore_sortData(allSongs,"bezeichnung"),function(b,e){$.each(e.arrangement,function(f,g){f=[];f.song_id=e.id;f.arrangement_id=g.id;f.id=e.id+"_"+g.id;c.push(f)})})}else{c={};allSongs!=null&&$.each(allSongs,function(b,e){$.each(e.arrangement,function(f,g){f=[];f.song_id=e.id;f.arrangement_id=g.id;f.id=e.id+"_"+g.id;c[f.id]=f})})}return c};
a.renderFilter=function(){if(masterData.settings.filterSongcategory==""||masterData.settings.filterSongcategory==null)delete masterData.settings.filterSongcategory;else this.filter.filterSongcategory=masterData.settings.filterSongcategory;var d=[],c=new CC_Form;c.setHelp("ChurchService-Filter");c.addHtml('<div id="filterKategorien"></div>');c.addSelect({data:this.sortMasterData(masterData.songcategory),label:"Song-Kategorien",selected:this.filter.filterSongcategory,freeoption:true,cssid:"filterSongcategory",
type:"medium",func:function(b){return masterData.auth.viewsongcategory!=null&&masterData.auth.viewsongcategory[b.id]}});c.addCheckbox({cssid:"searchStandard",label:"Nur Standard-Arrangement"});d.push(c.render(true));d.push('<div id="cdb_filtercover"></div>');$("#cdb_filter").html(d.join(""));$.each(this.filter,function(b,e){$("#"+b).val(e)});filter=this.filter;this.implantStandardFilterCallbacks(this,"cdb_filter");this.renderCalendar()};
a.groupingFunction=function(d){if(this.filter.searchStandard==null){var c="";c=c+"<b>"+allSongs[d.song_id].bezeichnung+"</b>";if(allSongs[d.song_id].author!="")c=c+"&nbsp; <small>"+allSongs[d.song_id].author+"</small>";return c=c+'&nbsp; <a href="#" class="edit-song" data-id="'+d.song_id+'">'+form_renderImage({src:"options.png",width:16})+"</a>"}else return null};
a.checkFilter=function(d){if(d==null)return false;var c=allSongs[d.song_id],b=c.arrangement[d.arrangement_id];if(songView.filter!=null){var e=songView.filter;if(e.searchEntry!=null&&c.bezeichnung.toLowerCase().indexOf(e.searchEntry.toLowerCase())==-1&&e.searchEntry!=d.arrangement_id)return false;if(e.filterSongcategory!=null&&c.songcategory_id!=e.filterSongcategory)return false;if(!churchcore_inArray(c.songcategory_id,masterData.auth.viewsongcategory))return false;if(e.searchStandard&&b.default_yn==
0)return false}return true};a.renderTooltip=function(d,c){var b=d.parents("div.entrydetail").attr("data-song-id"),e=d.parent().attr("data-id"),f=d.attr("tooltip");return this.renderTooltipForFiles(d,c,allSongs[b].arrangement[e].files[f],masterData.auth.editsong)};a.tooltipCallback=function(d,c){var b=c.parents("div.entrydetail").attr("data-song-id"),e=c.parent().attr("data-id");return this.tooltipCallbackForFiles(d,c,allSongs[b].arrangement,e)};
a.renderFiles=function(d,c){var b=this;b.clearTooltip(true);masterData.auth.editsong?b.renderFilelist("",d,c,function(e){delete d[c].files[e];b.renderFiles(d,c)}):b.renderFilelist("",d,c);$("div.filelist[data-id="+c+"] span[tooltip],a[tooltip]").hover(function(){drin=true;this_object.prepareTooltip($(this),null,$(this).attr("data-tooltiptype"))},function(){drin=false;window.setTimeout(function(){drin||this_object.clearTooltip()},100)})};
a.renderEntryDetail=function(d){var c=this,b=d.indexOf("_"),e=allSongs[d.substr(0,b)],f=e.arrangement[d.substr(b+1,99)];b=[];b.push('<div class="entrydetail" id="entrydetail_'+d+'" data-song-id="'+e.id+'" data-arrangement-id="'+f.id+'">');b.push('<div class="well">');b.push('<b style="font-size:140%">'+e.bezeichnung+" - "+f.bezeichnung+"</b>");e.autor!=""&&b.push("<br/><small>Autor: "+e.author+"</small>");e.copyright!=""&&b.push("<br/><small>Copyright: "+e.copyright+"</small>");e.ccli!=""&&b.push("<br/><small>CCLI: "+
e.ccli+"</small>");b.push("</div>");b.push('<div class="row-fluid">');b.push('<div class="span6">');b.push("<legend>Informationen &nbsp; ");masterData.auth.editsong&&b.push('<a href="#" class="edit">'+c.renderImage("options",20)+"</a>");b.push("</legend>");b.push("<p>Tonart: "+f.tonality);b.push("&nbsp; BPM: "+f.bpm);b.push("&nbsp; Takt: "+f.beat);b.push("<p>L&auml;nge: "+f.length_min+":"+f.length_sec);b.push("<p>Bemerkung:<br/><p><small> "+f.note.replace(/\n/g,"<br/>")+"</small>");b.push("</div>");
b.push('<div class="span6">');b.push("<legend>Dateien</legend>");b.push('<div class="we_ll">');b.push('<div class="filelist" data-id="'+f.id+'"></div>');masterData.auth.editsong&&b.push('<p><div id="upload_button_'+f.id+'">Nochmal bitte...</div>');b.push("</div>");b.push("</div>");b.push("</div>");if(masterData.auth.editsong){b.push("<hr/><p>");b.push(form_renderButton({label:"Weiteres Arrangement hinzuf&uuml;gen",htmlclass:"add",type:"small"})+"&nbsp; ");if(f.default_yn==0){b.push(form_renderButton({label:"Zum Standard machen",
htmlclass:"makestandard",type:"small"})+"&nbsp; ");b.push(form_renderButton({label:"Arrangement entfernen",htmlclass:"delete",type:"small"})+"&nbsp; ")}}b.push("</div>");$("tr[id="+d+"]").after('<tr id="detail'+d+'"><td colspan="7" id="detailTD'+d+'">'+b.join("")+"</td></tr>");c.renderFiles(allSongs[e.id].arrangement,f.id);masterData.auth.editsong&&new qq.FileUploader({element:document.getElementById("upload_button_"+f.id),action:"?q=churchservice/uploadfile",params:{domain_type:"song_arrangement",
domain_id:f.id},multiple:true,debug:true,onSubmit:function(){},onComplete:function(g,i,h){if(h.success){if(f.files==null)f.files={};f.files[h.id]={bezeichnung:h.bezeichnung,filename:h.filename,id:h.id,domain_type:"song_arrangement",domain_id:f.id};c.renderFiles(allSongs[e.id].arrangement,f.id)}else alert("Sorry, Fehler beim Hochladen aufgetreten! Datei zu gross oder Dateiname schon vergeben?")}});$("td[id=detailTD"+d+"] a.edit").click(function(){c.editArrangement(e.id,f.id);return false});$("td[id=detailTD"+
d+"] input.add").click(function(){c.addArrangement(e.id);return false});$("td[id=detailTD"+d+"] input.delete").click(function(){c.deleteArrangement(e.id,f.id);return false});$("td[id=detailTD"+d+"] input.makestandard").click(function(){c.makeAsStandardArrangement(e.id,f.id);return false})};a.loadSongData=function(){if(!this.songsLoaded&&this.allDataLoaded){var d=this.showDialog("Lade Songs","Lade Songs...",300,300);cs_loadSongs(function(){this_object.songsLoaded=true;d.dialog("close");this_object.renderList()})}};
a.renderMenu=function(){this_object=this;menu=new CC_Menu("Men&uuml;");masterData.auth.editsong&&menu.addEntry("Neuen Song anlegen","anewentry","star");menu.renderDiv("cdb_menu",churchcore_handyformat())?$("#cdb_menu a").click(function(){if($(this).attr("id")=="anewentry")this_object.renderAddEntry();else $(this).attr("id")=="ahelp"&&churchcore_openNewWindow("http://intern.churchtools.de/?q=help&doc=ChurchService");return false}):$("#cdb_menu").hide()};
a.editSong=function(d){var c=this,b=new CC_Form("Infos des Songs",allSongs[d]);b.addInput({label:"Bezeichnung",cssid:"bezeichnung",required:true,disabled:!masterData.auth.editsong});b.addSelect({label:"Song-Kategorie",cssid:"songcategory_id",data:masterData.songcategory,disabled:!masterData.auth.editsong});b.addInput({label:"Autor",cssid:"author",disabled:!masterData.auth.editsong});b.addInput({label:"Copyright",cssid:"copyright",disabled:!masterData.auth.editsong});b.addInput({label:"CCLI-Nummer",
cssid:"ccli",disabled:!masterData.auth.editsong});var e=form_showDialog("Song editieren",b.render(false,"horizontal"),500,500);masterData.auth.editsong&&e.dialog("addbutton","Speichern",function(){obj=b.getAllValsAsObject();if(obj!=null){obj.func="editSong";obj.id=d;churchInterface.jsendWrite(obj,function(){c.songsLoaded=false;c.loadSongData()});$(this).dialog("close")}});e.dialog("addbutton","Abbrechen",function(){$(this).dialog("close")})};
a.renderAddEntry=function(){var d=this,c=new CC_Form("Bitte Infos des neuen Songs angeben");c.addInput({label:"Bezeichnung",cssid:"bezeichnung",required:true});c.addSelect({label:"Song-Kategorie",cssid:"songcategory_id",required:true,data:masterData.songcategory,selected:masterData.settings.filterSongcategory});c.addInput({label:"Autor",cssid:"author"});c.addInput({label:"Copyright",cssid:"copyright"});c.addInput({label:"CCLI-Nummer",cssid:"ccli"});c.addInput({label:"Tonart",type:"small",cssid:"tonality"});
c.addInput({label:"BPM",type:"small",cssid:"bpm"});c.addInput({label:"Takt",type:"small",cssid:"beat"});form_showDialog("Neuen Song anlegen",c.render(false,"horizontal"),500,500,{Erstellen:function(){var b=c.getAllValsAsObject();if(b!=null){b.func="addNewSong";churchInterface.jsendWrite(b,function(){d.songsLoaded=false;d.filter.searchEntry=b.bezeichnung;if(d.filter.filterSongcategory!=b.songcategory_id){delete d.filter.filterSongcategory;delete masterData.settings.filterSongcategory}d.renderFilter();
d.loadSongData()});$(this).dialog("close")}},Abbrechen:function(){$(this).dialog("close")}})};function processFieldInput(d,c){var b=d.parents("td").attr("data-oldval");d.parents("td").removeAttr("data-oldval");if(c){newval=d.val();d.parents("td").html(newval)}else d.parents("td").html(b)}a=SongView.prototype;a.addFurtherListCallbacks=function(){var d=this;$("#cdb_content a.edit-song").click(function(){d.editSong($(this).attr("data-id"));return false})};
a.editArrangement=function(d,c){var b=this,e=new CC_Form("Bitte Arrangement anpassen",allSongs[d].arrangement[c]);e.addInput({label:"Bezeichnung",cssid:"bezeichnung",required:true});e.addInput({label:"Tonart",cssid:"tonality"});e.addInput({label:"BPM",cssid:"bpm"});e.addInput({label:"Takt",cssid:"beat"});e.addInput({label:"L&auml;nge Minuten:Sekunden",type:"mini",cssid:"length_min",controlgroup_start:true});e.addHtml(" : ");e.addInput({controlgroup_end:true,type:"mini",cssid:"length_sec"});e.addTextarea({label:"Bemerkungen",
rows:3,cssid:"note"});form_showDialog("Arrangement editieren",e.render(false,"horizontal"),500,500,{Absenden:function(){obj=e.getAllValsAsObject();if(obj!=null){obj.func="editArrangement";obj.id=c;churchInterface.jsendWrite(obj,function(){b.songsLoaded=false;b.loadSongData()});$(this).dialog("close")}},Abbrechen:function(){$(this).dialog("close")}})};
a.deleteArrangement=function(d,c){var b=this,e=allSongs[d].arrangement[c];if(e.files!=null){alert("Bitte zuerst die Dateien entfernen!");return null}if(confirm("Wirklich Arrangement "+e.bezeichnung+" entfernen?")){e={};e.func="delArrangement";e.song_id=d;e.id=c;churchInterface.jsendWrite(e,function(){b.songsLoaded=false;b.loadSongData()})}};
a.makeAsStandardArrangement=function(d,c){var b=this,e={};e.func="makeAsStandardArrangement";e.id=c;e.song_id=d;churchInterface.jsendWrite(e,function(){b.songsLoaded=false;b.loadSongData()})};a.addArrangement=function(d){var c=this,b={};b.func="addArrangement";b.song_id=d;b.bezeichnung="Neues Arrangement";churchInterface.jsendWrite(b,function(e,f){c.songsLoaded=false;c.open=true;c.filter.searchEntry=f;c.renderFilter();c.loadSongData()})};a.getCountCols=function(){return 6};
a.getListHeader=function(){this.loadSongData();var d=[];songView.listViewTableHeight=masterData.settings.listViewTableHeight==0?null:665;this.filter.searchStandard!=null&&d.push("<th>Nr.");d.push("<th>Bezeichnung<th>Tonart<th>BPM<th>Takt<th>Tags");return d.join("")};
a.renderListEntry=function(d){var c=[],b=allSongs[d.song_id],e=b.arrangement[d.arrangement_id];if(this.filter.searchStandard==null){c.push('<td><a href="#" id="detail'+d.id+'">'+e.bezeichnung+"</a>");e.default_yn==1&&c.push(" *")}else{c.push('<td><a href="#" id="detail'+d.id+'">'+b.bezeichnung+"</a>");masterData.auth.editsong!=null&&c.push('&nbsp; <a href="#" class="edit-song" data-id="'+d.song_id+'">'+form_renderImage({src:"options.png",width:16})+"</a>")}c.push("<td>"+e.tonality);c.push("<td>"+
e.bpm);c.push("<td>"+e.beat);c.push("<td>");return c.join("")};a.messageReceiver=function(d,c){if(d=="allDataLoaded"){this.allDataLoaded=true;this==churchInterface.getCurrentView()&&this.loadSongData()}this==churchInterface.getCurrentView()&&d=="allDataLoaded"&&this.renderList();if(d=="filterChanged")if(c[0]=="filterSongcategory"){masterData.settings.filterSongcategory=$("#filterSongcategory").val();churchInterface.jsonWrite({func:"saveSetting",sub:"filterSongcategory",val:masterData.settings.filterSongcategory})}};
a.addSecondMenu=function(){return""};
