Index: branches/5.2.x/core/admin_templates/js/simple_grid.js =================================================================== diff -u -N -r13840 -r14092 --- branches/5.2.x/core/admin_templates/js/simple_grid.js (.../simple_grid.js) (revision 13840) +++ branches/5.2.x/core/admin_templates/js/simple_grid.js (.../simple_grid.js) (revision 14092) @@ -67,30 +67,25 @@ return document.getElementById($prepend + this.FieldMask.replace('#FIELD#', $field_name).replace('#ID#', $id) + $append); } -SimpleGrid.prototype.markError = function ($item_id, $field_name, $error_found) { +SimpleGrid.prototype.markError = function ($item_id, $field_name, $error_found, $error_message) { if (!isset($error_found)) { $error_found = true; } - var $field = this.getField($item_id, $field_name); + var $field = $( this.getField($item_id, $field_name) ); + if ($error_found) { - $field.style.backgroundColor = '#EF2C2C'; + $field.css('background-color', '#EF2C2C').attr('title', $error_message === undefined ? '' : $error_message) // TODO: duplicate focus events possible on one element, fix this later - addEvent($field, 'focus', + .focus( function($e) { - if (!$e) { - $e = window.event; - } - - var $element = document.all ? $e.srcElement : $e.currentTarget; - $element.style.backgroundColor = ''; + $(this).css('background-color', '').attr('title', ''); } - ); } else { - $field.style.backgroundColor = ''; + $field.css('background-color', '').attr('title', ''); } } @@ -111,34 +106,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; + } + } +}