jellyfin-web/dashboard-ui/scripts/userparentalcontrol.js

1 line
6.8 KiB
JavaScript
Raw Normal View History

2017-01-27 20:16:59 -07:00
define(["jQuery","datetime","listViewStyle","paper-icon-button-light"],function($,datetime){"use strict";function populateRatings(allParentalRatings,page){var html="";html+="<option value=''></option>";var i,length,rating,ratings=[];for(i=0,length=allParentalRatings.length;i<length;i++){if(rating=allParentalRatings[i],ratings.length){var lastRating=ratings[ratings.length-1];if(lastRating.Value===rating.Value){lastRating.Name+="/"+rating.Name;continue}}ratings.push({Name:rating.Name,Value:rating.Value})}for(i=0,length=ratings.length;i<length;i++)rating=ratings[i],html+="<option value='"+rating.Value+"'>"+rating.Name+"</option>";$("#selectMaxParentalRating",page).html(html)}function loadUnratedItems(page,user){var items=[{name:Globalize.translate("OptionBlockBooks"),value:"Book"},{name:Globalize.translate("OptionBlockGames"),value:"Game"},{name:Globalize.translate("OptionBlockChannelContent"),value:"ChannelContent"},{name:Globalize.translate("OptionBlockLiveTvChannels"),value:"LiveTvChannel"},{name:Globalize.translate("OptionBlockMovies"),value:"Movie"},{name:Globalize.translate("OptionBlockMusic"),value:"Music"},{name:Globalize.translate("OptionBlockTrailers"),value:"Trailer"},{name:Globalize.translate("OptionBlockTvShows"),value:"Series"},{name:Globalize.translate("OptionBlockOthers"),value:"Other"}],html="";html+='<h3 class="checkboxListLabel">'+Globalize.translate("HeaderBlockItemsWithNoRating")+"</h3>",html+='<div class="checkboxList paperList checkboxList-paperList">';for(var i=0,length=items.length;i<length;i++){var item=items[i],checkedAttribute=user.Policy.BlockUnratedItems.indexOf(item.value)!=-1?' checked="checked"':"";html+='<label><input type="checkbox" is="emby-checkbox" class="chkUnratedItem" data-itemtype="'+item.value+'" type="checkbox"'+checkedAttribute+"><span>"+item.name+"</span></label>"}html+="</div>",$(".blockUnratedItems",page).html(html).trigger("create")}function loadUser(page,user,allParentalRatings){LibraryMenu.setTitle(user.Name),loadUnratedItems(page,user),loadBlockedTags(page,user.Policy.BlockedTags),populateRatings(allParentalRatings,page);var ratingValue="";if(user.Policy.MaxParentalRating)for(var i=0,length=allParentalRatings.length;i<length;i++){var rating=allParentalRatings[i];user.Policy.MaxParentalRating>=rating.Value&&(ratingValue=rating.Value)}$("#selectMaxParentalRating",page).val(ratingValue),user.Policy.IsAdministrator?$(".accessScheduleSection",page).hide():$(".accessScheduleSection",page).show(),renderAccessSchedule(page,user.Policy.AccessSchedules||[]),Dashboard.hideLoadingMsg()}function loadBlockedTags(page,tags){var html=tags.map(function(h){var li='<div class="listItem">';return li+='<div class="listItemBody">',li+='<h3 class="listItemBodyText">',li+=h,li+="</h3>",li+="</div>",li+='<button type="button" is="paper-icon-button-light" class="blockedTag btnDeleteTag listItemButton" data-tag="'+h+'"><i class="md-icon">delete</i></button>',li+="</div>"}).join("");html&&(html='<div class="paperList">'+html+"</div>");var elem=$(".blockedTags",page).html(html).trigger("create");$(".btnDeleteTag",elem).on("click",function(){var tag=this.getAttribute("data-tag"),newTags=tags.filter(function(t){return t!=tag});loadBlockedTags(page,newTags)})}function deleteAccessSchedule(page,schedules,index){schedules.splice(index,1),renderAccessSchedule(page,schedules)}function renderAccessSchedule(page,schedules){var html="",index=0;html+=schedules.map(function(a){var itemHtml="";return itemHtml+='<div class="liSchedule listItem" data-day="'+a.DayOfWeek+'" data-start="'+a.StartHour+'" data-end="'+a.EndHour+'">',itemHtml+='<div class="listItemBody two-line">',itemHtml+='<h3 class="listItemBodyText">',itemHtml+=Globalize.translate("Option"+a.DayOfWeek),itemHtml+="</h3>",itemHtml+='<div class="listItemBodyText secondary">'+getDisplayTime(a.StartHour)+" - "+getDisplayTime(a.EndHour)+"</div>",itemHtml+="</div>",itemHtml+='<button type="button" is="paper-icon-button-light" class="btnDelete listItemButton" data-index="'+index+'"><i class="md-icon">delete</i></button>',itemHtml+="</div>",index++,itemHtml}).