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