Index: branches/5.1.x/core/admin_templates/js/simple_grid.js =================================================================== diff -u -N -r12127 -r13878 --- branches/5.1.x/core/admin_templates/js/simple_grid.js (.../simple_grid.js) (revision 12127) +++ branches/5.1.x/core/admin_templates/js/simple_grid.js (.../simple_grid.js) (revision 13878) @@ -111,34 +111,73 @@ return $is_valid; } -SimpleGrid.prototype.addRecord = function () { +SimpleGrid.prototype.addRecord = function ($after_item_id) { var new_item_number = this.nextNumber(); var $item_mask = this.getControl('mask').value; var $result_html = $item_mask.replace(/#NUMBER#/g, new_item_number); var $div = document.createElement('DIV'); $div.id = this.IDPrefix + '_' + new_item_number; - this.getControl('container').appendChild($div); + + if ($after_item_id === undefined) { + this.getControl('container').appendChild($div); + } + else { + $('#' + jq(this.IDPrefix + '_' + $after_item_id)).after($div); + } + $div.innerHTML = $result_html; var $js_mask = this.getControl('js_mask').value; var result_js = $js_mask.replace(/#NUMBER#/g, new_item_number); eval(result_js); + this.updateTotals(); + + return new_item_number; } SimpleGrid.prototype.removeRecord = function ($number) { - this.getControl('container').removeChild( this.getControl($number) ); var $index = array_search($number, this.ItemIDs); + + if ($index == -1) { + // don't allow to delete missing rows + return false; + } + + this.getControl('container').removeChild( this.getControl($number) ); + this.ItemIDs.splice($index, 1); + this.renumberRecords(); this.updateTotals(); + + return true; } +SimpleGrid.prototype.removeRecords = function () { + while (this.ItemIDs.length > 0) { + var $item_id = this.ItemIDs[this.ItemIDs.length - 1]; + this.removeRecord($item_id); + } +} + SimpleGrid.prototype.updateTotals = function () { // prototype } SimpleGrid.prototype.processRecordDependancies = function ($id) { // prototype } + +SimpleGrid.prototype.each = function($callback) { + var $result = null; + + for (var $i = 0; $i < this.ItemIDs.length; $i++) { + $result = $callback.call(this, this.ItemIDs[$i]); + + if ($result === false) { + break; + } + } +}