]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/web/js/dojo/fieldmapper/hash.js
Initial vmsp tree editor
[working/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
23     if(!dojo._hasResource["fieldmapper.Fieldmapper"]) {
24
25         /* XXX Content loaded in Fieldmapper */
26         /* XXX deprecate this file **/
27
28         var i;
29         function _fromHash (_hash) {
30             for (i = 0; i < this._fields.length; i++) {
31                 if (_hash[this._fields[i]] !== null)
32                     this[this._fields[i]]( _hash[this._fields[i]] );
33             }
34             return this;
35         }
36
37         function _toHash (includeNulls, virtFields) {
38             var _hash = {};
39             for (i = 0; i < this._fields.length; i++) {
40                 if (includeNulls || this[this._fields[i]]() !== null) {
41                     if (this[this._fields[i]]() === null)
42                         _hash[this._fields[i]] = null;
43                     else
44                         _hash[this._fields[i]] = '' + this[this._fields[i]]();
45                 }
46             }
47
48             if (virtFields && virtFields.length > 0) {
49                 for (i = 0; i < virtFields.length; i++) {
50                     if (!_hash[virtFields[i]])
51                         _hash[virtFields[i]] = null;
52                 }
53             }
54
55             return _hash;
56         }
57
58         for (var i in fmclasses) {
59             window[i].prototype.fromHash = _fromHash;
60             window[i].prototype.toHash = _toHash;
61         }
62     }
63 }