source: cats/ISOcat/trunk/mod-ISOcat-interface-gi/interface/JSXAPPS/ISOcat/js/org/isocat/gui/ProfileValueDomainEditor.js @ 2710

Last change on this file since 2710 was 2710, checked in by mwindhouwer, 11 years ago

M mod-ISOcat-interface-gi/interface/JSXAPPS/ISOcat/xml/dc.xml
M mod-ISOcat-interface-gi/interface/JSXAPPS/ISOcat/components/ProfileValueDomainEditor.xml
M mod-ISOcat-interface-gi/interface/JSXAPPS/ISOcat/xsl/Profiles2CDF.xsl
M mod-ISOcat-interface-gi/interface/JSXAPPS/ISOcat/xsl/DC2CDF.xsl
M mod-ISOcat-interface-gi/interface/JSXAPPS/ISOcat/js/org/isocat/gui/DCEditor.js
M mod-ISOcat-interface-gi/interface/JSXAPPS/ISOcat/js/org/isocat/gui/ProfileValueDomainEditor.js
M mod-ISOcat-access-data/access/dc_check.xsl
M mod-ISOcat-access-data/access/dc_sql.xsl
M mod-ISOcat-access-data/dbms/ISOcat-schema-init.sql

  • renamed Private profile to 'undecided'
  • added 'not available' profile

M mod-ISOcat-site/site/index_files/news.html
M mod-ISOcat-site/pub/isocat.pub

  • keep track of the revision info
