2013-04-15 18:46:17 -07:00
|
|
|
|
(function ($, document, window) {
|
2013-02-20 18:33:05 -07:00
|
|
|
|
|
2013-04-15 18:46:17 -07:00
|
|
|
|
function onSaveComplete() {
|
|
|
|
|
Dashboard.hideLoadingMsg();
|
2013-02-20 18:33:05 -07:00
|
|
|
|
|
2013-04-15 18:46:17 -07:00
|
|
|
|
Dashboard.navigate('wizardlibrary.html');
|
|
|
|
|
}
|
2013-02-20 18:33:05 -07:00
|
|
|
|
|
2013-04-15 18:46:17 -07:00
|
|
|
|
function wizardUserPage() {
|
2013-02-20 18:33:05 -07:00
|
|
|
|
|
2013-04-15 18:46:17 -07:00
|
|
|
|
var self = this;
|
2013-02-20 18:33:05 -07:00
|
|
|
|
|
2013-04-15 18:46:17 -07:00
|
|
|
|
self.onSubmit = function () {
|
|
|
|
|
Dashboard.showLoadingMsg();
|
2013-02-20 18:33:05 -07:00
|
|
|
|
|
2013-04-15 18:46:17 -07:00
|
|
|
|
var page = $.mobile.activePage;
|
2013-02-20 18:33:05 -07:00
|
|
|
|
|
2013-04-15 18:46:17 -07:00
|
|
|
|
ApiClient.getUsers().done(function (users) {
|
2013-02-20 18:33:05 -07:00
|
|
|
|
|
2013-04-15 18:46:17 -07:00
|
|
|
|
var user;
|
2013-02-20 18:33:05 -07:00
|
|
|
|
|
2013-04-15 18:46:17 -07:00
|
|
|
|
if (users.length) {
|
2013-02-20 18:33:05 -07:00
|
|
|
|
|
2013-04-15 18:46:17 -07:00
|
|
|
|
user = users[0];
|
2013-02-20 18:33:05 -07:00
|
|
|
|
|
2013-04-15 18:46:17 -07:00
|
|
|
|
user.Name = $('#txtUsername', page).val();
|
2013-02-20 18:33:05 -07:00
|
|
|
|
|
2013-04-15 18:46:17 -07:00
|
|
|
|
ApiClient.updateUser(user).done(onSaveComplete);
|
2013-02-20 18:33:05 -07:00
|
|
|
|
|
2013-04-15 18:46:17 -07:00
|
|
|
|
} else {
|
2013-02-20 18:33:05 -07:00
|
|
|
|
|
2013-04-15 18:46:17 -07:00
|
|
|
|
user = { Name: $('#txtUsername', page).val() };
|
2013-02-20 18:33:05 -07:00
|
|
|
|
|
2013-04-15 18:46:17 -07:00
|
|
|
|
ApiClient.createUser(user).done(onSaveComplete);
|
|
|
|
|
}
|
2013-02-20 18:33:05 -07:00
|
|
|
|
|
2013-04-15 18:46:17 -07:00
|
|
|
|
});
|
2013-02-20 18:33:05 -07:00
|
|
|
|
|
2013-04-15 18:46:17 -07:00
|
|
|
|
return false;
|
|
|
|
|
};
|
2013-02-20 18:33:05 -07:00
|
|
|
|
}
|
|
|
|
|
|
2013-04-15 18:46:17 -07:00
|
|
|
|
$(document).on('pageshow', "#wizardUserPage", function () {
|
|
|
|
|
|
|
|
|
|
Dashboard.showLoadingMsg();
|
|
|
|
|
|
|
|
|
|
var page = this;
|
|
|
|
|
|
|
|
|
|
ApiClient.getUsers().done(function (users) {
|
|
|
|
|
|
|
|
|
|
var user = users[0] || { Name: "User" };
|
|
|
|
|
|
|
|
|
|
$('#txtUsername', page).val(user.Name);
|
|
|
|
|
|
|
|
|
|
Dashboard.hideLoadingMsg();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
window.WizardUserPage = new wizardUserPage();
|
2013-02-20 18:33:05 -07:00
|
|
|
|
|
2013-04-15 18:46:17 -07:00
|
|
|
|
})(jQuery, document, window);
|