333a2d90b9d0c8d2c16e1c7961e26d141f8ba22b
[Evergreen.git] / Open-ILS / web / js / dojo / fieldmapper / hash.js
1 /*
2 # ---------------------------------------------------------------------------
3 # Copyright (C) 2008  Georgia Public Library Service / Equinox Software, Inc
4 # Mike Rylander <miker@esilibrary.com>
5
6 # This program is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU General Public License
8 # as published by the Free Software Foundation; either version 2
9 # of the License, or (at your option) any later version.
10
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 # GNU General Public License for more details.
15 # ---------------------------------------------------------------------------
16 */
17
18 if(!dojo._hasResource['fieldmapper.hash']){
19
20         dojo._hasResource['fieldmapper.hash'] = true;
21         dojo.provide('fieldmapper.hash');
22         dojo.require('fieldmapper.Fieldmapper');
23
24         function _fromHash (_hash) {
25                 for ( var i=0; i < this._fields.length; i++) {
26                         if (_hash[this._fields[i]] != null)
27                                 this[this._fields[i]]( _hash[this._fields[i]] );
28                 }
29                 return this;
30         }
31
32         function _toHash (includeNulls) {
33                 var _hash = {};
34                 for ( var i=0; i < this._fields.length; i++) {
35                         if (includeNulls || this[this._fields[i]]() != null) {
36                                 if (this[this._fields[i]]() == null)
37                     _hash[this._fields[i]] = null;
38                 else
39                                     _hash[this._fields[i]] = '' + this[this._fields[i]]();
40             }
41                 }
42                 return _hash;
43         }
44
45         for (var i in fmclasses) {
46                 window[i].prototype.fromHash = _fromHash;
47                 window[i].prototype.toHash = _toHash;
48         }
49
50 }