File size: 11.9 KB
Line 
1jsx3.util.Logger.getLogger("org.isocat").info("Loading class[org.isocat.gui.ProfileValueDomainEditor]");
2
3/**
4 * The ProfileValueDomainEditor controller
5 * @author Menzo.Windhouwer@mpi.nl
6 */
7jsx3.lang.Class.defineClass("org.isocat.gui.ProfileValueDomainEditor", null, [], function(ProfileValueDomainEditor, ProfileValueDomainEditor_prototype) {
8       
9        /**
10         * The class logger
11         */
12        ProfileValueDomainEditor.log = jsx3.util.Logger.getLogger("org.isocat.gui.ProfileValueDomainEditor");
13       
14        /**
15         * The root block of the component
16         */
17        ProfileValueDomainEditor_prototype.view;
18       
19        /**
20         * The viewer
21         */
22        ProfileValueDomainEditor_prototype.viewer;
23       
24        /**
25         * The profile column template
26         */
27        ProfileValueDomainEditor_prototype.template;
28       
29        /**
30         * The profiles
31          */
32        ProfileValueDomainEditor_prototype.profiles;
33       
34        /**
35         * The addValue callback
36         */
37        this.addContext  = null;
38        this.addCallback = null;
39
40        /**
41         * The delValue callback
42         */
43        this.delContext  = null;
44        this.delCallback = null;
45       
46        /**
47         * The changed callback
48         */
49        this.changedContext  = null;
50        this.changedCallback = null;
51       
52        /**
53         * Constructor
54         */
55        ProfileValueDomainEditor_prototype.init = function(view) {
56                org.isocat.gui.ProfileValueDomainEditor.log.info("initialize ProfileValueDomainEditor input["+this+"]");
57
58                this.view = view;
59               
60                this.viewer = this.view.getDescendantOfName("ProfileValueDomains");
61                org.isocat.gui.ProfileValueDomainEditor.log.info("- profile value domains viewer["+this.viewer+"]");
62               
63                this.template = this.view.getDescendantOfName("templateColumn");
64                org.isocat.gui.ProfileValueDomainEditor.log.info("- profile column template["+this.template+"]");
65               
66                this.profiles = jsx3.xml.CDF.Document.newDocument();
67                this.profiles.insertRecord({jsxid:'profile-0',jsxtext:'undecided'});
68               
69                this.setProfiles(this.profiles);
70
71                this.addContext  = null;
72                this.addCallback = null;
73                this.delContext  = null;
74                this.delCallback = null;
75                this.changedContext  = null;
76                this.changedCallback = null;
77       
78                org.isocat.gui.ProfileValueDomainEditor.log.info("initialized ProfileValueDomainEditor input["+this+"]");
79               
80                this.view.controller = this;
81               
82                // create message
83                var message = {
84                        jss: "org.pagebus.msg.Message",
85                        jssv: "1.0.0",
86                        header: { },
87                        body: this
88                };
89               
90                // publish the message using PageBus
91                window.PageBus.publish("org.isocat.gui.ProfileValueDomainEditor.init", message);
92        };
93       
94        // disable the checkbox if the row doesn't have an attribute for this column, i.e., the value can't be part of the profile value domain
95        ProfileValueDomainEditor.formatCheckbox = function(objDiv, strCDFKey, objMatrix, objColumn, rowIndex, objServer) {
96                var rec = objMatrix.getRecordNode(strCDFKey);
97                var att = objColumn.getPath();
98                if ((rec.getAttribute(att) == null) && (att != 'profile--1') && (att != 'profile-0')) {
99                        var checkmask = objColumn.getChild(0); 
100                        checkmask.setEnabled(0);
101                        checkmask.setChecked(checkmask.UNCHECKED);
102                        var html = checkmask.paint();
103                        // override the cell's innerHTML with a disabled checkbox.
104                        objDiv.innerHTML = html;
105                        checkmask.setEnabled(1);
106                }
107        };
108
109        ProfileValueDomainEditor_prototype.setAddCallback = function(context,callback) {
110                this.addContext  = context;
111                this.addCallback = callback;
112        };
113       
114        ProfileValueDomainEditor_prototype.setDelCallback = function(context,callback) {
115                this.delContext  = context;
116                this.delCallback = callback;
117        };
118       
119        ProfileValueDomainEditor_prototype.setChangedCallback = function(context,callback) {
120                this.changedContext  = context;
121                this.changedCallback = callback;
122        };
123       
124        ProfileValueDomainEditor_prototype.getProfiles = function() {
125                return this.profiles;
126        };
127       
128        ProfileValueDomainEditor_prototype.setProfiles = function(newProfiles,show) {
129                if (typeof(show) == 'undefined')
130                        show = false;
131               
132                org.isocat.gui.ProfileValueDomainEditor.log.info("ProfileValueDomainEditor.setProfiles("+newProfiles+"):");
133                this.profiles = newProfiles;
134
135                org.isocat.gui.ProfileValueDomainEditor.log.info("ProfileValueDomainEditor.setProfiles(...):profiles["+this.profiles+"]");
136               
137                // remove all the existing profile columns
138                var cols = this.viewer.getChildren();
139                var del = new Array();
140                org.isocat.gui.ProfileValueDomainEditor.log.info("ProfileValueDomainEditor.setProfiles(...):columns["+cols.length+"]");
141                for (var i = 0;i<cols.length;i++) {
142                        var col = cols[i];
143                        if (col.getName() == "Profile") {
144                                del.push(col);
145                                org.isocat.gui.ProfileValueDomainEditor.log.info("ProfileValueDomainEditor.setProfiles(...):remove profile column["+col.getPath()+"]");
146                        } else
147                                org.isocat.gui.ProfileValueDomainEditor.log.info("ProfileValueDomainEditor.setProfiles(...):keep column["+col.getPath()+"]");
148                }
149                org.isocat.gui.ProfileValueDomainEditor.log.info("ProfileValueDomainEditor.setProfiles(...):remove profile columns["+del.length+"]");
150                this.viewer.removeChildren(del);
151                org.isocat.gui.ProfileValueDomainEditor.log.info("ProfileValueDomainEditor.setProfiles(...):removed profile columns");
152               
153                // add all the needed profile columns
154                var profs = this.profiles.getRecordIds();
155                for (var i = 0;i<profs.length;i++) {
156                        var prof = this.profiles.getRecord(profs[i]);
157                        var col = this.template.doClone();
158                        col.setName("Profile");
159                        col.setText(prof.jsxtext);
160                        col.setPath(prof.jsxid);
161                        if (show || (profs.length > 1)) // if there is only one profile column, we can keep it hidden
162                                col.setDisplay(jsx3.gui.Block.DISPLAYBLOCK,true);
163                        org.isocat.gui.ProfileValueDomainEditor.log.info("ProfileValueDomainEditor.setProfiles(...):added profile column["+col.getPath()+"]");
164                }
165               
166                this.viewer.repaint();
167                org.isocat.gui.ProfileValueDomainEditor.log.info("ProfileValueDomainEditor.setProfiles(...):repaint");
168        };
169       
170        ProfileValueDomainEditor_prototype.hasValues = function() {
171                return (this.viewer.getRecordIds().length > 0);
172        };
173       
174        ProfileValueDomainEditor_prototype.getValues = function() {
175                var doc = this.viewer.getXML();
176                if (doc instanceof jsx3.xml.CDF.Document)
177                        return doc;
178                else
179                        return jsx3.xml.CDF.Document.wrap(doc);
180        };
181       
182        ProfileValueDomainEditor_prototype.setValues = function(valuesCacheId) {
183                this.viewer.setXMLId(valuesCacheId);
184                this.viewer.repaintData();
185        };
186       
187        ProfileValueDomainEditor_prototype.addValue = function() {
188                var list = org.isocat.APP.getRootBlock().loadAndCache("components/DCList.xml",true).controller;
189                org.isocat.gui.ProfileValueDomainEditor.log.info("ProfileValueDomainEditor.addValue():loaded list component");
190               
191                list.callback(this,this.addValues);
192                org.isocat.gui.ProfileValueDomainEditor.log.info("ProfileValueDomainEditor.addValue():registered callback");
193               
194                // preselect the already selected values
195                org.isocat.gui.ProfileValueDomainEditor.log.info("ProfileValueDomainEditor.addValue():values["+this.getValues()+"]");
196                org.isocat.gui.ProfileValueDomainEditor.log.info("ProfileValueDomainEditor.addValue():records["+this.getValues().getRecordIds()+"]");
197                var vals = this.viewer.getRecordIds();
198                for (var i = 0;i<vals.length;i++) {
199                        var value = vals[i];
200                        vals[i] = value.replace(/conceptualdomain-value-/,'');
201                }
202                list.preselectValues(jsx3.util.List.wrap(vals));
203                org.isocat.gui.ProfileValueDomainEditor.log.info("ProfileValueDomainEditor.addValue():request preselect values");
204                 
205                 //check if the DC is member of the undecided/unavailable profile
206                 var q = null;
207                 if ((this.getProfiles().getRecord("profile-0")!=null) || (this.getProfiles().getRecord("profile--1")!=null)) {
208                         // any simple DC can be linked
209                         q = new org.isocat.data.Query(org.isocat.profile.user(),"simple",new Array());
210                         org.isocat.gui.ProfileValueDomainEditor.log.info("ProfileValueDomainEditor.addValue():query for any simple DC");
211                 } else {
212                         // only simple DCs from the selected profiles can be linked
213                         q = new org.isocat.data.Query(org.isocat.profile.user(),"simple",this.getProfiles().getRecordIds());
214                         org.isocat.gui.ProfileValueDomainEditor.log.info("ProfileValueDomainEditor.addValue():query for simple DCs belonging to selected profiles");
215                 }
216                 q.params("profs=true");
217                 list.load(q);
218                 org.isocat.gui.ProfileValueDomainEditor.log.info("ProfileValueDomainEditor.addValue():load query in list");
219        };
220       
221        ProfileValueDomainEditor_prototype.addValues = function(values) {
222                org.isocat.gui.ProfileValueDomainEditor.log.info("ProfileValueDomainEditor.addValues("+values+")");
223                var profs = this.getProfiles();
224                // need the following CDF record: @jsxid=conceptualdomain-value-<id> @jsxtext=<name> @name=<name> @identifier=<identifier> @profile-<id>=true @profile-<id>-<name>=<name>
225                for (var iter = values.iterator();iter.hasNext();) {
226                        var ins = false;
227                        var value = iter.next();
228                        var rec = {jsxid:"conceptualdomain-value-"+value.getAttribute("id"),jsxtext:value.getAttribute("name"),name:value.getAttribute("name"),identifier:value.getAttribute("identifier")};
229                        org.isocat.gui.ProfileValueDomainEditor.log.info("ProfileValueDomainEditor.addValues(...):rec["+rec.jsxid+"]");
230                        var vp = value.getAttribute("profiles").split(' ');
231                        var pm = 0;
232                        for (var p = 0;p<vp.length;p++) {
233                                var pid = "profile-"+vp[p];
234                                rec[pid] = '0'; // disable by default
235                                rec[pid+"-name"] = 'unk';
236                                var prof = profs.getRecord(pid);
237                                if (prof != null) {
238                                        rec[pid] = "1"; // enable as there is a profile value domain for this profile
239                                        pm++;
240                                }
241                                org.isocat.gui.ProfileValueDomainEditor.log.info("ProfileValueDomainEditor.addValues(...):rec["+rec.jsxid+"]."+pid+"["+rec[pid]+"]."+pid+"-name["+rec[pid+"-name"]+"]");
242                        }
243                        if (pm == 0) {
244                                var priv = profs.getRecord("profile-0");
245                                if (priv!=null) {
246                                        // add the simple DC to the undecided profile value domain
247                                        rec[priv.jsxid] = '1';
248                                        rec[priv.jsxid+"-name"] = priv.jsxtext;
249                                        org.isocat.gui.ProfileValueDomainEditor.log.info("ProfileValueDomainEditor.addValues(...):rec["+rec.jsxid+"]."+priv.jsxid+"["+rec[priv.jsxid]+"]."+priv.jsxid+"-name["+rec[priv.jsxid+"-name"]+"]");
250                                        ins = true;
251                                }
252                                if (!ins) {
253                                    priv = profs.getRecord("profile--1");
254                                    if (priv!=null) {
255                                           // add the simple DC to the uunavailable profile value domain
256                                           rec[priv.jsxid] = '1';
257                                           rec[priv.jsxid+"-name"] = priv.jsxtext;
258                                           org.isocat.gui.ProfileValueDomainEditor.log.info("ProfileValueDomainEditor.addValues(...):rec["+rec.jsxid+"]."+priv.jsxid+"["+rec[priv.jsxid]+"]."+priv.jsxid+"-name["+rec[priv.jsxid+"-name"]+"]");
259                                           ins = true;
260                                    }
261                            }
262                                if (!ins) {
263                                        org.isocat.gui.ProfileValueDomainEditor.log.info("ProfileValueDomainEditor.addValues(...):rec["+rec.jsxid+"] doesn't have an overlapping profile");
264                                        org.isocat.APP.alert("Can't add this simple DC","Sorry, you can't add the simple data category /"+rec.name+"/ because it doesn't have profile overlap with this closed data category.",null,"OK");
265                                }
266                        } else
267                                ins = true;
268                               
269                        if (ins) {
270                                this.viewer.insertRecord(rec);
271                                // addValue callback
272                                org.isocat.gui.ProfileValueDomainEditor.log.info("ProfileValueDomainEditor.addValues(...):addCallback ...");
273                                if (this.addCallback !== null)
274                                        this.addCallback.call(this.addContext,rec.jsxid);
275                                org.isocat.gui.ProfileValueDomainEditor.log.info("ProfileValueDomainEditor.addValues(...):addCallback ... done");
276                                this.changed();
277                                org.isocat.gui.ProfileValueDomainEditor.log.info("ProfileValueDomainEditor.addValues(...):changed");
278                        }
279                       
280                }
281                this.viewer.repaintData();
282                return true;
283        };
284       
285        ProfileValueDomainEditor_prototype.delValue = function(id) {
286                this.viewer.deleteRecord(id,true);
287                org.isocat.gui.ProfileValueDomainEditor.log.info("value["+id+"] deleted from CD");
288                // delValue callback
289                if (this.delCallback !== null)
290                        this.delCallback.call(this.delContext,id);
291                this.changed();
292        };
293       
294        ProfileValueDomainEditor_prototype.changed = function() {
295                // changed callback
296                if (this.changedCallback !== null)
297                        this.changedCallback.call(this.changedContext);
298        };
299});
Note: See TracBrowser for help on using the repository browser.