solving merge conflict
This commit is contained in:
@@ -91,55 +91,68 @@ jQuery.fn.dialogForm = function (options) {
|
||||
formData[elem.name] = elem.value;
|
||||
});
|
||||
|
||||
// Success actions ...
|
||||
var onSuccess = function (jqXHR, textStatus, data) {
|
||||
var resourceId = jqXHR.getResponseHeader("ResourceId");
|
||||
if (options.redirect) {
|
||||
var redirectUrl = options.redirect;
|
||||
redirectUrl = redirectUrl.replace("{header.resourceId}", resourceId);
|
||||
|
||||
// Hack: IE ignore the base href tag ...
|
||||
var baseUrl = window.location.href.substring(0, window.location.href.lastIndexOf("c/maps/"));
|
||||
window.open(baseUrl + redirectUrl, '_self');
|
||||
|
||||
} else if (options.postUpdate) {
|
||||
options.postUpdate(formData, resourceId);
|
||||
}
|
||||
dialogElem.modal('hide');
|
||||
};
|
||||
|
||||
// On error message
|
||||
var onFailure = function (jqXHR, textStatus, data) {
|
||||
var errors = JSON.parse(jqXHR.responseText);
|
||||
// Mark fields with errors ...
|
||||
var fieldErrors = errors.fieldErrors;
|
||||
if (fieldErrors) {
|
||||
for (var fieldName in fieldErrors) {
|
||||
// Mark the field with errors ...
|
||||
var message = fieldErrors[fieldName];
|
||||
var inputField = $("#" + containerId + " input[name='" + fieldName + "']");
|
||||
|
||||
$("#" + containerId).find(".errorMessage").text(message).addClass("alert alert-error");
|
||||
inputField.parent().addClass('error');
|
||||
}
|
||||
}
|
||||
var acceptBtn = $('#' + containerId + ' .btn-accept');
|
||||
acceptBtn.button('reset');
|
||||
};
|
||||
|
||||
var onError = function (jqXHR, textStatus, errorThrown) {
|
||||
console.log(errorThrown);
|
||||
console.log(jqXHR);
|
||||
dialogElem.modal('hide');
|
||||
$('#messagesPanel div div').text(errorThrown);
|
||||
$('#messagesPanel').show()
|
||||
var acceptBtn = $('#' + containerId + ' .btn-accept');
|
||||
acceptBtn.button('reset');
|
||||
};
|
||||
|
||||
$(acceptBtn).button('loading');
|
||||
var dialogElem = this;
|
||||
jQuery.ajax(url, {
|
||||
async:false,
|
||||
//dataType:'json', comentado momentaneamente, problema con jquery 2.1.0
|
||||
data:JSON.stringify(formData),
|
||||
type:options.type ? options.type : 'POST',
|
||||
contentType:"application/json; charset=utf-8",
|
||||
success:function (data, textStatus, jqXHR) {
|
||||
var resourceId = jqXHR.getResponseHeader("ResourceId");
|
||||
if (options.redirect) {
|
||||
var redirectUrl = options.redirect;
|
||||
redirectUrl = redirectUrl.replace("{header.resourceId}", resourceId);
|
||||
|
||||
// Hack: IE ignore the base href tag ...
|
||||
var baseUrl = window.location.href.substring(0, window.location.href.lastIndexOf("c/maps/"));
|
||||
window.open(baseUrl + redirectUrl, '_self');
|
||||
|
||||
} else if (options.postUpdate) {
|
||||
options.postUpdate(formData, resourceId);
|
||||
}
|
||||
dialogElem.modal('hide');
|
||||
},
|
||||
error:function (jqXHR, textStatus, errorThrown) {
|
||||
if (jqXHR.status == 400) {
|
||||
var errors = JSON.parse(jqXHR.responseText);
|
||||
// Mark fields with errors ...
|
||||
var fieldErrors = errors.fieldErrors;
|
||||
if (fieldErrors) {
|
||||
for (var fieldName in fieldErrors) {
|
||||
// Mark the field with errors ...
|
||||
var message = fieldErrors[fieldName];
|
||||
var inputField = $("#" + containerId + " input[name='" + fieldName + "']");
|
||||
|
||||
$("#" + containerId).find(".errorMessage").text(message).addClass("alert alert-error");
|
||||
inputField.parent().addClass('error');
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
console.log(errorThrown);
|
||||
console.log(jqXHR);
|
||||
dialogElem.modal('hide');
|
||||
$('#messagesPanel div div').text(errorThrown);
|
||||
$('#messagesPanel').show()
|
||||
}
|
||||
var acceptBtn = $('#' + containerId + ' .btn-accept');
|
||||
acceptBtn.button('reset');
|
||||
|
||||
async: false,
|
||||
dataType: 'json',
|
||||
data: JSON.stringify(formData),
|
||||
type: options.type ? options.type : 'POST',
|
||||
contentType: "application/json; charset=utf-8",
|
||||
statusCode: {
|
||||
200: onSuccess,
|
||||
201: onSuccess,
|
||||
204: onSuccess,
|
||||
400: onFailure,
|
||||
444: onError,
|
||||
500: onError,
|
||||
501: onError
|
||||
}
|
||||
});
|
||||
}.bind(this));
|
||||
@@ -205,12 +218,12 @@ function updateStarred(spanElem) {
|
||||
}
|
||||
|
||||
jQuery.ajax("c/restful/maps/" + mapId + "/starred", {
|
||||
async:false,
|
||||
dataType:'json',
|
||||
data:"" + starred,
|
||||
type:'PUT',
|
||||
contentType:"text/plain",
|
||||
success:function () {
|
||||
async: false,
|
||||
dataType: 'json',
|
||||
data: "" + starred,
|
||||
type: 'PUT',
|
||||
contentType: "text/plain",
|
||||
success: function () {
|
||||
if (starred) {
|
||||
$(spanElem).removeClass('starredOff');
|
||||
$(spanElem).addClass('starredOn');
|
||||
@@ -219,7 +232,7 @@ function updateStarred(spanElem) {
|
||||
$(spanElem).addClass('starredOff');
|
||||
}
|
||||
},
|
||||
error:function (jqXHR, textStatus, errorThrown) {
|
||||
error: function (jqXHR, textStatus, errorThrown) {
|
||||
$('#messagesPanel div').text(errorThrown).parent().show();
|
||||
}
|
||||
});
|
||||
@@ -248,8 +261,8 @@ $(function () {
|
||||
$("#newBtn").click(
|
||||
function () {
|
||||
$("#new-dialog-modal").dialogForm({
|
||||
redirect:"c/maps/{header.resourceId}/edit",
|
||||
url:"c/restful/maps"
|
||||
redirect: "c/maps/{header.resourceId}/edit",
|
||||
url: "c/restful/maps"
|
||||
});
|
||||
}
|
||||
);
|
||||
@@ -308,8 +321,8 @@ $(function () {
|
||||
|
||||
// Initialize dialog ...
|
||||
$("#duplicate-dialog-modal").dialogForm({
|
||||
redirect:"c/maps/{header.resourceId}/edit",
|
||||
url:"c/restful/maps/" + mapId
|
||||
redirect: "c/maps/{header.resourceId}/edit",
|
||||
url: "c/restful/maps/" + mapId
|
||||
});
|
||||
}
|
||||
});
|
||||
@@ -334,16 +347,16 @@ $(function () {
|
||||
|
||||
// Initialize dialog ...
|
||||
$("#rename-dialog-modal").dialogForm({
|
||||
type:'PUT',
|
||||
clearForm:false,
|
||||
postUpdate:function (reqBodyData) {
|
||||
type: 'PUT',
|
||||
clearForm: false,
|
||||
postUpdate: function (reqBodyData) {
|
||||
tableElem.dataTableExt.removeSelectedRows();
|
||||
|
||||
rowData.title = reqBodyData.title;
|
||||
rowData.description = reqBodyData.description;
|
||||
dataTable.fnAddData(JSON.parse(JSON.stringify(rowData)));
|
||||
},
|
||||
url:"c/restful/maps/" + mapId
|
||||
url: "c/restful/maps/" + mapId
|
||||
});
|
||||
}
|
||||
});
|
||||
@@ -356,12 +369,12 @@ $(function () {
|
||||
if (mapIds.length > 0) {
|
||||
// Initialize dialog ...
|
||||
$("#delete-dialog-modal").dialogForm({
|
||||
type:'DELETE',
|
||||
postUpdate:function () {
|
||||
type: 'DELETE',
|
||||
postUpdate: function () {
|
||||
// Remove old entry ...
|
||||
tableUI.dataTableExt.removeSelectedRows();
|
||||
},
|
||||
url:"c/restful/maps/batch?ids=" + jQuery.makeArray(mapIds).join(',')
|
||||
url: "c/restful/maps/batch?ids=" + jQuery.makeArray(mapIds).join(',')
|
||||
});
|
||||
}
|
||||
});
|
||||
|
@@ -8,6 +8,7 @@
|
||||
<li><a href="#changePasswordPanel" data-toggle="pill"><spring:message code="SECURITY"/></a></li>
|
||||
</c:if>
|
||||
<li><a href="#languagePanel" data-toggle="pill"><spring:message code="LANGUAGE"/></a></li>
|
||||
<li><a href="#deleteAccountPanel" data-toggle="pill"><spring:message code="DELETE__ACCOUNT"/></a></li>
|
||||
</ul>
|
||||
|
||||
<div class="tab-content">
|
||||
@@ -88,6 +89,16 @@
|
||||
</fieldset>
|
||||
</form>
|
||||
</div>
|
||||
<div class="tab-pane fade" id="deleteAccountPanel">
|
||||
<div id="deleteAccountMsg" class="alert alert-error" style="display: block;"><spring:message code="WARNING_DELETE_USER"/></div>
|
||||
<form action="#" method="POST" id="deleteAccountForm">
|
||||
<fieldset>
|
||||
<input type="checkbox" name="confirmAccountDelete" id="accountMarkedForDelete" required="required"/>
|
||||
<input type="submit" id="deleteAccountBtn" class="btn btn-primary"
|
||||
value="<spring:message code="DELETE__ACCOUNT"/>"/>
|
||||
</fieldset>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -96,52 +107,115 @@
|
||||
$('#changeInfoMsg').hide();
|
||||
$('#languageMsg').hide();
|
||||
|
||||
function postChange(url, postBody, msgContainerId, successMsg) {
|
||||
function postChange(url, postBody, onSuccess, onError, type) {
|
||||
// Change success message ...
|
||||
jQuery.ajax(url, {
|
||||
async: false,
|
||||
dataType: 'json',
|
||||
data: postBody,
|
||||
type: 'PUT',
|
||||
type: type ? type : 'PUT',
|
||||
contentType: "text/plain; charset=utf-8",
|
||||
success: function (data, textStatus, jqXHR) {
|
||||
$('#' + msgContainerId).removeClass('alert-error').addClass('alert-info').show();
|
||||
$('#' + msgContainerId).text(successMsg);
|
||||
onSuccess()
|
||||
},
|
||||
error: function (jqXHR, textStatus, errorThrown) {
|
||||
$('#' + msgContainerId).removeClass('alert-info').addClass('alert-error').show();
|
||||
$('#' + msgContainerId).text(textStatus);
|
||||
onError(textStatus)
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
$('#changePasswordForm').submit(function (event) {
|
||||
|
||||
var inputVal = $('#changePasswordForm #password').val();
|
||||
var rinputVal = $('#changePasswordForm #repassword').val();
|
||||
var changePasswordMsg = $('#changePasswordMsg');
|
||||
if (inputVal != rinputVal) {
|
||||
// Password mismatch message ...
|
||||
$('#changePasswordMsg').removeClass('alert-info').addClass('alert-error').show();
|
||||
$('#changePasswordMsg').text('<spring:message code="PASSWORD_MISSMATCH"/>');
|
||||
changePasswordMsg.removeClass('alert-info').addClass('alert-error').show();
|
||||
changePasswordMsg.text('<spring:message code="PASSWORD_MISSMATCH"/>');
|
||||
} else {
|
||||
postChange("c/restful/account/password", inputVal, 'changePasswordMsg', "<spring:message code="CHANGE_PASSWORD_SUCCESS"/>");
|
||||
postChange(
|
||||
"c/restful/account/password",
|
||||
inputVal,
|
||||
function() {
|
||||
changePasswordMsg.removeClass('alert-error').addClass('alert-info').show();
|
||||
changePasswordMsg.text('<spring:message code="CHANGE_PASSWORD_SUCCESS"/>');
|
||||
},
|
||||
function(textStatus) {
|
||||
changePasswordMsg.removeClass('alert-info').addClass('alert-error').show();
|
||||
changePasswordMsg.text(textStatus);
|
||||
}
|
||||
);
|
||||
}
|
||||
event.preventDefault();
|
||||
});
|
||||
|
||||
$('#changeUserForm').submit(function (event) {
|
||||
|
||||
var fistname = $('#changeUserForm #firstname').val();
|
||||
var firstname = $('#changeUserForm #firstname').val();
|
||||
var lastname = $('#changeUserForm #lastname').val();
|
||||
postChange("c/restful/account/firstname", fistname, 'changeInfoMsg', "<spring:message code="INFO_UPDATE_SUCCESS"/>");
|
||||
postChange("c/restful/account/lastname", lastname, 'changeInfoMsg', "<spring:message code="INFO_UPDATE_SUCCESS"/>");
|
||||
var changeInfoMsg = $('#changeInfoMsg');
|
||||
postChange(
|
||||
"c/restful/account/firstname",
|
||||
firstname,
|
||||
function() {
|
||||
var changeInfoMsg = $('#changeInfoMsg');
|
||||
changeInfoMsg.removeClass('alert-error').addClass('alert-info').show();
|
||||
changeInfoMsg.text('<spring:message code="INFO_UPDATE_SUCCESS"/>');
|
||||
},
|
||||
function(textStatus) {
|
||||
changeInfoMsg.removeClass('alert-info').addClass('alert-error').show();
|
||||
changeInfoMsg.text(textStatus);
|
||||
}
|
||||
);
|
||||
postChange(
|
||||
"c/restful/account/lastname",
|
||||
lastname,
|
||||
function() {
|
||||
changeInfoMsg.removeClass('alert-error').addClass('alert-info').show();
|
||||
changeInfoMsg.text('<spring:message code="INFO_UPDATE_SUCCESS"/>');
|
||||
},
|
||||
function(textStatus) {
|
||||
changeInfoMsg.removeClass('alert-info').addClass('alert-error').show();
|
||||
changeInfoMsg.text(textStatus);
|
||||
}
|
||||
);
|
||||
event.preventDefault();
|
||||
});
|
||||
|
||||
$('#languageForm').submit(function (event) {
|
||||
|
||||
var locale = $('#languageForm option:selected').val();
|
||||
postChange("c/restful/account/locale", locale, 'languageMsg', "<spring:message code="INFO_UPDATE_SUCCESS"/>");
|
||||
var languageMsg = $('#languageMsg');
|
||||
postChange(
|
||||
"c/restful/account/locale",
|
||||
locale,
|
||||
function() {
|
||||
languageMsg.removeClass('alert-error').addClass('alert-info').show();
|
||||
languageMsg.text('<spring:message code="INFO_UPDATE_SUCCESS"/>');
|
||||
},
|
||||
function(textStatus) {
|
||||
languageMsg.removeClass('alert-info').addClass('alert-error').show();
|
||||
languageMsg.text(textStatus);
|
||||
}
|
||||
);
|
||||
event.preventDefault();
|
||||
});
|
||||
|
||||
$('#deleteAccountForm').submit(function (event) {
|
||||
var locale = $('#deleteAccountForm option:selected').val();
|
||||
postChange(
|
||||
"c/restful/account",
|
||||
locale,
|
||||
function() {
|
||||
window.location.href = "/c/logout"
|
||||
},
|
||||
function(textStatus) {
|
||||
var deleteAccountMsg = $('#deleteAccountMsg');
|
||||
deleteAccountMsg.removeClass('alert-info').addClass('alert-error').show();
|
||||
deleteAccountMsg.text(textStatus);
|
||||
},
|
||||
'DELETE'
|
||||
)
|
||||
event.preventDefault();
|
||||
});
|
||||
|
||||
</script>
|
||||
|
Reference in New Issue
Block a user