[ Mini Kiebo ]
Server: Windows NT DESKTOP-5B8S0D4 6.2 build 9200 (Windows 8 Professional Edition) i586
Path:
D:
/
Backup
/
05122024
/
htdocs
/
simpeg
/
zapatec
/
zpgrid
/
zpgrid
/
jsdocs
/
[
Home
]
File: overview-summary-zpgrid-query.js.html
<!doctype html public "-//W3C//DTD HTML 4.0 Frameset//EN""http://www.w3.org/TR/REC-html40/frameset.dtd"> <html> <head> <title> Zapatec Grid Overview </title> <link rel ="stylesheet" type="text/css" href="stylesheet.css" title="Style"> <script> function asd() { parent.document.title="zpgrid-query.js Overview"; } </script> </head> <body bgcolor="white" onload="asd();"> <!-- ========== START OF NAVBAR ========== --> <a name="navbar_top"><!-- --></a> <table border="0" width="100%" cellpadding="1" cellspacing="0"> <tr> <td colspan=2 bgcolor="#EEEEFF" class="NavBarCell1"> <a name="navbar_top_firstrow"><!-- --></a> <table border="0" cellpadding="0" cellspacing="3"> <tr align="center" valign="top"> <td bgcolor="#EEEEFF" class="NavBarCell1"> <a href="overview-summary.html"><font class="NavBarFont1"><b>Overview</b></font></a> </td> <td bgcolor="#FFFFFF" class="NavBarCell1Rev"> <font class="NavBarFont1Rev"><b>File</b></font> </td> <td bgcolor="#FFFFFF" class="NavBarCell1"> <font class="NavBarFont1">Class</font> </td> <td bgcolor="#EEEEFF" class="NavBarCell1"> <a href="overview-tree.html"><font class="NavBarFont1"><b>Tree</b></font></a> </td> <td bgcolor="#EEEEFF" class="NavBarCell1"> <a href="index-all.html"--><font class="NavBarFont1"><b>Index</b></font></a> </td> <td bgcolor="#EEEEFF" class="NavBarCell1"> <a href="help-doc.html"><font class="NavBarFont1"><b>Help</b></font></a> </td> </tr> </table> </td> <td bgcolor="#EEEEFF" align="right" valign="top"> <em> <b>Zapatec Grid</b></em> </td> </tr> <tr> <td bgcolor="white" class="NavBarCell2"><font size="-2"> PREV NEXT</font></td> <td bgcolor="white" class="NavBarCell2"><font size="-2"> <a href="index.html" target="_top"><b>FRAMES</b></a> <a href="overview-summary.html" target="_top"><b>NO FRAMES</b></a> <script> <!-- if(window==top) { document.writeln('<A HREF="allclasses-noframe.html" TARGET=""><B>All Classes</B></A>'); } //--> </script> <noscript> <a href="allclasses-noframe.html" target=""><b>All Classes</b></a> </noscript> </font></td> </tr> </table> <!-- =========== END OF NAVBAR =========== --> <hr> <center> <h2>zpgrid-query.js</h2> </center> <h4>Summary</h4> <p> Plugin for Zapatec Grid to make queries to the grid. <pre> Copyright (c) 2004-2006 by Zapatec, Inc. http://www.zapatec.com 1700 MLK Way, Berkeley, California, 94709, U.S.A. All rights reserved. </pre><BR/><BR/> </p> <hr> <table border="1" cellpadding="3" cellspacing="0" width="100%"> <tr bgcolor="#CCCCFF" class="TableHeadingColor"> <td colspan=2><font size="+2"> <b>Class Summary</b> </font></td> </tr> <tr bgcolor="white" class="TableRowColor"> <td width="15%"><b><a href="Zapatec/GridQuery.html">Zapatec.GridQuery</a></b></td> <td> </td> </tr> <tr bgcolor="white" class="TableRowColor"> <td width="15%"><b><a href="Zapatec/GridQueryDelete.html">Zapatec.GridQueryDelete</a></b></td> <td> </td> </tr> <tr bgcolor="white" class="TableRowColor"> <td width="15%"><b><a href="Zapatec/GridQueryInsert.html">Zapatec.GridQueryInsert</a></b></td> <td> </td> </tr> <tr bgcolor="white" class="TableRowColor"> <td width="15%"><b><a href="Zapatec/GridQueryUpdate.html">Zapatec.GridQueryUpdate</a></b></td> <td> </td> </tr> </table> <hr/> <!-- ========== METHOD SUMMARY =========== --> <!-- ========== END METHOD SUMMARY =========== --> <pre class="sourceview"><span class="comment">/** * <span class="attrib">@fileoverview</span> Plugin for Zapatec Grid to make queries to the grid. * * <pre> * Copyright (c) 2004-2006 by Zapatec, Inc. * http://www.zapatec.com * 1700 MLK Way, Berkeley, California, * 94709, U.S.A. * All rights reserved. * </pre> */</span> <span class="comment">/* $Id: zpgrid-query.js 7323 2007-06-01 21:05:51Z alex $ */</span> <span class="comment">/** * Executes query on the grid. * * <pre> * Query object format: * * { * type: [string] query type ('insert', 'update' or 'delete'), * rows: [object, optional] array of rows to add (see * Zapatec.Grid.prototype.splice for details), * values: [object, optional] object with new values of row (see * Zapatec.GridQueryUpdate.prototype.execute for details), * where: [object, optional] condition statement object (see * Zapatec.GridQuery.prototype.compileStatement for details), * noRefresh: [boolean, optional] indicates that grid should not be refreshed * after changing (default: false) (useful when several changes go one by * one), * debug: [boolean, optional] if true, actual change to the grid will not be * performed * } * </pre> * * <span class="attrib">@param</span> {object} oArgs Query object. * <span class="attrib">@return</span> Array of affected rows during query. Number of affected rows can be * accessed through the length property of this array. If error occured during * query, returns undefined. See {<span class="attrib">@link</span> Zapatec.GridQueryInsert#execute}, * {<span class="attrib">@link</span> Zapatec.GridQueryUpdate#execute}, * {<span class="attrib">@link</span> Zapatec.GridQueryDelete#execute} for details * <span class="attrib">@type</span> object */</span> Zapatec.Grid.<span class="reserved">prototype</span>.query = <span class="reserved">function</span>(oArgs) { <span class="comment">// Check arguments</span> <span class="reserved">if</span> (!oArgs || !oArgs.type) { <span class="reserved">return</span>; } <span class="reserved">if</span> (!oArgs.where) { oArgs.where = null; } <span class="reserved">if</span> (!oArgs.noRefresh) { oArgs.noRefresh = null; } <span class="comment">// Execute query</span> <span class="reserved">if</span> (oArgs.type == <span class="literal">'insert'</span>) { <span class="reserved">if</span> (oArgs.rows instanceof Array) { var oQuery = new Zapatec.GridQueryInsert({ grid: <span class="reserved">this</span>, noRefresh: oArgs.noRefresh }); <span class="reserved">return</span> oQuery.execute({ rows: oArgs.rows, debug: oArgs.debug }); } } <span class="reserved">else</span> <span class="reserved">if</span> (oArgs.type == <span class="literal">'update'</span>) { <span class="reserved">if</span> (oArgs.values instanceof Object) { var oQuery = new Zapatec.GridQueryUpdate({ grid: <span class="reserved">this</span>, where: oArgs.where, noRefresh: oArgs.noRefresh }); <span class="reserved">return</span> oQuery.execute({ cells: oArgs.values.cells, style: oArgs.values.style, debug: oArgs.debug }); } } <span class="reserved">else</span> <span class="reserved">if</span> (oArgs.type == <span class="literal">'delete'</span>) { var oQuery = new Zapatec.GridQueryDelete({ grid: <span class="reserved">this</span>, where: oArgs.where, noRefresh: oArgs.noRefresh }); <span class="reserved">return</span> oQuery.execute({ debug: oArgs.debug }); } }; <span class="comment">/** * Base query. * * <pre> * <strong>Query initialization object format:</strong> * * { * grid: [object] Grid object to query, * where: [object, optional] statement object that describes query condition * (if not defined, all rows will be affected), * noRefresh: [boolean, optional] indicates that grid should not be refreshed * after changing (default: false) * } * * <strong>Statement object format:</strong> * * { * leftValue: [object, optional] statement value object, * rightValue: [object, optional] statement value object, * operator: [string, optional] any javascript binary or unary operator * } * * If operator is binary (e.g. '==' or '&&'), both leftValue and rightValue are * required. * * Operator can be left or right unary. In this case only one of leftValue or * rightValue should be defined. * * Examples: * * Statement "!value" can be described with following object: * * { * rightValue: {value: value}, * operator: '!' * } * * Statement "value++" can be described with following object: * * { * leftValue: {value: value}, * operator: '++' * } * * Statement "value1 == value2" can be described with following object: * * { * leftValue: {value: value1}, * rightValue: {value: value2}, * operator: '==' * } * * Statement "value != value1 && value != -value2" can be described with * following object: * * { * leftValue: { * statement: { * leftValue: {value: value}, * rightValue: {value: value1}, * operator: '!=' * } * }, * rightValue: { * statement: { * leftValue: {value: value}, * rightValue: { * statement: { * rightValue: {value: value2}, * operator: '-' * } * }, * operator: '!=' * } * }, * operator: '&&' * } * * <strong>Statement value object can be one of the following objects:</strong> * * { * column: [number] column number to use value of * } * * or * * { * value: [any] any value, * type: [string, optional] specifies field type to use comparison rules of * } * * or * * { * statement: [object] statement object (see above) * } * </pre> * * <span class="attrib">@constructor</span> * <span class="attrib">@param</span> {object} oArgs Query initialization object */</span> Zapatec.GridQuery = <span class="reserved">function</span>(oArgs) { <span class="reserved">this</span>.init(oArgs); }; <span class="comment">/** * Initializes object. * * <span class="attrib">@private</span> * <span class="attrib">@param</span> {object} oArgs Query initialization object * <span class="attrib">@return</span> Success * <span class="attrib">@type</span> boolean */</span> Zapatec.GridQuery.<span class="reserved">prototype</span>.init = <span class="reserved">function</span>(oArgs) { <span class="comment">// Grid to query [object]</span> <span class="reserved">this</span>.grid = null; <span class="comment">// Indicates that grid should not be refreshed after changing [boolean]</span> <span class="reserved">this</span>.noRefresh = false; <span class="comment">// Reference to query condition function [function]</span> <span class="reserved">this</span>.condition = null; <span class="comment">// Indicates that error occured during query initialization [boolean]</span> <span class="reserved">this</span>.error = null; <span class="comment">// Human readable error description [string]</span> <span class="reserved">this</span>.errorDescription = null; <span class="comment">// Get Grid object</span> <span class="reserved">if</span> (oArgs.grid && oArgs.grid.fields && oArgs.grid.rows) { <span class="reserved">this</span>.grid = oArgs.grid; } <span class="reserved">else</span> { <span class="comment">// Error</span> <span class="reserved">return</span> <span class="reserved">this</span>.setError(<span class="literal">'No grid'</span>); } <span class="comment">// Get query condition</span> <span class="reserved">if</span> (oArgs.where) { <span class="reserved">this</span>.condition = <span class="reserved">this</span>.compileStatement(oArgs.where); <span class="reserved">if</span> (!<span class="reserved">this</span>.condition) { <span class="comment">// True for all rows by default</span> <span class="reserved">this</span>.condition = <span class="reserved">function</span>(iRow) { <span class="reserved">return</span> true; } } } <span class="comment">// Initialized successfully</span> <span class="reserved">return</span> true; }; <span class="comment">/** * Compiles statement object. * * <span class="attrib">@private</span> * <span class="attrib">@param</span> {object} oStatement Statement object * <span class="attrib">@return</span> Reference to a function that accepts row number and returns result of * evaluation of statement on that row * <span class="attrib">@type</span> function or null */</span> Zapatec.GridQuery.<span class="reserved">prototype</span>.compileStatement = <span class="reserved">function</span>(oStatement) { <span class="comment">// Check arguments</span> <span class="reserved">if</span> (!oStatement) { <span class="reserved">return</span> null; } <span class="comment">// Get left value</span> var fLeftValue = null; <span class="reserved">if</span> (typeof oStatement.leftValue != <span class="literal">'undefined'</span>) { fLeftValue = <span class="reserved">this</span>.compileStatementValue(oStatement.leftValue); } <span class="comment">// Get right value</span> var fRightValue = null; <span class="reserved">if</span> (typeof oStatement.rightValue != <span class="literal">'undefined'</span>) { fRightValue = <span class="reserved">this</span>.compileStatementValue(oStatement.rightValue); } <span class="comment">// Get operator</span> var fOperator = null; <span class="reserved">if</span> (typeof oStatement.operator == <span class="literal">'string'</span>) { fOperator = <span class="reserved">this</span>.compileOperator(fLeftValue, fRightValue, oStatement.operator); } <span class="comment">// Compile statement</span> <span class="reserved">if</span> (fOperator) { <span class="reserved">if</span> (fLeftValue && fRightValue) { <span class="comment">// Binary operator</span> <span class="reserved">return</span> <span class="reserved">function</span>(iRow) { <span class="reserved">return</span> fOperator(fLeftValue(iRow), fRightValue(iRow)); } } <span class="reserved">if</span> (fRightValue) { <span class="comment">// Left unary operator</span> <span class="reserved">return</span> <span class="reserved">function</span>(iRow) { <span class="reserved">return</span> fOperator(fRightValue(iRow)); } } <span class="reserved">if</span> (fLeftValue) { <span class="comment">// Right unary operator</span> <span class="reserved">return</span> <span class="reserved">function</span>(iRow) { <span class="reserved">return</span> fOperator(fLeftValue(iRow)); } } } <span class="reserved">if</span> (fLeftValue) { <span class="reserved">return</span> fLeftValue; } <span class="reserved">return</span> fRightValue; }; <span class="comment">/** * Compiles statement value object. * * <span class="attrib">@private</span> * <span class="attrib">@param</span> {object} oValue Statement value object * <span class="attrib">@return</span> Reference to a function that accepts row number and returns result of * evaluation of statement value on that row * <span class="attrib">@type</span> function or null */</span> Zapatec.GridQuery.<span class="reserved">prototype</span>.compileStatementValue = <span class="reserved">function</span>(oValue) { <span class="comment">// Check arguments</span> <span class="reserved">if</span> (!oValue) { <span class="reserved">return</span> null; } <span class="comment">// Try to get column number</span> <span class="reserved">if</span> (typeof oValue.column != <span class="literal">'undefined'</span>) { var iColumn = oValue.column * 1; <span class="reserved">if</span> (!<span class="reserved">this</span>.grid.fields[iColumn]) { <span class="comment">// Error</span> <span class="reserved">this</span>.setError(<span class="literal">'Invalid column number: '</span> + oValue.column); <span class="reserved">return</span> null; } <span class="comment">// Return column value</span> var oGrid = <span class="reserved">this</span>.grid; <span class="reserved">return</span> <span class="reserved">function</span>(iRow) { var oRow = oGrid.rows[iRow]; <span class="reserved">if</span> (!oRow || !oRow.cells) { <span class="reserved">return</span>; } var oCell = oRow.cells[iColumn]; <span class="reserved">if</span> (!oCell) { <span class="reserved">return</span>; } <span class="reserved">return</span> oGrid.getCellValueCompare(oCell); }; } <span class="comment">// Try to get value</span> <span class="reserved">if</span> (typeof oValue.value != <span class="literal">'undefined'</span>) { var value = oValue.value; <span class="comment">// Get type</span> <span class="reserved">if</span> (typeof oValue.type != <span class="literal">'undefined'</span> && Zapatec.Grid.convertByType) { <span class="comment">// Get method</span> var strMethod = Zapatec.Grid.convertByType[oValue.type]; <span class="reserved">if</span> (!strMethod) { <span class="comment">// Error</span> <span class="reserved">this</span>.setError(<span class="literal">'Invalid field type: '</span> + oValue.type); <span class="reserved">return</span> null; } <span class="comment">// Convert to compare value according to the type rules</span> var oCell = { v: value }; oCell = <span class="reserved">this</span>.grid[strMethod](oCell); value = <span class="reserved">this</span>.grid.getCellValueCompare(oCell); } <span class="comment">// Return value</span> <span class="reserved">return</span> <span class="reserved">function</span>(iRow) { <span class="reserved">return</span> value; }; } <span class="comment">// Try to get statement</span> <span class="reserved">if</span> (typeof oValue.statement != <span class="literal">'undefined'</span>) { <span class="comment">// Return compiled statement</span> <span class="reserved">return</span> <span class="reserved">this</span>.compileStatement(oValue.statement); } <span class="comment">// Nothing applicable</span> <span class="reserved">this</span>.setError(<span class="literal">'Invalid statement value'</span>); <span class="reserved">return</span> null; }; <span class="comment">/** * Compiles operator. * * <span class="attrib">@private</span> * <span class="attrib">@param</span> {function or null} fLeftValue Left value * <span class="attrib">@param</span> {function or null} fRightValue Right value * <span class="attrib">@param</span> {string} strOperator Any javascript binary or unary operator * <span class="attrib">@return</span> Rreference to a function that accepts 1 or 2 values and returns * result of operator evaluation on those values * <span class="attrib">@type</span> function or null */</span> Zapatec.GridQuery.<span class="reserved">prototype</span>.compileOperator = <span class="reserved">function</span>(fLeftValue, fRightValue, strOperator) { <span class="comment">// Compile operator</span> try { <span class="reserved">if</span> (fLeftValue && fRightValue) { <span class="comment">// Binary operator</span> <span class="reserved">return</span> new Function(<span class="literal">'l'</span>, <span class="literal">'r'</span>, <span class="literal">'return l '</span> + strOperator + <span class="literal">' r'</span>); } <span class="reserved">if</span> (fRightValue) { <span class="comment">// Left unary operator</span> <span class="reserved">return</span> new Function(<span class="literal">'v'</span>, <span class="literal">'return '</span> + strOperator + <span class="literal">' v'</span>); } <span class="reserved">if</span> (fLeftValue) { <span class="comment">// Right unary operator</span> <span class="reserved">return</span> new Function(<span class="literal">'v'</span>, <span class="literal">'return v '</span> + strOperator); } } catch(oException) { <span class="reserved">this</span>.setError(<span class="literal">'Invalid operator: '</span> + strOperator); }; <span class="reserved">return</span> null; }; <span class="comment">/** * Sets error. * * <span class="attrib">@private</span> * <span class="attrib">@param</span> {string} strError Human readable error description * <span class="attrib">@return</span> Always false * <span class="attrib">@type</span> boolean */</span> Zapatec.GridQuery.<span class="reserved">prototype</span>.setError = <span class="reserved">function</span>(strError) { <span class="reserved">this</span>.error = true; <span class="reserved">this</span>.errorDescription = strError; <span class="reserved">return</span> false; }; <span class="comment">/** * Refreshes grid after change. * <span class="attrib">@private</span> */</span> Zapatec.GridQuery.<span class="reserved">prototype</span>.refreshGrid = <span class="reserved">function</span>() { <span class="reserved">if</span> (!<span class="reserved">this</span>.noRefresh && <span class="reserved">this</span>.grid && <span class="reserved">this</span>.grid.show) { <span class="reserved">this</span>.grid.modify(); } }; <span class="comment">/** * Insert query. * * <span class="attrib">@constructor</span> * <span class="attrib">@extends</span> Zapatec.GridQuery * <span class="attrib">@param</span> {object} oArgs Query initialization object (see * {<span class="attrib">@link</span> Zapatec.GridQuery} for details) */</span> Zapatec.GridQueryInsert = <span class="reserved">function</span>(oArgs) { <span class="comment">// Call constructor of superclass</span> Zapatec.GridQueryInsert.SUPERconstructor.call(<span class="reserved">this</span>, oArgs); }; <span class="comment">// Inherit GridQuery</span> Zapatec.inherit(Zapatec.GridQueryInsert, Zapatec.GridQuery); <span class="comment">/** * Initializes object. * * <span class="attrib">@private</span> * <span class="attrib">@param</span> {object} oArgs Query initialization object (see * {<span class="attrib">@link</span> Zapatec.GridQuery} for details) * <span class="attrib">@return</span> Success * <span class="attrib">@type</span> boolean */</span> Zapatec.GridQueryInsert.<span class="reserved">prototype</span>.init = <span class="reserved">function</span>(oArgs) { <span class="comment">// Call parent</span> <span class="reserved">return</span> Zapatec.GridQueryInsert.SUPERclass.init.call(<span class="reserved">this</span>, oArgs); }; <span class="comment">/** * Executes query. * * <pre> * Query data object format: * * { * rows: [object] array of rows to add (see {<span class="attrib">@link</span> Zapatec.Grid#splice} for * details), * debug: [boolean, optional] if true, actual change to the grid will not be * performed * } * </pre> * * <span class="attrib">@param</span> {object} oArgs Query data object * <span class="attrib">@return</span> Array of added rows. Number of added rows can be accessed through the * length property of this array. If error occured during query, returns * undefined * <span class="attrib">@type</span> object */</span> Zapatec.GridQueryInsert.<span class="reserved">prototype</span>.execute = <span class="reserved">function</span>(oArgs) { <span class="reserved">if</span> (!<span class="reserved">this</span>.grid || <span class="reserved">this</span>.error) { <span class="comment">// Error</span> <span class="reserved">return</span>; } <span class="comment">// Check arguments</span> <span class="reserved">if</span> (!oArgs || !oArgs.rows) { <span class="reserved">return</span>; } <span class="comment">// Insert rows</span> <span class="reserved">if</span> (!oArgs.debug) { <span class="reserved">this</span>.grid.splice({ rows: oArgs.rows, noRefresh: <span class="reserved">this</span>.noRefresh }); } <span class="comment">// Success</span> <span class="reserved">return</span> oArgs.rows; }; <span class="comment">/** * Update query. * * <span class="attrib">@constructor</span> * <span class="attrib">@extends</span> Zapatec.GridQuery * <span class="attrib">@param</span> {object} oArgs Query initialization object (see * {<span class="attrib">@link</span> Zapatec.GridQuery} for details) */</span> Zapatec.GridQueryUpdate = <span class="reserved">function</span>(oArgs) { <span class="comment">// Call constructor of superclass</span> Zapatec.GridQueryUpdate.SUPERconstructor.call(<span class="reserved">this</span>, oArgs); }; <span class="comment">// Inherit GridQuery</span> Zapatec.inherit(Zapatec.GridQueryUpdate, Zapatec.GridQuery); <span class="comment">/** * Initializes object. * * <span class="attrib">@private</span> * <span class="attrib">@param</span> {object} oArgs Query initialization object (see * {<span class="attrib">@link</span> Zapatec.GridQuery} for details) * <span class="attrib">@return</span> Success * <span class="attrib">@type</span> boolean */</span> Zapatec.GridQueryUpdate.<span class="reserved">prototype</span>.init = <span class="reserved">function</span>(oArgs) { <span class="comment">// Call parent</span> <span class="reserved">return</span> Zapatec.GridQueryUpdate.SUPERclass.init.call(<span class="reserved">this</span>, oArgs); }; <span class="comment">/** * Executes query. * * <pre> * Query data object format: * * { * cells: [ * { * v: [any] cell value, * style: [string, optional] table cell style attribute * }, * ... * ], * style: [string, optional] table row style attribute, * debug: [boolean, optional] if true, actual change to the grid will not be * performed * } * * If only some of cells should be changed, specify only those cells. E.g. * * { * cells: [ * null, * null, * { v: value1 }, * null, * { v: value2 } * ] * } * * will change only values in 3-rd and 5-th columns. * </pre> * * <span class="attrib">@param</span> {object} oArgs Query data object * <span class="attrib">@return</span> Array of modified rows. Number of modified rows can be accessed * through the length property of this array. Each element of this array * contains array with copy of original row object and reference to modified * row object: [oOriginalRow, oModifiedRow]. If error occured during query, * returns undefined * <span class="attrib">@type</span> object */</span> Zapatec.GridQueryUpdate.<span class="reserved">prototype</span>.execute = <span class="reserved">function</span>(oArgs) { <span class="reserved">if</span> (!<span class="reserved">this</span>.grid || <span class="reserved">this</span>.error) { <span class="comment">// Error</span> <span class="reserved">return</span>; } <span class="comment">// Check arguments</span> <span class="reserved">if</span> (!oArgs || !oArgs.cells) { <span class="reserved">return</span>; } <span class="comment">// Fire event</span> <span class="reserved">this</span>.grid.fireEvent(<span class="literal">'gridPrepareModify'</span>); <span class="comment">// Will contain modified rows</span> var aModified = []; <span class="comment">// Iterate over rows</span> <span class="reserved">for</span> (var iRow = 0; iRow < <span class="reserved">this</span>.grid.rows.length; iRow++) { <span class="comment">// Get row</span> <span class="reserved">if</span> (!(<span class="reserved">this</span>.grid.rows[iRow] instanceof Object)) { <span class="reserved">this</span>.grid.rows[iRow] = {}; } var oRow = <span class="reserved">this</span>.grid.rows[iRow]; <span class="reserved">if</span> (!(oRow.cells instanceof Array)) { oRow.cells = []; } <span class="comment">// Update row</span> <span class="reserved">if</span> (<span class="reserved">this</span>.condition(iRow)) { <span class="comment">// Save a copy of original row and a reference to modified row</span> aModified.push([Zapatec.Utils.clone(oRow), oRow]); <span class="comment">// Update row</span> <span class="reserved">if</span> (!oArgs.debug) { <span class="reserved">for</span> (var iCol = 0; iCol < <span class="reserved">this</span>.grid.fields.length; iCol++) { <span class="comment">// Get new value</span> var oArgsCell = oArgs.cells[iCol]; <span class="reserved">if</span> (!oArgsCell) { continue; } <span class="comment">// Get cell</span> <span class="reserved">if</span> (!(oRow.cells[iCol] instanceof Object)) { oRow.cells[iCol] = {}; } var oCell = oRow.cells[iCol]; <span class="comment">// Set new cell value</span> oCell = <span class="reserved">this</span>.grid.setCellValue(oCell, <span class="reserved">this</span>.grid.getCellValue(oArgsCell)); <span class="comment">// Set cell style</span> oCell = <span class="reserved">this</span>.grid.setCellStyle(oCell, oArgsCell.style); <span class="comment">// Update cell</span> oRow.cells[iCol] = oCell; } <span class="comment">// Set row style</span> oRow = <span class="reserved">this</span>.grid.setRowStyle(oRow, oArgs.style); } } } <span class="comment">// Rebuild primary key</span> <span class="reserved">if</span> (!oArgs.debug && aModified.length) { <span class="reserved">this</span>.grid.rebuildPrimaryKey(); } <span class="comment">// Refresh grid</span> <span class="reserved">this</span>.refreshGrid(); <span class="comment">// Success</span> <span class="reserved">return</span> aModified; }; <span class="comment">/** * Delete query. * * <span class="attrib">@constructor</span> * <span class="attrib">@extends</span> Zapatec.GridQuery * <span class="attrib">@param</span> {object} oArgs Query initialization object (see * {<span class="attrib">@link</span> Zapatec.GridQuery} for details) */</span> Zapatec.GridQueryDelete = <span class="reserved">function</span>(oArgs) { <span class="comment">// Call constructor of superclass</span> Zapatec.GridQueryDelete.SUPERconstructor.call(<span class="reserved">this</span>, oArgs); }; <span class="comment">// Inherit GridQuery</span> Zapatec.inherit(Zapatec.GridQueryDelete, Zapatec.GridQuery); <span class="comment">/** * Initializes object. * * <span class="attrib">@private</span> * <span class="attrib">@param</span> {object} oArgs Query initialization object (see * {<span class="attrib">@link</span> Zapatec.GridQuery} for details) * <span class="attrib">@return</span> Success * <span class="attrib">@type</span> boolean */</span> Zapatec.GridQueryDelete.<span class="reserved">prototype</span>.init = <span class="reserved">function</span>(oArgs) { <span class="comment">// Call parent</span> <span class="reserved">return</span> Zapatec.GridQueryDelete.SUPERclass.init.call(<span class="reserved">this</span>, oArgs); }; <span class="comment">/** * Executes query. * * <pre> * Query data object format: * * { * debug: [boolean, optional] if true, actual change to the grid will not be * performed * } * </pre> * * <span class="attrib">@param</span> {object} oArgs Query data object * <span class="attrib">@return</span> Array of removed rows. Number of removed rows can be accessed through * the length property of this array. If error occured during query, returns * undefined * <span class="attrib">@type</span> object */</span> Zapatec.GridQueryDelete.<span class="reserved">prototype</span>.execute = <span class="reserved">function</span>(oArgs) { <span class="reserved">if</span> (!<span class="reserved">this</span>.grid || <span class="reserved">this</span>.error) { <span class="comment">// Error</span> <span class="reserved">return</span>; } <span class="comment">// Fire event</span> <span class="reserved">this</span>.grid.fireEvent(<span class="literal">'gridPrepareModify'</span>); <span class="comment">// Will contain removed rows</span> var aRemoved = []; <span class="comment">// Iterate over rows</span> <span class="reserved">for</span> (var iRow = <span class="reserved">this</span>.grid.rows.length - 1; iRow >= 0; iRow--) { <span class="comment">// Get row</span> var oRow = <span class="reserved">this</span>.grid.rows[iRow]; <span class="reserved">if</span> (!(oRow instanceof Object) || !(oRow.cells instanceof Array)) { continue; } <span class="comment">// Remove row</span> <span class="reserved">if</span> (<span class="reserved">this</span>.condition(iRow)) { <span class="reserved">if</span> (oArgs && oArgs.debug) { <span class="comment">// Only get copy of row without removing</span> aRemoved.push(oRow); } <span class="reserved">else</span> { <span class="comment">// Remove row</span> aRemoved.push(<span class="reserved">this</span>.grid.removeRow(iRow)); } } } <span class="comment">// Rows were removed in reverse order</span> aRemoved.reverse(); <span class="comment">// Rebuild primary key</span> <span class="reserved">if</span> (!(oArgs && oArgs.debug) && aRemoved.length) { <span class="reserved">this</span>.grid.rebuildPrimaryKey(); } <span class="comment">// Refresh grid</span> <span class="reserved">this</span>.refreshGrid(); <span class="comment">// Success</span> <span class="reserved">return</span> aRemoved; }; </pre> <hr> <!-- ========== START OF NAVBAR ========== --> <a name="navbar_top"><!-- --></a> <table border="0" width="100%" cellpadding="1" cellspacing="0"> <tr> <td colspan=2 bgcolor="#EEEEFF" class="NavBarCell1"> <a name="navbar_top_firstrow"><!-- --></a> <table border="0" cellpadding="0" cellspacing="3"> <tr align="center" valign="top"> <td bgcolor="#EEEEFF" class="NavBarCell1"> <a href="overview-summary.html"><font class="NavBarFont1"><b>Overview</b></font></a> </td> <td bgcolor="#FFFFFF" class="NavBarCell1Rev"> <font class="NavBarFont1Rev"><b>File</b></font> </td> <td bgcolor="#FFFFFF" class="NavBarCell1"> <font class="NavBarFont1">Class</font> </td> <td bgcolor="#EEEEFF" class="NavBarCell1"> <a href="overview-tree.html"><font class="NavBarFont1"><b>Tree</b></font></a> </td> <td bgcolor="#EEEEFF" class="NavBarCell1"> <a href="index-all.html"--><font class="NavBarFont1"><b>Index</b></font></a> </td> <td bgcolor="#EEEEFF" class="NavBarCell1"> <a href="help-doc.html"><font class="NavBarFont1"><b>Help</b></font></a> </td> </tr> </table> </td> <td bgcolor="#EEEEFF" align="right" valign="top"><em> <b>Zapatec Grid</b></em> </td> </tr> <tr> <td bgcolor="white" class="NavBarCell2"><font size="-2"> PREV NEXT</font></td> <td bgcolor="white" class="NavBarCell2"><font size="-2"> <a href="index.html" target="_top"><b>FRAMES</b></a> <a href="overview-summary.html" target="_top"><b>NO FRAMES</b></a> <script> <!-- if(window==top) { document.writeln('<A HREF="allclasses-noframe.html" TARGET=""><B>All Classes</B></A>'); } //--> </script> <noscript> <a href="allclasses-noframe.html" target=""><b>All Classes</b></a> </noscript> </font></td> </tr> </table> <!-- =========== END OF NAVBAR =========== --> <hr> <font size="-1"> </font> <div class="jsdoc_ctime">Documentation generated by <a href="http://jsdoc.sourceforge.net/" target="_parent">JSDoc</a> on Thu Aug 16 12:18:56 2007</div> </body> </html>