2017-04-28 15:31:47 -07:00
|
|
|
define(["itemHelper","dom","layoutManager","dialogHelper","datetime","loading","focusManager","connectionManager","globalize","require","shell","emby-checkbox","emby-input","emby-select","listViewStyle","emby-textarea","emby-button","paper-icon-button-light","css!./../formdialog"],function(itemHelper,dom,layoutManager,dialogHelper,datetime,loading,focusManager,connectionManager,globalize,require,shell){"use strict";function isDialog(){return currentContext.classList.contains("dialog")}function closeDialog(isSubmitted){isDialog()&&dialogHelper.close(currentContext)}function submitUpdatedItem(form,item){function afterContentTypeUpdated(){require(["toast"],function(toast){toast(globalize.translate("sharedcomponents#MessageItemSaved"))}),loading.hide(),closeDialog(!0)}var apiClient=getApiClient();apiClient.updateItem(item).then(function(){var newContentType=form.querySelector("#selectContentType").value||"";(metadataEditorInfo.ContentType||"")!==newContentType?apiClient.ajax({url:apiClient.getUrl("Items/"+item.Id+"/ContentType",{ContentType:newContentType}),type:"POST"}).then(function(){afterContentTypeUpdated()}):afterContentTypeUpdated()})}function getSelectedAirDays(form){var checkedItems=form.querySelectorAll(".chkAirDay:checked")||[];return Array.prototype.map.call(checkedItems,function(c){return c.getAttribute("data-day")})}function getAlbumArtists(form){return form.querySelector("#txtAlbumArtist").value.trim().split(";").filter(function(s){return s.length>0}).map(function(a){return{Name:a}})}function getArtists(form){return form.querySelector("#txtArtist").value.trim().split(";").filter(function(s){return s.length>0}).map(function(a){return{Name:a}})}function getDateFromForm(form,element,property){var val=form.querySelector(element).value;if(!val)return null;if(currentItem[property]){var date=datetime.parseISO8601Date(currentItem[property],!0),parts=date.toISOString().split("T");if(0===parts[0].indexOf(val)){var iso=parts[1];val+="T"+iso}}return val}function onSubmit(e){loading.show();var form=this;try{var item={Id:currentItem.Id,Name:form.querySelector("#txtName").value,OriginalTitle:form.querySelector("#txtOriginalName").value,ForcedSortName:form.querySelector("#txtSortName").value,DisplayMediaType:form.querySelector("#txtDisplayMediaType").value,CommunityRating:form.querySelector("#txtCommunityRating").value,VoteCount:form.querySelector("#txtCommunityVoteCount").value,HomePageUrl:form.querySelector("#txtHomePageUrl").value,CriticRating:form.querySelector("#txtCriticRating").value,IndexNumber:form.querySelector("#txtIndexNumber").value||null,AbsoluteEpisodeNumber:form.querySelector("#txtAbsoluteEpisodeNumber").value,DvdEpisodeNumber:form.querySelector("#txtDvdEpisodeNumber").value,DvdSeasonNumber:form.querySelector("#txtDvdSeasonNumber").value,AirsBeforeSeasonNumber:form.querySelector("#txtAirsBeforeSeason").value,AirsAfterSeasonNumber:form.querySelector("#txtAirsAfterSeason").value,AirsBeforeEpisodeNumber:form.querySelector("#txtAirsBeforeEpisode").value,ParentIndexNumber:form.querySelector("#txtParentIndexNumber").value||null,DisplayOrder:form.querySelector("#selectDisplayOrder").value,Players:form.querySelector("#txtPlayers").value,Album:form.querySelector("#txtAlbum").value,AlbumArtists:getAlbumArtists(form),ArtistItems:getArtists(form),AwardSummary:form.querySelector("#txtAwardSummary").value,Overview:form.querySelector("#txtOverview").value,Status:form.querySelector("#selectStatus").value,AirDays:getSelectedAirDays(form),AirTime:form.querySelector("#txtAirTime").value,Genres:editableListViewValues(form.querySelector("#listGenres")),Tags:editableListViewValues(form.querySelector("#listTags")),Keywords:editableListViewValues(form.querySelector("#listKeywords")),Studios:editableListViewValues(form.querySelector("#listStudios")).map(function(element){return{Name:element}}),PremiereDate:getDateFromForm(form,"#txtPremiereDate","PremiereDate"),DateCreated:getDateFromForm(form,"#txtDateAdded","DateCreated"),EndDate:getDateFromForm(form,"#txtEndDate","EndDate"),ProductionYear:form.querySelector("#txtProductionYear").v
|