MINOR Rewrote part of the javascript to use entwine instead of jquery.live

This commit is contained in:
Stig Lindqvist 2012-05-07 17:12:44 +12:00
parent 63469ced2f
commit 58799b9b1a

View File

@ -141,48 +141,43 @@
* area. the type information should all be on this object * area. the type information should all be on this object
*/ */
$("div.FieldEditor .MenuHolder .action").live('click',function() { $.entwine('udf', function($){
$('div.FieldEditor .MenuHolder .action').entwine({
// if this form is readonly... onclick: function(e) {
if($("#Fields").hasClass('readonly')) { if($("#Fields").hasClass('readonly')) {
return false; e.preventDefault();
return;
} }
// Give the user some feedback
statusMessage(userforms.message('ADDING_FIELD')); statusMessage(userforms.message('ADDING_FIELD'));
// variables // variables
var action = $("#Form_EditForm").attr("action") + '/field/Fields/addfield'; var $form = $("#Form_EditForm");
var length = $(".FieldInfo").length + 1; var length = $(".FieldInfo").length + 1;
var securityID = ($("#SecurityID").length > 0) ? '&SecurityID='+$("#SecurityID").attr("value") : ''; var securityID = ($("#SecurityID").length > 0) ? '&SecurityID='+$("#SecurityID").attr("value") : '';
var type = $(this).siblings("select").val(); var fieldType = $(this).siblings("select").val();
var formData = $form.serialize()+'NewID='+ length +"&Type="+ fieldType + securityID;
// send ajax request to the page var $fieldEditor = $(this.closest('.FieldEditor'));
// Due to some very weird behaviout of jquery.metadata, the url have to be double quoted
var addURL = $fieldEditor.attr('data-add-url').substr(1,$fieldEditor.attr('data-add-url').length-2);
$.ajax({ $.ajax({
type: "GET", headers: {"X-Pjax" : 'Partial'},
url: action, type: "POST",
data: 'NewID='+ length +"&Type="+ type + securityID, url: addURL,
data: formData,
// create a new field success: function(data) {
success: function(msg){ $('#Fields_fields').append(data);
$('#Fields_fields').append(msg);
statusMessage(userforms.message('ADDED_FIELD')); statusMessage(userforms.message('ADDED_FIELD'));
// update the internal lists
var name = $("#Fields_fields li.EditableFormField:last").attr("id").split(' '); var name = $("#Fields_fields li.EditableFormField:last").attr("id").split(' ');
$("#Fields_fields select.fieldOption").append("<option value='"+ name[2] +"'>New "+ name[2] + "</option>"); $("#Fields_fields select.fieldOption").append("<option value='"+ name[2] +"'>New "+ name[2] + "</option>");
}, },
error: function(e) {
// error creating new field alert(ss.i18n._t('GRIDFIELD.ERRORINTRANSACTION', 'An error occured while fetching data from the server\n Please try again later.'));
error: function(request, text, error) {
statusMessage(userforms.message('ERROR_CREATING_FIELD'));
} }
}); });
e.preventDefault();
$("#Fields_fields").sortable('refresh'); $("#Fields_fields").sortable('refresh');
}
return false; });
}); });
/** /**