Changeset 76
- Timestamp:
- 06/30/07 10:48:47 (19 months ago)
- Location:
- unicoders/trunk/unicoders
- Files:
-
- 4 modified
-
adminedit/media/scripts/adminedit.js (modified) (6 diffs)
-
adminedit/templates/adminedit/field_edit.html (modified) (1 diff)
-
adminedit/views.py (modified) (1 diff)
-
media/scripts/adminedit.js (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
unicoders/trunk/unicoders/adminedit/media/scripts/adminedit.js
r75 r76 50 50 } 51 51 52 function setupForm(target, single) { 53 var form = $(target).find('input, textarea, select'); 54 if (form.length == 0) return; 55 56 // do not start the edit again if we click on a form element 57 form.click(function(event) { event.stopPropagation(); event.preventDefault(); }); 58 // on blur: save 59 form.blur(function() { saveField.call(this, single); }); 60 // on enter: save 61 form.keypress(function(event) { 62 if (event.keyCode == 13) saveField.call(this, single); 63 }); 64 65 66 function changeField() { 67 function innerChangeField() { 68 var cell = $(target); 69 if (target.tagName == 'A') cell = $(target).parent(); 70 getCellsInColumn(cell).each(function() { 71 if (isRowSelected(this)) { 72 var f = $(this).find('input, textarea, select')[0]; 73 if (f != form[0]) f.value = form[0].value; 74 } 75 }); 76 }; 77 setTimeout(innerChangeField, 10); 78 } 79 form.change(changeField); 80 form.keypress(changeField); 81 82 // focus on the new form widget 83 if (single) form[0].focus(); 84 } 52 85 53 86 function editSingleField(single) { 87 var target = this; 88 // keep the link if present 89 if ($(target).find('a').length > 0) { 90 target = $(this).find('a')[0]; 91 } 92 54 93 // throbber 55 $(t his).append('<img src="/media/images/throbber.gif"/>');94 $(target).append('<img src="/media/images/throbber.gif"/>'); 56 95 57 58 var target = this;59 96 // ajax request for the form widget 60 97 $.get(getUrl(this), function(data) { … … 62 99 $(target).html(data); 63 100 64 var form = $(target).find('input, textarea, select'); 65 // do not start the edit again if we click on a form element 66 form.click(function(event) { event.stopPropagation(); }); 67 // focus on the new form widget 68 if (single) form[0].focus(); 69 70 // on blur: save 71 form.blur(function() { saveField.call(this, single); }); 72 // on enter: save 73 form.keypress(function(event) { 74 if (event.keyCode == 13) saveField.call(this, single); 75 }); 76 77 78 function changeField() { 79 function innerChangeField() { 80 getCellsInColumn(form.parent()).each(function() { 81 if (isRowSelected(this)) { 82 var f = $(this).find('input, textarea, select')[0]; 83 if (f != form[0]) f.value = form[0].value; 84 } 85 }); 86 }; 87 setTimeout(innerChangeField, 10); 88 } 89 form.change(changeField); 90 form.keypress(changeField); 101 setupForm(target, single); 91 102 }); 92 103 } … … 94 105 function saveField(single) { 95 106 var cell = $(this).parent(); 107 // var target = cell; 108 // if (cell[0].tagName == 'SPAN') cell = cell.parent(); 96 109 97 110 if (!single) { … … 108 121 // just one argument to the post: the field we are editing with its new value 109 122 var args = {}; 110 args[$(this).attr('name')] = $(this).attr('value'); 123 if ($(this).attr('value')) { 124 args[$(this).attr('name')] = $(this).attr('value'); 125 } else { 126 args[$(this).attr('name')] = ''; 127 } 111 128 112 129 // ajax post to edit the object … … 114 131 // display the new value in the page 115 132 $(cell).html(data); 133 134 // in case of validation error 135 setupForm(cell, single); 116 136 }); 117 137 } … … 119 139 120 140 $(document).ready(function() { 121 $('#content h1').append('<h3>Click any field to edit it in place</h2>'); 141 if ($('body').attr('class') != 'change-list') return; 142 143 $('#content h1').append('<ul class="messagelist"><li>Click any field to edit it in place</li></ul>'); 122 144 123 145 // on click: edit 124 $('td').click(editField); 146 $('td, th').click(editField); 147 // when clicking on a link, do not edit 148 $('td a, th a').click(function(event) { event.stopPropagation(); }); 125 149 126 150 // add checkboxes to each row -
unicoders/trunk/unicoders/adminedit/templates/adminedit/field_edit.html
r75 r76 1 { { field }}1 {% if error %}{{ error.messages }}{% endif %}{{ field }} -
unicoders/trunk/unicoders/adminedit/views.py
r75 r76 18 18 o = c.objects.get(id=id) 19 19 try: 20 setattr(o, field, form[field].field.clean(request.POST [field]))20 setattr(o, field, form[field].field.clean(request.POST.get(field, None))) 21 21 o.save() 22 22 except forms.ValidationError, e: 23 print e23 return render_to_response("adminedit/field_edit.html", dict(field=form[field], error=e)) 24 24 25 25 return field_view(o, field) -
unicoders/trunk/unicoders/media/scripts/adminedit.js
r75 r76 50 50 } 51 51 52 function setupForm(target, single) { 53 var form = $(target).find('input, textarea, select'); 54 if (form.length == 0) return; 55 56 // do not start the edit again if we click on a form element 57 form.click(function(event) { event.stopPropagation(); event.preventDefault(); }); 58 // on blur: save 59 form.blur(function() { saveField.call(this, single); }); 60 // on enter: save 61 form.keypress(function(event) { 62 if (event.keyCode == 13) saveField.call(this, single); 63 }); 64 65 66 function changeField() { 67 function innerChangeField() { 68 var cell = $(target); 69 if (target.tagName == 'A') cell = $(target).parent(); 70 getCellsInColumn(cell).each(function() { 71 if (isRowSelected(this)) { 72 var f = $(this).find('input, textarea, select')[0]; 73 if (f != form[0]) f.value = form[0].value; 74 } 75 }); 76 }; 77 setTimeout(innerChangeField, 10); 78 } 79 form.change(changeField); 80 form.keypress(changeField); 81 82 // focus on the new form widget 83 if (single) form[0].focus(); 84 } 52 85 53 86 function editSingleField(single) { 87 var target = this; 88 // keep the link if present 89 if ($(target).find('a').length > 0) { 90 target = $(this).find('a')[0]; 91 } 92 54 93 // throbber 55 $(t his).append('<img src="/media/images/throbber.gif"/>');94 $(target).append('<img src="/media/images/throbber.gif"/>'); 56 95 57 58 var target = this;59 96 // ajax request for the form widget 60 97 $.get(getUrl(this), function(data) { … … 62 99 $(target).html(data); 63 100 64 var form = $(target).find('input, textarea, select'); 65 // do not start the edit again if we click on a form element 66 form.click(function(event) { event.stopPropagation(); }); 67 // focus on the new form widget 68 if (single) form[0].focus(); 69 70 // on blur: save 71 form.blur(function() { saveField.call(this, single); }); 72 // on enter: save 73 form.keypress(function(event) { 74 if (event.keyCode == 13) saveField.call(this, single); 75 }); 76 77 78 function changeField() { 79 function innerChangeField() { 80 getCellsInColumn(form.parent()).each(function() { 81 if (isRowSelected(this)) { 82 var f = $(this).find('input, textarea, select')[0]; 83 if (f != form[0]) f.value = form[0].value; 84 } 85 }); 86 }; 87 setTimeout(innerChangeField, 10); 88 } 89 form.change(changeField); 90 form.keypress(changeField); 101 setupForm(target, single); 91 102 }); 92 103 } … … 94 105 function saveField(single) { 95 106 var cell = $(this).parent(); 107 // var target = cell; 108 // if (cell[0].tagName == 'SPAN') cell = cell.parent(); 96 109 97 110 if (!single) { … … 108 121 // just one argument to the post: the field we are editing with its new value 109 122 var args = {}; 110 args[$(this).attr('name')] = $(this).attr('value'); 123 if ($(this).attr('value')) { 124 args[$(this).attr('name')] = $(this).attr('value'); 125 } else { 126 args[$(this).attr('name')] = ''; 127 } 111 128 112 129 // ajax post to edit the object … … 114 131 // display the new value in the page 115 132 $(cell).html(data); 133 134 // in case of validation error 135 setupForm(cell, single); 116 136 }); 117 137 } … … 119 139 120 140 $(document).ready(function() { 121 $('#content h1').append('<h3>Click any field to edit it in place</h2>'); 141 if ($('body').attr('class') != 'change-list') return; 142 143 $('#content h1').append('<ul class="messagelist"><li>Click any field to edit it in place</li></ul>'); 122 144 123 145 // on click: edit 124 $('td').click(editField); 146 $('td, th').click(editField); 147 // when clicking on a link, do not edit 148 $('td a, th a').click(function(event) { event.stopPropagation(); }); 125 149 126 150 // add checkboxes to each row