stub out profile edit page

This commit is contained in:
Luke Pulverenti 2014-03-26 16:14:47 -04:00
parent da74410dfb
commit 8ce24c1c53
2 changed files with 87 additions and 12 deletions

View File

@ -11,17 +11,24 @@
<div data-role="controlgroup" data-type="horizontal" class="localnav" data-mini="true"> <div data-role="controlgroup" data-type="horizontal" class="localnav" data-mini="true">
<a href="dlnasettings.html" data-role="button">Settings</a> <a href="dlnasettings.html" data-role="button">Settings</a>
<a href="#" data-role="button" class="ui-btn-active">Profiles</a> <a href="dlnaprofiles.html" data-role="button" class="ui-btn-active">Profiles</a>
</div> </div>
<form class="dlnaProfileForm"> <form class="dlnaProfileForm">
<ul data-role="listview" class="ulForm"> <ul data-role="listview" class="ulForm">
<li> <li>
<button type="submit" data-theme="b" data-icon="check" data-mini="true"> <label for="txtName">Name</label>
<input type="text" id="txtName" data-mini="true" required="required" />
</li>
</ul>
<ul data-role="listview" class="ulForm">
<li>
<button class="btnSave" style="display: none;" type="submit" data-theme="b" data-icon="check" data-mini="true">
Save Save
</button> </button>
<button type="button" onclick="Dashboard.navigate('dashboard.html');" data-icon="delete" data-mini="true"> <button type="button" onclick="Dashboard.navigate('dlnaprofiles.html');" data-icon="delete" data-mini="true">
Cancel Cancel
</button> </button>
</li> </li>

View File

@ -4,20 +4,78 @@
Dashboard.showLoadingMsg(); Dashboard.showLoadingMsg();
var id = getParameterByName('id'); getProfile().done(function (result) {
var url = id ? 'Dlna/Profiles/' + id :
'Dlna/Profiles/Default';
$.getJSON(ApiClient.getUrl(url)).done(function (result) {
renderProfile(page, result); renderProfile(page, result);
Dashboard.hideLoadingMsg(); Dashboard.hideLoadingMsg();
}); });
} }
function getProfile() {
var id = getParameterByName('id');
var url = id ? 'Dlna/Profiles/' + id :
'Dlna/Profiles/Default';
return $.getJSON(ApiClient.getUrl(url));
}
function renderProfile(page, profile) { function renderProfile(page, profile) {
if (profile.ProfileType == 'User' || !profile.Id) {
$('.btnSave', page).show();
} else {
$('.btnSave', page).hide();
}
$('#txtName', page).val(profile.Name);
}
function saveProfile(page, profile) {
updateProfile(page, profile);
var id = getParameterByName('id');
if (id) {
$.ajax({
type: "POST",
url: ApiClient.getUrl("Dlna/Profiles/" + id),
data: JSON.stringify(profile),
contentType: "application/json"
}).done(function () {
Dashboard.alert('Settings saved.');
});
} else {
$.ajax({
type: "POST",
url: ApiClient.getUrl("Dlna/Profiles"),
data: JSON.stringify(profile),
contentType: "application/json"
}).done(function () {
Dashboard.navigate('dlnaprofiles.html');
});
}
Dashboard.hideLoadingMsg();
}
function updateProfile(page, profile) {
profile.Name = $('#txtName', page).val();
} }
$(document).on('pageshow', "#dlnaProfilePage", function () { $(document).on('pageshow', "#dlnaProfilePage", function () {
@ -28,9 +86,19 @@
}); });
window.DlnaProfilePage = { window.DlnaProfilePage = {
onSubmit: function() { onSubmit: function () {
Dashboard.showLoadingMsg();
var form = this;
var page = $(form).parents('.page');
getProfile().done(function (profile) {
saveProfile(page, profile);
});
return false; return false;
} }