WIP javascript app

This commit is contained in:
John Woodlock
2012-06-28 13:40:24 +10:00
parent 3c2d0333e2
commit 17dac4ae03
+15 -39
View File
@@ -297,17 +297,9 @@ function jsViewsRegisterHelpers() {
}; };
function popupDialogWithFormView(getUrl, postUrl, submitType, titleCode, templateSelector, width, height, saveSuccessFunction) { function popupDialogWithFormView(getUrl, postUrl, submitType, titleCode, templateSelector, width, height, saveSuccessFunction) {
var dialogDiv = $("<div id='dialog-form'></div>"); var dialogDiv = $("<div id='dialog-form'></div>");
var jqxhr = $.ajax({
url: getUrl, var successFunction = function(data, textStatus, jqXHR) {
type: 'GET',
contentType: 'application/json',
dataType: 'json',
cache: false,
beforeSend: function(xhr) {
xhr.setRequestHeader("Authorization", "Basic " + base64);
},
success: function(data, textStatus, jqXHR) {
console.log(data); console.log(data);
var formHtml = $(templateSelector).render(data); var formHtml = $(templateSelector).render(data);
@@ -321,30 +313,17 @@ function jsViewsRegisterHelpers() {
$('#notSelectedItems option').each(function(i) { $('#notSelectedItems option').each(function(i) {
$(this).attr("selected", "selected"); $(this).attr("selected", "selected");
}); });
$('#selectedItems option').each(function(i) { $('#selectedItems option').each(function(i) {
$(this).attr("selected", "selected"); $(this).attr("selected", "selected");
}); });
var newFormData = JSON.stringify($('#entityform').serializeObject()); var newFormData = JSON.stringify($('#entityform').serializeObject());
console.log(newFormData); console.log(newFormData);
var jqxhr = $.ajax({ executeAjaxRequest(postUrl, submitType, newFormData, base64, saveSuccessFunction, formErrorFunction);
url: postUrl,
type: submitType,
contentType: 'application/json',
dataType: 'json',
data: newFormData,
success: saveSuccessFunction,
cache: false,
beforeSend: function(xhr) {
xhr.setRequestHeader("Authorization", "Basic " + base64);
},
error: function(jqXHR, textStatus, errorThrown) {
handleXhrError(jqXHR, textStatus, errorThrown, "#formErrorsTemplate", "#formerrors");
}
});
}; };
buttonsOpts[cancelButton] = function() {$(this).dialog( "close" );}; buttonsOpts[cancelButton] = function() {$(this).dialog( "close" );};
@@ -375,12 +354,10 @@ function jsViewsRegisterHelpers() {
$('#entityform input').first().focus(); $('#entityform input').first().focus();
} }
}).dialog('open'); }).dialog('open');
} };
});
jqxhr.error(function(jqXHR, textStatus, errorThrown) { executeAjaxRequest(getUrl, "GET", "", base64, successFunction, formErrorFunction);
handleXhrError(jqXHR, textStatus, errorThrown, "#formErrorsTemplate", "#formerrors");
});
} }
@@ -764,7 +741,6 @@ alert("here");
eval(genRefreshNoteWidgetSuccessVar(clientUrl)); eval(genRefreshNoteWidgetSuccessVar(clientUrl));
executeAjaxRequest(clientUrl + '/notes', 'GET', "", base64, successFunction, formErrorFunction); executeAjaxRequest(clientUrl + '/notes', 'GET', "", base64, successFunction, formErrorFunction);
} }
function genRefreshNoteWidgetSuccessVar(clientUrl) { function genRefreshNoteWidgetSuccessVar(clientUrl) {
var retVar = 'var successFunction = function(data, textStatus, jqXHR) { ' + var retVar = 'var successFunction = function(data, textStatus, jqXHR) { ' +
@@ -782,7 +758,7 @@ alert("here");
' var height = 400;' + ' var height = 400;' +
' var saveSuccessFunction = function(data, textStatus, jqXHR) {' + ' var saveSuccessFunction = function(data, textStatus, jqXHR) {' +
' $("#dialog-form").dialog("close");' + ' $("#dialog-form").dialog("close");' +
' refreshNoteWidget();' + ' refreshNoteWidget("' + clientUrl + '");' +
' };' + ' };' +
' popupDialogWithFormView(getAndPutUrl, getAndPutUrl, "PUT", "dialog.title.edit.note", templateSelector, width, height, saveSuccessFunction);' + ' popupDialogWithFormView(getAndPutUrl, getAndPutUrl, "PUT", "dialog.title.edit.note", templateSelector, width, height, saveSuccessFunction);' +
' e.preventDefault();' + ' e.preventDefault();' +