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

1177 lines
39 KiB
JavaScript
Raw Normal View History

define(['jQuery'], function ($) {
2014-03-26 12:21:29 -07:00
var currentProfile;
2014-03-28 19:28:02 -07:00
var currentSubProfile;
var isSubProfileNew;
2014-07-16 20:17:14 -07:00
var allText = Globalize.translate('LabelAll');
2014-03-26 12:21:29 -07:00
function loadProfile(page) {
Dashboard.showLoadingMsg();
2014-04-19 22:21:08 -07:00
var promise1 = getProfile();
var promise2 = ApiClient.getUsers();
2014-03-26 12:21:29 -07:00
2015-12-14 08:43:03 -07:00
Promise.all([promise1, promise2]).then(function (responses) {
2015-12-14 08:43:03 -07:00
currentProfile = responses[0];
2014-04-19 22:21:08 -07:00
2015-12-14 08:43:03 -07:00
renderProfile(page, currentProfile, responses[1]);
2014-03-26 12:21:29 -07:00
Dashboard.hideLoadingMsg();
2014-04-19 22:21:08 -07:00
2014-03-26 12:21:29 -07:00
});
}
2014-03-26 13:14:47 -07:00
function getProfile() {
var id = getParameterByName('id');
var url = id ? 'Dlna/Profiles/' + id :
'Dlna/Profiles/Default';
2014-07-01 22:16:59 -07:00
return ApiClient.getJSON(ApiClient.getUrl(url));
2014-03-26 13:14:47 -07:00
}
2014-04-19 22:21:08 -07:00
function renderProfile(page, profile, users) {
2014-03-27 12:30:21 -07:00
2014-03-26 13:14:47 -07:00
$('#txtName', page).val(profile.Name);
2014-03-31 21:16:35 -07:00
$('.chkMediaType', page).each(function () {
2014-03-27 12:30:21 -07:00
this.checked = (profile.SupportedMediaTypes || '').split(',').indexOf(this.getAttribute('data-value')) != -1;
2014-03-27 12:30:21 -07:00
}).checkboxradio('refresh');
$('#chkEnableAlbumArtInDidl', page).checked(profile.EnableAlbumArtInDidl).checkboxradio('refresh');
$('#chkEnableSingleImageLimit', page).checked(profile.EnableSingleAlbumArtLimit).checkboxradio('refresh');
renderXmlDocumentAttributes(page, profile.XmlRootAttributes || []);
var idInfo = profile.Identification || {};
2014-07-17 15:21:35 -07:00
renderIdentificationHeaders(page, idInfo.Headers || []);
renderSubtitleProfiles(page, profile.SubtitleProfiles || []);
2014-07-17 15:21:35 -07:00
2014-04-28 08:05:28 -07:00
$('#txtInfoFriendlyName', page).val(profile.FriendlyName || '');
$('#txtInfoModelName', page).val(profile.ModelName || '');
$('#txtInfoModelNumber', page).val(profile.ModelNumber || '');
$('#txtInfoModelDescription', page).val(profile.ModelDescription || '');
$('#txtInfoModelUrl', page).val(profile.ModelUrl || '');
$('#txtInfoManufacturer', page).val(profile.Manufacturer || '');
$('#txtInfoManufacturerUrl', page).val(profile.ManufacturerUrl || '');
$('#txtInfoSerialNumber', page).val(profile.SerialNumber || '');
$('#txtIdFriendlyName', page).val(idInfo.FriendlyName || '');
$('#txtIdModelName', page).val(idInfo.ModelName || '');
$('#txtIdModelNumber', page).val(idInfo.ModelNumber || '');
$('#txtIdModelDescription', page).val(idInfo.ModelDescription || '');
$('#txtIdModelUrl', page).val(idInfo.ModelUrl || '');
$('#txtIdManufacturer', page).val(idInfo.Manufacturer || '');
$('#txtIdManufacturerUrl', page).val(idInfo.ManufacturerUrl || '');
$('#txtIdSerialNumber', page).val(idInfo.SerialNumber || '');
$('#txtIdDeviceDescription', page).val(idInfo.DeviceDescription || '');
$('#txtAlbumArtPn', page).val(profile.AlbumArtPn || '');
$('#txtAlbumArtMaxWidth', page).val(profile.MaxAlbumArtWidth || '');
$('#txtAlbumArtMaxHeight', page).val(profile.MaxAlbumArtHeight || '');
$('#txtIconMaxWidth', page).val(profile.MaxIconWidth || '');
$('#txtIconMaxHeight', page).val(profile.MaxIconHeight || '');
$('#chkIgnoreTranscodeByteRangeRequests', page).checked(profile.IgnoreTranscodeByteRangeRequests).checkboxradio('refresh');
2014-07-27 15:01:29 -07:00
$('#txtMaxAllowedBitrate', page).val(profile.MaxStreamingBitrate || '');
2014-08-14 06:24:30 -07:00
$('#txtMusicStreamingTranscodingBitrate', page).val(profile.MusicStreamingTranscodingBitrate || '');
$('#chkRequiresPlainFolders', page).checked(profile.RequiresPlainFolders).checkboxradio('refresh');
$('#chkRequiresPlainVideoItems', page).checked(profile.RequiresPlainVideoItems).checkboxradio('refresh');
2014-06-24 14:45:21 -07:00
$('#txtProtocolInfo', page).val(profile.ProtocolInfo || '');
2014-04-22 10:25:54 -07:00
$('#txtXDlnaCap', page).val(profile.XDlnaCap || '');
$('#txtXDlnaDoc', page).val(profile.XDlnaDoc || '');
$('#txtSonyAggregationFlags', page).val(profile.SonyAggregationFlags || '');
profile.DirectPlayProfiles = (profile.DirectPlayProfiles || []);
profile.TranscodingProfiles = (profile.TranscodingProfiles || []);
profile.ContainerProfiles = (profile.ContainerProfiles || []);
profile.CodecProfiles = (profile.CodecProfiles || []);
2014-03-31 21:16:35 -07:00
profile.ResponseProfiles = (profile.ResponseProfiles || []);
2014-07-16 20:17:14 -07:00
2014-04-19 22:21:08 -07:00
var usersHtml = '<option></option>' + users.map(function (u) {
return '<option value="' + u.Id + '">' + u.Name + '</option>';
}).join('');
2015-09-03 10:01:51 -07:00
$('#selectUser', page).html(usersHtml).val(profile.UserId || '');
2014-03-28 19:28:02 -07:00
renderSubProfiles(page, profile);
}
2014-07-17 15:21:35 -07:00
function renderIdentificationHeaders(page, headers) {
var index = 0;
var html = '<ul data-role="listview" data-inset="true" data-split-icon="delete">' + headers.map(function (h) {
var li = '<li>';
li += '<a href="#">';
li += '<div style="font-weight:normal;">' + h.Name + ': ' + (h.Value || '') + '</div>';
li += '<div style="font-weight:normal;">' + (h.Match || '') + '</div>';
li += '</a>';
li += '<a class="btnDeleteIdentificationHeader" href="#" data-index="' + index + '"></a>';
li += '</li>';
index++;
return li;
}).join('') + '</ul>';
var elem = $('.httpHeaderIdentificationList', page).html(html).trigger('create');
$('.btnDeleteIdentificationHeader', elem).on('click', function () {
var itemIndex = parseInt(this.getAttribute('data-index'));
currentProfile.Identification.Headers.splice(itemIndex, 1);
renderIdentificationHeaders(page, currentProfile.Identification.Headers);
});
}
function editIdentificationHeader(page, header) {
isSubProfileNew = header == null;
header = header || {};
currentSubProfile = header;
var popup = $('#identificationHeaderPopup', page);
$('#txtIdentificationHeaderName', popup).val(header.Name || '');
$('#txtIdentificationHeaderValue', popup).val(header.Value || '');
2015-09-03 10:01:51 -07:00
$('#selectMatchType', popup).val(header.Match || 'Equals');
2014-07-17 15:21:35 -07:00
popup.popup('open');
}
function saveIdentificationHeader(page) {
currentSubProfile.Name = $('#txtIdentificationHeaderName', page).val();
currentSubProfile.Value = $('#txtIdentificationHeaderValue', page).val();
currentSubProfile.Match = $('#selectMatchType', page).val();
if (isSubProfileNew) {
currentProfile.Identification.Headers.push(currentSubProfile);
}
renderIdentificationHeaders(page, currentProfile.Identification.Headers);
currentSubProfile = null;
$('#identificationHeaderPopup', page).popup('close');
}
function renderXmlDocumentAttributes(page, attribute) {
var index = 0;
var html = '<ul data-role="listview" data-inset="true" data-split-icon="delete">' + attribute.map(function (h) {
var li = '<li>';
li += '<a href="#">';
li += '<div style="font-weight:normal;">' + h.Name + ' = ' + (h.Value || '') + '</div>';
li += '</a>';
2016-02-08 11:05:29 -07:00
li += '<a class="btnDeleteXmlAttribute" href="#" data-icon="delete" data-index="' + index + '"></a>';
li += '</li>';
index++;
return li;
}).join('') + '</ul>';
var elem = $('.xmlDocumentAttributeList', page).html(html).trigger('create');
$('.btnDeleteXmlAttribute', elem).on('click', function () {
var itemIndex = parseInt(this.getAttribute('data-index'));
currentProfile.XmlRootAttributes.splice(itemIndex, 1);
renderXmlDocumentAttributes(page, currentProfile.XmlRootAttributes);
});
}
function editXmlDocumentAttribute(page, attribute) {
isSubProfileNew = attribute == null;
attribute = attribute || {};
currentSubProfile = attribute;
var popup = $('#xmlAttributePopup', page);
$('#txtXmlAttributeName', popup).val(attribute.Name || '');
$('#txtXmlAttributeValue', popup).val(attribute.Value || '');
popup.popup('open');
}
function saveXmlDocumentAttribute(page) {
currentSubProfile.Name = $('#txtXmlAttributeName', page).val();
currentSubProfile.Value = $('#txtXmlAttributeValue', page).val();
if (isSubProfileNew) {
currentProfile.XmlRootAttributes.push(currentSubProfile);
}
renderXmlDocumentAttributes(page, currentProfile.XmlRootAttributes);
currentSubProfile = null;
$('#xmlAttributePopup', page).popup('close');
}
function renderSubtitleProfiles(page, profiles) {
var index = 0;
var html = '<ul data-role="listview" data-inset="true" data-split-icon="delete">' + profiles.map(function (h) {
var li = '<li>';
li += '<a href="#" class="lnkEditSubProfile" data-index="' + index + '">';
li += '<div style="font-weight:normal;">' + (h.Format || '') + '</div>';
li += '</a>';
2016-02-08 11:05:29 -07:00
li += '<a class="btnDeleteProfile" href="#" data-icon="delete" data-index="' + index + '"></a>';
li += '</li>';
index++;
return li;
}).join('') + '</ul>';
var elem = $('.subtitleProfileList', page).html(html).trigger('create');
$('.btnDeleteProfile', elem).on('click', function () {
var itemIndex = parseInt(this.getAttribute('data-index'));
currentProfile.SubtitleProfiles.splice(itemIndex, 1);
renderSubtitleProfiles(page, currentProfile.SubtitleProfiles);
});
$('.lnkEditSubProfile', elem).on('click', function () {
var itemIndex = parseInt(this.getAttribute('data-index'));
editSubtitleProfile(page, currentProfile.SubtitleProfiles[itemIndex]);
});
}
function editSubtitleProfile(page, profile) {
isSubProfileNew = profile == null;
profile = profile || {};
currentSubProfile = profile;
var popup = $('#subtitleProfilePopup', page);
$('#txtSubtitleProfileFormat', popup).val(profile.Format || '');
2015-09-03 10:01:51 -07:00
$('#selectSubtitleProfileMethod', popup).val(profile.Method || '');
$('#selectSubtitleProfileDidlMode', popup).val(profile.DidlMode || '');
popup.popup('open');
}
function saveSubtitleProfile(page) {
currentSubProfile.Format = $('#txtSubtitleProfileFormat', page).val();
currentSubProfile.Method = $('#selectSubtitleProfileMethod', page).val();
currentSubProfile.DidlMode = $('#selectSubtitleProfileDidlMode', page).val();
if (isSubProfileNew) {
currentProfile.SubtitleProfiles.push(currentSubProfile);
}
renderSubtitleProfiles(page, currentProfile.SubtitleProfiles);
currentSubProfile = null;
$('#subtitleProfilePopup', page).popup('close');
}
2014-03-28 19:28:02 -07:00
function renderSubProfiles(page, profile) {
2014-03-29 08:40:32 -07:00
renderDirectPlayProfiles(page, profile.DirectPlayProfiles);
renderTranscodingProfiles(page, profile.TranscodingProfiles);
renderContainerProfiles(page, profile.ContainerProfiles);
renderCodecProfiles(page, profile.CodecProfiles);
2014-03-31 21:16:35 -07:00
renderResponseProfiles(page, profile.ResponseProfiles);
}
2014-03-28 19:28:02 -07:00
function saveDirectPlayProfile(page) {
currentSubProfile.Type = $('#selectDirectPlayProfileType', page).val();
currentSubProfile.Container = $('#txtDirectPlayContainer', page).val();
currentSubProfile.AudioCodec = $('#txtDirectPlayAudioCodec', page).val();
currentSubProfile.VideoCodec = $('#txtDirectPlayVideoCodec', page).val();
2014-03-29 08:40:32 -07:00
2014-03-28 19:28:02 -07:00
if (isSubProfileNew) {
currentProfile.DirectPlayProfiles.push(currentSubProfile);
2014-03-29 08:40:32 -07:00
}
2014-03-28 19:28:02 -07:00
renderSubProfiles(page, currentProfile);
currentSubProfile = null;
2014-03-29 08:40:32 -07:00
2014-03-28 19:28:02 -07:00
$('#popupEditDirectPlayProfile', page).popup('close');
}
function renderDirectPlayProfiles(page, profiles) {
var html = '';
html += '<ul data-role="listview" data-inset="true" data-split-icon="delete">';
var currentType;
for (var i = 0, length = profiles.length; i < length; i++) {
var profile = profiles[i];
if (profile.Type !== currentType) {
html += '<li data-role="list-divider">' + profile.Type + '</li>';
currentType = profile.Type;
}
html += '<li>';
2014-03-28 19:28:02 -07:00
html += '<a data-profileindex="' + i + '" class="lnkEditSubProfile" href="#">';
2014-07-16 20:17:14 -07:00
html += '<p>' + Globalize.translate('ValueContainer').replace('{0}', (profile.Container || allText)) + '</p>';
if (profile.Type == 'Video') {
2014-07-16 20:17:14 -07:00
html += '<p>' + Globalize.translate('ValueVideoCodec').replace('{0}', (profile.VideoCodec || allText)) + '</p>';
html += '<p>' + Globalize.translate('ValueAudioCodec').replace('{0}', (profile.AudioCodec || allText)) + '</p>';
} else if (profile.Type == 'Audio') {
2014-07-16 20:17:14 -07:00
html += '<p>' + Globalize.translate('ValueCodec').replace('{0}', (profile.AudioCodec || allText)) + '</p>';
}
html += '</a>';
2014-03-28 19:28:02 -07:00
html += '<a href="#" data-icon="delete" class="btnDeleteProfile" data-profileindex="' + i + '">Delete</a>';
html += '</li>';
}
html += '</ul>';
var elem = $('.directPlayProfiles', page).html(html).trigger('create');
2014-03-31 21:16:35 -07:00
$('.btnDeleteProfile', elem).on('click', function () {
2014-03-28 19:28:02 -07:00
var index = this.getAttribute('data-profileindex');
deleteDirectPlayProfile(page, index);
});
2014-03-28 19:28:02 -07:00
2014-03-31 21:16:35 -07:00
$('.lnkEditSubProfile', elem).on('click', function () {
2014-03-28 19:28:02 -07:00
var index = parseInt(this.getAttribute('data-profileindex'));
editDirectPlayProfile(page, currentProfile.DirectPlayProfiles[index]);
});
}
function deleteDirectPlayProfile(page, index) {
currentProfile.DirectPlayProfiles.splice(index, 1);
renderDirectPlayProfiles(page, currentProfile.DirectPlayProfiles);
}
2014-04-07 21:17:18 -07:00
function editDirectPlayProfile(page, directPlayProfile) {
isSubProfileNew = directPlayProfile == null;
directPlayProfile = directPlayProfile || {};
currentSubProfile = directPlayProfile;
var popup = $('#popupEditDirectPlayProfile', page);
2015-09-03 10:01:51 -07:00
$('#selectDirectPlayProfileType', popup).val(directPlayProfile.Type || 'Video').trigger('change');
2014-04-07 21:17:18 -07:00
$('#txtDirectPlayContainer', popup).val(directPlayProfile.Container || '');
$('#txtDirectPlayAudioCodec', popup).val(directPlayProfile.AudioCodec || '');
$('#txtDirectPlayVideoCodec', popup).val(directPlayProfile.VideoCodec || '');
2014-07-16 20:17:14 -07:00
2014-04-07 21:17:18 -07:00
popup.popup('open');
}
function renderTranscodingProfiles(page, profiles) {
var html = '';
html += '<ul data-role="listview" data-inset="true" data-split-icon="delete">';
var currentType;
for (var i = 0, length = profiles.length; i < length; i++) {
var profile = profiles[i];
if (profile.Type !== currentType) {
html += '<li data-role="list-divider">' + profile.Type + '</li>';
currentType = profile.Type;
}
html += '<li>';
html += '<a data-profileindex="' + i + '" class="lnkEditSubProfile" href="#">';
2014-03-28 12:58:18 -07:00
html += '<p>Protocol: ' + (profile.Protocol || 'Http') + '</p>';
2014-07-16 20:17:14 -07:00
html += '<p>' + Globalize.translate('ValueContainer').replace('{0}', (profile.Container || allText)) + '</p>';
if (profile.Type == 'Video') {
2014-07-16 20:17:14 -07:00
html += '<p>' + Globalize.translate('ValueVideoCodec').replace('{0}', (profile.VideoCodec || allText)) + '</p>';
html += '<p>' + Globalize.translate('ValueAudioCodec').replace('{0}', (profile.AudioCodec || allText)) + '</p>';
} else if (profile.Type == 'Audio') {
2014-07-16 20:17:14 -07:00
html += '<p>' + Globalize.translate('ValueCodec').replace('{0}', (profile.AudioCodec || allText)) + '</p>';
}
html += '</a>';
2014-03-28 19:28:02 -07:00
html += '<a href="#" data-icon="delete" class="btnDeleteProfile" data-profileindex="' + i + '">Delete</a>';
html += '</li>';
}
html += '</ul>';
var elem = $('.transcodingProfiles', page).html(html).trigger('create');
2014-03-31 21:16:35 -07:00
$('.btnDeleteProfile', elem).on('click', function () {
2014-03-28 19:28:02 -07:00
var index = this.getAttribute('data-profileindex');
deleteTranscodingProfile(page, index);
});
$('.lnkEditSubProfile', elem).on('click', function () {
var index = parseInt(this.getAttribute('data-profileindex'));
editTranscodingProfile(page, currentProfile.TranscodingProfiles[index]);
});
}
function editTranscodingProfile(page, transcodingProfile) {
isSubProfileNew = transcodingProfile == null;
transcodingProfile = transcodingProfile || {};
currentSubProfile = transcodingProfile;
2014-04-07 21:17:18 -07:00
var popup = $('#transcodingProfilePopup', page);
2015-09-03 10:01:51 -07:00
$('#selectTranscodingProfileType', popup).val(transcodingProfile.Type || 'Video').trigger('change');
$('#txtTranscodingContainer', popup).val(transcodingProfile.Container || '');
$('#txtTranscodingAudioCodec', popup).val(transcodingProfile.AudioCodec || '');
$('#txtTranscodingVideoCodec', popup).val(transcodingProfile.VideoCodec || '');
2015-09-03 10:01:51 -07:00
$('#selectTranscodingProtocol', popup).val(transcodingProfile.Protocol || 'Http');
2014-03-31 21:16:35 -07:00
2014-04-03 15:50:04 -07:00
$('#chkEnableMpegtsM2TsMode', popup).checked(transcodingProfile.EnableMpegtsM2TsMode || false).checkboxradio('refresh');
$('#chkEstimateContentLength', popup).checked(transcodingProfile.EstimateContentLength || false).checkboxradio('refresh');
2014-03-31 21:16:35 -07:00
$('#chkReportByteRangeRequests', popup).checked(transcodingProfile.TranscodeSeekInfo == 'Bytes').checkboxradio('refresh');
2014-04-02 14:55:19 -07:00
2016-02-07 14:16:02 -07:00
$('.radioTabButton:first', popup).trigger('click');
2014-07-16 20:17:14 -07:00
2014-04-07 21:17:18 -07:00
popup.popup('open');
}
function deleteTranscodingProfile(page, index) {
currentProfile.TranscodingProfiles.splice(index, 1);
renderTranscodingProfiles(page, currentProfile.TranscodingProfiles);
}
function saveTranscodingProfile(page) {
currentSubProfile.Type = $('#selectTranscodingProfileType', page).val();
currentSubProfile.Container = $('#txtTranscodingContainer', page).val();
currentSubProfile.AudioCodec = $('#txtTranscodingAudioCodec', page).val();
currentSubProfile.VideoCodec = $('#txtTranscodingVideoCodec', page).val();
2014-07-27 15:01:29 -07:00
currentSubProfile.Protocol = $('#selectTranscodingProtocol', page).val();
2015-01-03 12:38:22 -07:00
currentSubProfile.Context = 'Streaming';
2014-03-31 21:16:35 -07:00
currentSubProfile.EnableMpegtsM2TsMode = $('#chkEnableMpegtsM2TsMode', page).checked();
currentSubProfile.EstimateContentLength = $('#chkEstimateContentLength', page).checked();
currentSubProfile.TranscodeSeekInfo = $('#chkReportByteRangeRequests', page).checked() ? 'Bytes' : 'Auto';
if (isSubProfileNew) {
currentProfile.TranscodingProfiles.push(currentSubProfile);
}
renderSubProfiles(page, currentProfile);
currentSubProfile = null;
$('#transcodingProfilePopup', page).popup('close');
}
function renderContainerProfiles(page, profiles) {
var html = '';
html += '<ul data-role="listview" data-inset="true" data-split-icon="delete">';
var currentType;
for (var i = 0, length = profiles.length; i < length; i++) {
var profile = profiles[i];
if (profile.Type !== currentType) {
html += '<li data-role="list-divider">' + profile.Type + '</li>';
currentType = profile.Type;
}
html += '<li>';
html += '<a data-profileindex="' + i + '" class="lnkEditSubProfile" href="#">';
2014-07-16 20:17:14 -07:00
html += '<p>' + Globalize.translate('ValueContainer').replace('{0}', (profile.Container || allText)) + '</p>';
if (profile.Conditions && profile.Conditions.length) {
2014-07-16 20:17:14 -07:00
html += '<p>';
html += Globalize.translate('ValueConditions').replace('{0}', profile.Conditions.map(function (c) {
return c.Property;
2014-07-16 20:17:14 -07:00
}).join(', '));
html += '</p>';
}
html += '</a>';
2014-03-28 19:28:02 -07:00
html += '<a href="#" data-icon="delete" class="btnDeleteProfile" data-profileindex="' + i + '">Delete</a>';
html += '</li>';
}
html += '</ul>';
var elem = $('.containerProfiles', page).html(html).trigger('create');
2014-03-31 21:16:35 -07:00
$('.btnDeleteProfile', elem).on('click', function () {
2014-03-28 19:28:02 -07:00
var index = this.getAttribute('data-profileindex');
deleteContainerProfile(page, index);
});
2014-04-03 15:50:04 -07:00
$('.lnkEditSubProfile', elem).on('click', function () {
var index = parseInt(this.getAttribute('data-profileindex'));
editContainerProfile(page, currentProfile.ContainerProfiles[index]);
});
}
function deleteContainerProfile(page, index) {
currentProfile.ContainerProfiles.splice(index, 1);
renderContainerProfiles(page, currentProfile.ContainerProfiles);
}
2014-07-16 20:17:14 -07:00
2014-04-03 15:50:04 -07:00
function editContainerProfile(page, containerProfile) {
isSubProfileNew = containerProfile == null;
containerProfile = containerProfile || {};
currentSubProfile = containerProfile;
2014-04-07 21:17:18 -07:00
var popup = $('#containerProfilePopup', page);
2014-04-03 15:50:04 -07:00
2015-09-03 10:01:51 -07:00
$('#selectContainerProfileType', popup).val(containerProfile.Type || 'Video').trigger('change');
2014-04-03 15:50:04 -07:00
$('#txtContainerProfileContainer', popup).val(containerProfile.Container || '');
2014-04-07 21:17:18 -07:00
2016-02-07 14:16:02 -07:00
$('.radioTabButton:first', popup).trigger('click');
2014-07-16 20:17:14 -07:00
2014-04-07 21:17:18 -07:00
popup.popup('open');
2014-04-03 15:50:04 -07:00
}
function saveContainerProfile(page) {
currentSubProfile.Type = $('#selectContainerProfileType', page).val();
currentSubProfile.Container = $('#txtContainerProfileContainer', page).val();
if (isSubProfileNew) {
currentProfile.ContainerProfiles.push(currentSubProfile);
}
renderSubProfiles(page, currentProfile);
currentSubProfile = null;
$('#containerProfilePopup', page).popup('close');
}
function renderCodecProfiles(page, profiles) {
var html = '';
html += '<ul data-role="listview" data-inset="true" data-split-icon="delete">';
var currentType;
for (var i = 0, length = profiles.length; i < length; i++) {
var profile = profiles[i];
var type = profile.Type.replace("VideoAudio", "Video Audio");
if (type !== currentType) {
html += '<li data-role="list-divider">' + type + '</li>';
currentType = type;
}
html += '<li>';
html += '<a data-profileindex="' + i + '" class="lnkEditSubProfile" href="#">';
2014-07-16 20:17:14 -07:00
html += '<p>' + Globalize.translate('ValueCodec').replace('{0}', (profile.Codec || allText)) + '</p>';
if (profile.Conditions && profile.Conditions.length) {
2014-07-16 20:17:14 -07:00
html += '<p>';
html += Globalize.translate('ValueConditions').replace('{0}', profile.Conditions.map(function (c) {
return c.Property;
2014-07-16 20:17:14 -07:00
}).join(', '));
html += '</p>';
}
html += '</a>';
2014-03-28 19:28:02 -07:00
html += '<a href="#" data-icon="delete" class="btnDeleteProfile" data-profileindex="' + i + '">Delete</a>';
html += '</li>';
}
html += '</ul>';
var elem = $('.codecProfiles', page).html(html).trigger('create');
2014-03-31 21:16:35 -07:00
$('.btnDeleteProfile', elem).on('click', function () {
2014-03-28 19:28:02 -07:00
var index = this.getAttribute('data-profileindex');
deleteCodecProfile(page, index);
});
2014-04-03 15:50:04 -07:00
$('.lnkEditSubProfile', elem).on('click', function () {
var index = parseInt(this.getAttribute('data-profileindex'));
editCodecProfile(page, currentProfile.CodecProfiles[index]);
});
}
function deleteCodecProfile(page, index) {
currentProfile.CodecProfiles.splice(index, 1);
renderCodecProfiles(page, currentProfile.CodecProfiles);
}
2014-04-03 15:50:04 -07:00
function editCodecProfile(page, codecProfile) {
isSubProfileNew = codecProfile == null;
codecProfile = codecProfile || {};
currentSubProfile = codecProfile;
2014-04-07 21:17:18 -07:00
var popup = $('#codecProfilePopup', page);
2014-04-03 15:50:04 -07:00
2015-09-03 10:01:51 -07:00
$('#selectCodecProfileType', popup).val(codecProfile.Type || 'Video').trigger('change');
2014-04-03 15:50:04 -07:00
$('#txtCodecProfileCodec', popup).val(codecProfile.Codec || '');
2014-04-07 21:17:18 -07:00
2016-02-07 14:16:02 -07:00
$('.radioTabButton:first', popup).trigger('click');
2014-07-16 20:17:14 -07:00
2014-04-07 21:17:18 -07:00
popup.popup('open');
2014-04-03 15:50:04 -07:00
}
function saveCodecProfile(page) {
currentSubProfile.Type = $('#selectCodecProfileType', page).val();
currentSubProfile.Codec = $('#txtCodecProfileCodec', page).val();
if (isSubProfileNew) {
currentProfile.CodecProfiles.push(currentSubProfile);
}
renderSubProfiles(page, currentProfile);
currentSubProfile = null;
$('#codecProfilePopup', page).popup('close');
}
2014-03-31 21:16:35 -07:00
function renderResponseProfiles(page, profiles) {
var html = '';
html += '<ul data-role="listview" data-inset="true" data-split-icon="delete">';
var currentType;
for (var i = 0, length = profiles.length; i < length; i++) {
var profile = profiles[i];
if (profile.Type !== currentType) {
html += '<li data-role="list-divider">' + profile.Type + '</li>';
currentType = profile.Type;
}
html += '<li>';
html += '<a data-profileindex="' + i + '" class="lnkEditSubProfile" href="#">';
2014-07-16 20:17:14 -07:00
html += '<p>' + Globalize.translate('ValueContainer').replace('{0}', (profile.Container || allText)) + '</p>';
if (profile.Type == 'Video') {
2014-07-16 20:17:14 -07:00
html += '<p>' + Globalize.translate('ValueVideoCodec').replace('{0}', (profile.VideoCodec || allText)) + '</p>';
html += '<p>' + Globalize.translate('ValueAudioCodec').replace('{0}', (profile.AudioCodec || allText)) + '</p>';
} else if (profile.Type == 'Audio') {
2014-07-16 20:17:14 -07:00
html += '<p>' + Globalize.translate('ValueCodec').replace('{0}', (profile.AudioCodec || allText)) + '</p>';
}
if (profile.Conditions && profile.Conditions.length) {
2014-07-16 20:17:14 -07:00
html += '<p>';
html += Globalize.translate('ValueConditions').replace('{0}', profile.Conditions.map(function (c) {
return c.Property;
2014-07-16 20:17:14 -07:00
}).join(', '));
html += '</p>';
}
html += '</a>';
2014-03-28 19:28:02 -07:00
html += '<a href="#" data-icon="delete" class="btnDeleteProfile" data-profileindex="' + i + '">Delete</a>';
html += '</li>';
}
html += '</ul>';
var elem = $('.mediaProfiles', page).html(html).trigger('create');
2014-03-31 21:16:35 -07:00
$('.btnDeleteProfile', elem).on('click', function () {
2014-03-28 19:28:02 -07:00
var index = this.getAttribute('data-profileindex');
2014-03-31 21:16:35 -07:00
deleteResponseProfile(page, index);
});
2014-04-07 21:17:18 -07:00
$('.lnkEditSubProfile', elem).on('click', function () {
var index = parseInt(this.getAttribute('data-profileindex'));
2014-07-16 20:17:14 -07:00
2014-04-07 21:17:18 -07:00
editResponseProfile(page, currentProfile.ResponseProfiles[index]);
});
}
2014-03-31 21:16:35 -07:00
function deleteResponseProfile(page, index) {
2014-03-31 21:16:35 -07:00
currentProfile.ResponseProfiles.splice(index, 1);
2014-03-31 21:16:35 -07:00
renderResponseProfiles(page, currentProfile.ResponseProfiles);
2014-04-07 21:17:18 -07:00
}
2014-04-07 21:17:18 -07:00
function editResponseProfile(page, responseProfile) {
isSubProfileNew = responseProfile == null;
responseProfile = responseProfile || {};
currentSubProfile = responseProfile;
var popup = $('#responseProfilePopup', page);
2015-09-03 10:01:51 -07:00
$('#selectResponseProfileType', popup).val(responseProfile.Type || 'Video').trigger('change');
2014-04-07 21:17:18 -07:00
$('#txtResponseProfileContainer', popup).val(responseProfile.Container || '');
$('#txtResponseProfileAudioCodec', popup).val(responseProfile.AudioCodec || '');
$('#txtResponseProfileVideoCodec', popup).val(responseProfile.VideoCodec || '');
2016-02-07 14:16:02 -07:00
$('.radioTabButton:first', popup).trigger('click');
2014-04-07 21:17:18 -07:00
popup.popup('open');
}
function saveResponseProfile(page) {
currentSubProfile.Type = $('#selectResponseProfileType', page).val();
currentSubProfile.Container = $('#txtResponseProfileContainer', page).val();
currentSubProfile.AudioCodec = $('#txtResponseProfileAudioCodec', page).val();
currentSubProfile.VideoCodec = $('#txtResponseProfileVideoCodec', page).val();
if (isSubProfileNew) {
currentProfile.ResponseProfiles.push(currentSubProfile);
}
renderSubProfiles(page, currentProfile);
currentSubProfile = null;
$('#responseProfilePopup', page).popup('close');
2014-03-26 13:14:47 -07:00
}
function saveProfile(page, profile) {
updateProfile(page, profile);
var id = getParameterByName('id');
if (id) {
2014-07-01 22:16:59 -07:00
ApiClient.ajax({
2014-03-26 13:14:47 -07:00
type: "POST",
url: ApiClient.getUrl("Dlna/Profiles/" + id),
data: JSON.stringify(profile),
contentType: "application/json"
2015-12-14 08:43:03 -07:00
}).then(function () {
2014-03-26 13:14:47 -07:00
2016-02-24 23:38:12 -07:00
require(['toast'], function (toast) {
toast('Settings saved.');
});
2016-04-23 13:23:37 -07:00
}, Dashboard.processErrorResponse);
2014-03-26 13:14:47 -07:00
} else {
2014-07-01 22:16:59 -07:00
ApiClient.ajax({
2014-03-26 13:14:47 -07:00
type: "POST",
url: ApiClient.getUrl("Dlna/Profiles"),
data: JSON.stringify(profile),
contentType: "application/json"
2015-12-14 08:43:03 -07:00
}).then(function () {
2014-03-26 13:14:47 -07:00
Dashboard.navigate('dlnaprofiles.html');
2016-04-23 13:23:37 -07:00
}, Dashboard.processErrorResponse);
2014-03-26 13:14:47 -07:00
}
Dashboard.hideLoadingMsg();
}
function updateProfile(page, profile) {
profile.Name = $('#txtName', page).val();
profile.EnableAlbumArtInDidl = $('#chkEnableAlbumArtInDidl', page).checked();
profile.EnableSingleAlbumArtLimit = $('#chkEnableSingleImageLimit', page).checked();
2014-03-31 21:16:35 -07:00
profile.SupportedMediaTypes = $('.chkMediaType:checked', page).get().map(function (c) {
return c.getAttribute('data-value');
}).join(',');
profile.Identification = profile.Identification || {};
2014-04-28 08:05:28 -07:00
profile.FriendlyName = $('#txtInfoFriendlyName', page).val();
profile.ModelName = $('#txtInfoModelName', page).val();
profile.ModelNumber = $('#txtInfoModelNumber', page).val();
profile.ModelDescription = $('#txtInfoModelDescription', page).val();
profile.ModelUrl = $('#txtInfoModelUrl', page).val();
profile.Manufacturer = $('#txtInfoManufacturer', page).val();
profile.ManufacturerUrl = $('#txtInfoManufacturerUrl', page).val();
profile.SerialNumber = $('#txtInfoSerialNumber', page).val();
profile.Identification.FriendlyName = $('#txtIdFriendlyName', page).val();
profile.Identification.ModelName = $('#txtIdModelName', page).val();
profile.Identification.ModelNumber = $('#txtIdModelNumber', page).val();
profile.Identification.ModelDescription = $('#txtIdModelDescription', page).val();
profile.Identification.ModelUrl = $('#txtIdModelUrl', page).val();
profile.Identification.Manufacturer = $('#txtIdManufacturer', page).val();
profile.Identification.ManufacturerUrl = $('#txtIdManufacturerUrl', page).val();
profile.Identification.SerialNumber = $('#txtIdSerialNumber', page).val();
profile.Identification.DeviceDescription = $('#txtIdDeviceDescription', page).val();
2014-04-19 22:21:08 -07:00
profile.AlbumArtPn = $('#txtAlbumArtPn', page).val();
profile.MaxAlbumArtWidth = $('#txtAlbumArtMaxWidth', page).val();
profile.MaxAlbumArtHeight = $('#txtAlbumArtMaxHeight', page).val();
profile.MaxIconWidth = $('#txtIconMaxWidth', page).val();
profile.MaxIconHeight = $('#txtIconMaxHeight', page).val();
profile.RequiresPlainFolders = $('#chkRequiresPlainFolders', page).checked();
profile.RequiresPlainVideoItems = $('#chkRequiresPlainVideoItems', page).checked();
profile.IgnoreTranscodeByteRangeRequests = $('#chkIgnoreTranscodeByteRangeRequests', page).checked();
2014-07-27 15:01:29 -07:00
profile.MaxStreamingBitrate = $('#txtMaxAllowedBitrate', page).val();
2014-08-14 06:24:30 -07:00
profile.MusicStreamingTranscodingBitrate = $('#txtMusicStreamingTranscodingBitrate', page).val();
2014-06-24 14:45:21 -07:00
profile.ProtocolInfo = $('#txtProtocolInfo', page).val();
2014-04-22 10:25:54 -07:00
profile.XDlnaCap = $('#txtXDlnaCap', page).val();
profile.XDlnaDoc = $('#txtXDlnaDoc', page).val();
profile.SonyAggregationFlags = $('#txtSonyAggregationFlags', page).val();
2014-04-19 22:21:08 -07:00
profile.UserId = $('#selectUser', page).val();
2014-03-26 12:21:29 -07:00
}
2015-09-01 07:01:59 -07:00
$(document).on('pageinit', "#dlnaProfilePage", function () {
2014-03-27 12:30:21 -07:00
var page = this;
2016-02-07 14:16:02 -07:00
$('.radioTabButton', page).on('click', function () {
2014-03-27 12:30:21 -07:00
2016-02-07 14:16:02 -07:00
$(this).siblings().removeClass('ui-btn-active');
$(this).addClass('ui-btn-active');
2016-02-08 21:46:25 -07:00
var value = this.tagName == 'A' ? this.getAttribute('data-value') : this.value;
var elem = $('.' + value, page);
2014-04-02 14:55:19 -07:00
elem.siblings('.tabContent').hide();
2014-03-27 12:30:21 -07:00
2014-04-02 14:55:19 -07:00
elem.show();
2014-03-27 12:30:21 -07:00
});
2014-03-31 21:16:35 -07:00
$('#selectDirectPlayProfileType', page).on('change', function () {
2014-03-28 19:28:02 -07:00
if (this.value == 'Video') {
$('#fldDirectPlayVideoCodec', page).show();
} else {
$('#fldDirectPlayVideoCodec', page).hide();
}
if (this.value == 'Photo') {
$('#fldDirectPlayAudioCodec', page).hide();
} else {
$('#fldDirectPlayAudioCodec', page).show();
}
});
$('#selectTranscodingProfileType', page).on('change', function () {
if (this.value == 'Video') {
$('#fldTranscodingVideoCodec', page).show();
2014-07-27 15:01:29 -07:00
$('#fldTranscodingProtocol', page).show();
2014-03-31 21:16:35 -07:00
$('#fldEnableMpegtsM2TsMode', page).show();
} else {
$('#fldTranscodingVideoCodec', page).hide();
2014-07-27 15:01:29 -07:00
$('#fldTranscodingProtocol', page).hide();
2014-03-31 21:16:35 -07:00
$('#fldEnableMpegtsM2TsMode', page).hide();
}
if (this.value == 'Photo') {
$('#fldTranscodingAudioCodec', page).hide();
2014-03-31 21:16:35 -07:00
$('#fldEstimateContentLength', page).hide();
$('#fldReportByteRangeRequests', page).hide();
} else {
$('#fldTranscodingAudioCodec', page).show();
2014-03-31 21:16:35 -07:00
$('#fldEstimateContentLength', page).show();
$('#fldReportByteRangeRequests', page).show();
}
});
2014-04-07 21:17:18 -07:00
$('#selectResponseProfileType', page).on('change', function () {
if (this.value == 'Video') {
$('#fldResponseProfileVideoCodec', page).show();
} else {
$('#fldResponseProfileVideoCodec', page).hide();
}
if (this.value == 'Photo') {
$('#fldResponseProfileAudioCodec', page).hide();
} else {
$('#fldResponseProfileAudioCodec', page).show();
}
});
2014-03-31 21:16:35 -07:00
$('.btnAddDirectPlayProfile', page).on('click', function () {
2014-03-29 08:40:32 -07:00
editDirectPlayProfile(page);
});
$('.btnAddTranscodingProfile', page).on('click', function () {
editTranscodingProfile(page);
});
2014-07-16 20:17:14 -07:00
2014-04-03 15:50:04 -07:00
$('.btnAddContainerProfile', page).on('click', function () {
editContainerProfile(page);
});
2014-07-16 20:17:14 -07:00
2014-04-03 15:50:04 -07:00
$('.btnAddCodecProfile', page).on('click', function () {
editCodecProfile(page);
});
2014-04-07 21:17:18 -07:00
$('.btnAddResponseProfile', page).on('click', function () {
editResponseProfile(page);
});
2014-07-17 15:21:35 -07:00
$('.btnAddIdentificationHttpHeader', page).on('click', function () {
editIdentificationHeader(page);
});
$('.btnAddXmlDocumentAttribute', page).on('click', function () {
editXmlDocumentAttribute(page);
});
$('.btnAddSubtitleProfile', page).on('click', function () {
editSubtitleProfile(page);
});
2015-06-07 18:23:56 -07:00
$('.dlnaProfileForm').off('submit', DlnaProfilePage.onSubmit).on('submit', DlnaProfilePage.onSubmit);
$('.editDirectPlayProfileForm').off('submit', DlnaProfilePage.onDirectPlayFormSubmit).on('submit', DlnaProfilePage.onDirectPlayFormSubmit);
$('.transcodingProfileForm').off('submit', DlnaProfilePage.onTranscodingProfileFormSubmit).on('submit', DlnaProfilePage.onTranscodingProfileFormSubmit);
$('.containerProfileForm').off('submit', DlnaProfilePage.onContainerProfileFormSubmit).on('submit', DlnaProfilePage.onContainerProfileFormSubmit);
$('.codecProfileForm').off('submit', DlnaProfilePage.onCodecProfileFormSubmit).on('submit', DlnaProfilePage.onCodecProfileFormSubmit);
$('.editResponseProfileForm').off('submit', DlnaProfilePage.onResponseProfileFormSubmit).on('submit', DlnaProfilePage.onResponseProfileFormSubmit);
$('.identificationHeaderForm').off('submit', DlnaProfilePage.onIdentificationHeaderFormSubmit).on('submit', DlnaProfilePage.onIdentificationHeaderFormSubmit);
$('.xmlAttributeForm').off('submit', DlnaProfilePage.onXmlAttributeFormSubmit).on('submit', DlnaProfilePage.onXmlAttributeFormSubmit);
$('.subtitleProfileForm').off('submit', DlnaProfilePage.onSubtitleProfileFormSubmit).on('submit', DlnaProfilePage.onSubtitleProfileFormSubmit);
2014-03-26 12:21:29 -07:00
2015-09-24 10:08:10 -07:00
}).on('pageshow', "#dlnaProfilePage", function () {
2014-03-27 12:30:21 -07:00
var page = this;
2016-02-07 14:16:02 -07:00
$('#radioInfo', page).trigger('click');
2014-03-27 12:30:21 -07:00
2015-06-07 18:23:56 -07:00
loadProfile(page);
2014-03-26 12:21:29 -07:00
});
2014-03-26 13:14:47 -07:00
window.DlnaProfilePage = {
2014-03-31 21:16:35 -07:00
onSubmit: function () {
2014-03-26 13:14:47 -07:00
Dashboard.showLoadingMsg();
var form = this;
var page = $(form).parents('.page');
saveProfile(page, currentProfile);
2014-03-26 12:21:29 -07:00
2014-03-28 19:28:02 -07:00
return false;
},
2014-03-31 21:16:35 -07:00
onDirectPlayFormSubmit: function () {
2014-03-28 19:28:02 -07:00
var form = this;
var page = $(form).parents('.page');
saveDirectPlayProfile(page);
2014-03-26 12:21:29 -07:00
return false;
},
2014-03-31 21:16:35 -07:00
onTranscodingProfileFormSubmit: function () {
var form = this;
var page = $(form).parents('.page');
saveTranscodingProfile(page);
return false;
2014-04-03 15:50:04 -07:00
},
2014-07-16 20:17:14 -07:00
onContainerProfileFormSubmit: function () {
2014-04-03 15:50:04 -07:00
var form = this;
var page = $(form).parents('.page');
saveContainerProfile(page);
return false;
},
2014-07-16 20:17:14 -07:00
onCodecProfileFormSubmit: function () {
2014-04-03 15:50:04 -07:00
var form = this;
var page = $(form).parents('.page');
saveCodecProfile(page);
2014-04-07 21:17:18 -07:00
return false;
},
2014-07-16 20:17:14 -07:00
onResponseProfileFormSubmit: function () {
2014-04-07 21:17:18 -07:00
var form = this;
var page = $(form).parents('.page');
saveResponseProfile(page);
2014-07-17 15:21:35 -07:00
return false;
},
onIdentificationHeaderFormSubmit: function () {
2014-07-17 15:21:35 -07:00
var form = this;
var page = $(form).parents('.page');
saveIdentificationHeader(page);
return false;
},
onXmlAttributeFormSubmit: function () {
var form = this;
var page = $(form).parents('.page');
saveXmlDocumentAttribute(page);
return false;
},
onSubtitleProfileFormSubmit: function () {
var form = this;
var page = $(form).parents('.page');
saveSubtitleProfile(page);
2014-04-03 15:50:04 -07:00
return false;
2014-03-26 12:21:29 -07:00
}
};
});