Zope ZPT jQuery update and delete of table records

<table class="listing" tal:define="part_pricings python: context.sql_select_part_pricing(parts_id = user['parts_id'])">
<thead>
<tr>
	<th>Type</th>
	<th>Multiplier</th>
	<th> </th>
</tr>
</thead>	
<tbody>
<tal:loop repeat="part_pricing part_pricings">
<tr>
	<td><input type="text" class="vp_name" tal:attributes="value part_pricing/vp_name" readonly="true" style="border:0;" /></td>
	<td><input type="text" class="vp_pricing" tal:attributes="value python: '%.2f' % (part_pricing['vp_pricing'])" readonly="true" style="border:0;" /></td>
	<td>
		<a class="part-pricing-update action-update"><img src="/pencil_icon.gif" alt="edit" /></a>
		<a tal:attributes="href string:part_pricing_update?vp_id=${part_pricing/vp_id}" class="part-pricing-save action-save">
			<img src="/save_icon.gif" alt="save" />
		</a>
		<a style="display: none;" tal:attributes="href string:part_pricing_delete?vp_id=${part_pricing/vp_id}" class="part-pricing-delete">
			<img src="/img/ico/icon-delete-green.png" alt="delete" />
		</a>
	</td>
</tr>
</tal:loop>
</tbody>
</table>

<script type="text/javascript">
	jq('.action-update').click(function() { 
		jq(this).parent().parent().find('input').css('border', '1px solid #000').attr('readonly', false);
		jq(this).hide();
		jq(this).siblings('.action-save').show();		
	});
	jq('.action-save').click(function() { 
		jq(this).parent().parent().find('input').css('border', 'none').attr('readonly', true);
		jq(this).hide();		
		jq(this).siblings('.action-update').show();		
	});
	jq('.part-pricing-save').click(function() { 
		var name = jq(this).parent().parent().find('.vp_name').val();
		var pricing = jq(this).parent().parent().find('.vp_pricing').val();
		var url = jq(this).attr('href') + '&vp_name=' + name + '&vp_pricing=' + pricing;
		jq.ajax({
			url: url,
			failure: function() {
				// your failure alerts
			}
		})
		return false;		
	});
</script>
Posted by
Snippet Viewed 2461 times.

Share your Zope ZPT code snippets:

  • Get some recognition & a link back to your site.
  • Create your own code library.
  • Help your fellow developers, as they have helped you.

 

Submit | Browse

Most Recent zope zpt snippets

Most Viewed