1 | jsx3.util.Logger.getLogger("org.isocat").info("Loading class[org.isocat.gui.DCEditor]"); |
---|
2 | |
---|
3 | /** |
---|
4 | * The DC viewer |
---|
5 | * @author Menzo.Windhouwer@mpi.nl |
---|
6 | */ |
---|
7 | jsx3.lang.Class.defineClass("org.isocat.gui.DCEditor", null, [], function(DCEditor, DCEditor_prototype) { |
---|
8 | |
---|
9 | /** |
---|
10 | * The class logger |
---|
11 | */ |
---|
12 | DCEditor.log = jsx3.util.Logger.getLogger("org.isocat.gui.DCEditor"); |
---|
13 | |
---|
14 | /** |
---|
15 | * The view block of the component |
---|
16 | */ |
---|
17 | DCEditor_prototype.view; |
---|
18 | |
---|
19 | /** |
---|
20 | * The window of the component |
---|
21 | */ |
---|
22 | DCEditor_prototype.window; |
---|
23 | |
---|
24 | /** |
---|
25 | * The editor CDF source |
---|
26 | */ |
---|
27 | DCEditor_prototype.cdf; |
---|
28 | |
---|
29 | /** |
---|
30 | * The DC |
---|
31 | */ |
---|
32 | DCEditor_prototype.dc; |
---|
33 | |
---|
34 | /** |
---|
35 | * The label |
---|
36 | */ |
---|
37 | DCEditor_prototype.label; |
---|
38 | |
---|
39 | /** |
---|
40 | * The save buttons |
---|
41 | */ |
---|
42 | DCEditor_prototype.saveButtonMenu; |
---|
43 | DCEditor_prototype.saveButtonWizard; |
---|
44 | |
---|
45 | /** |
---|
46 | * The cancel button |
---|
47 | */ |
---|
48 | DCEditor_prototype.cancelButtonWizard; |
---|
49 | |
---|
50 | /** |
---|
51 | * The check button |
---|
52 | */ |
---|
53 | DCEditor_prototype.checkButton; |
---|
54 | |
---|
55 | /** |
---|
56 | * The window button |
---|
57 | */ |
---|
58 | DCEditor_prototype.windowButton; |
---|
59 | |
---|
60 | /** |
---|
61 | * The view splitter |
---|
62 | */ |
---|
63 | DCEditor_prototype.viewSplitter; |
---|
64 | |
---|
65 | /** |
---|
66 | * The check result view |
---|
67 | */ |
---|
68 | DCEditor_prototype.checkView; |
---|
69 | |
---|
70 | /** |
---|
71 | * The check result viewer |
---|
72 | */ |
---|
73 | DCEditor_prototype.checkResult; |
---|
74 | |
---|
75 | /** |
---|
76 | * The editor stack |
---|
77 | */ |
---|
78 | DCEditor_prototype.stack; |
---|
79 | |
---|
80 | /** |
---|
81 | * The adminstrative information |
---|
82 | */ |
---|
83 | DCEditor_prototype.adminInfo; |
---|
84 | |
---|
85 | /** |
---|
86 | * The descriptive information |
---|
87 | */ |
---|
88 | DCEditor_prototype.descrInfo; |
---|
89 | |
---|
90 | /** |
---|
91 | * The linguistic information |
---|
92 | */ |
---|
93 | DCEditor_prototype.lingInfo; |
---|
94 | |
---|
95 | /** |
---|
96 | * Some of the form fields |
---|
97 | */ |
---|
98 | DCEditor_prototype.identifier; |
---|
99 | DCEditor_prototype.version; |
---|
100 | DCEditor_prototype.type; |
---|
101 | DCEditor_prototype.origin; |
---|
102 | DCEditor_prototype.administrationStatus; |
---|
103 | DCEditor_prototype.registrationStatus; |
---|
104 | DCEditor_prototype.effectiveDate; |
---|
105 | DCEditor_prototype.untilDate; |
---|
106 | DCEditor_prototype.explanations; |
---|
107 | DCEditor_prototype.issues; |
---|
108 | DCEditor_prototype.profiles; |
---|
109 | DCEditor_prototype.profileMask; |
---|
110 | DCEditor_prototype.dataElementNames; |
---|
111 | DCEditor_prototype.languageMenuLeft; |
---|
112 | DCEditor_prototype.languageMenuRight; |
---|
113 | DCEditor_prototype.languageSectionsSplitter; |
---|
114 | DCEditor_prototype.datatypes; |
---|
115 | DCEditor_prototype.valueDomain; |
---|
116 | DCEditor_prototype.ruleTypeMask; |
---|
117 | DCEditor_prototype.constraints; |
---|
118 | DCEditor_prototype.isA; |
---|
119 | DCEditor_prototype.linguisticMenuLeft; |
---|
120 | DCEditor_prototype.linguisticMenuRight; |
---|
121 | DCEditor_prototype.linguisticSectionsSplitter; |
---|
122 | |
---|
123 | /** |
---|
124 | * Tabs related to DC types |
---|
125 | */ |
---|
126 | DCEditor_prototype.simpleComplexTabs; |
---|
127 | DCEditor_prototype.closedConstrainedTabs; |
---|
128 | |
---|
129 | /** |
---|
130 | * language documents |
---|
131 | */ |
---|
132 | DCEditor_prototype.langsLeft; |
---|
133 | DCEditor_prototype.langsRight; |
---|
134 | |
---|
135 | /** |
---|
136 | * linguistic documents |
---|
137 | */ |
---|
138 | DCEditor_prototype.lingsLeft; |
---|
139 | DCEditor_prototype.lingsRight; |
---|
140 | /** |
---|
141 | * The change flag |
---|
142 | */ |
---|
143 | DCEditor_prototype.change; |
---|
144 | |
---|
145 | /** |
---|
146 | * Indentifier check results |
---|
147 | */ |
---|
148 | DCEditor_prototype.identifierCheckInfo; |
---|
149 | |
---|
150 | /** |
---|
151 | * Type change results |
---|
152 | */ |
---|
153 | DCEditor_prototype.DCType; |
---|
154 | DCEditor_prototype.typeChangeInfo; |
---|
155 | |
---|
156 | /** |
---|
157 | * Consistency checks |
---|
158 | */ |
---|
159 | DCEditor_prototype.checks; |
---|
160 | |
---|
161 | /** |
---|
162 | * Add to basket flag |
---|
163 | */ |
---|
164 | DCEditor_prototype.addToBasket; |
---|
165 | |
---|
166 | /** |
---|
167 | * Constructor |
---|
168 | */ |
---|
169 | DCEditor_prototype.init = function(view) { |
---|
170 | org.isocat.gui.DCEditor.log.info("initialize DC editor["+this+"]"); |
---|
171 | |
---|
172 | this.view = view; |
---|
173 | org.isocat.gui.DCEditor.log.info("- DC editor view["+this.view+"]"); |
---|
174 | this.window = null; |
---|
175 | org.isocat.gui.DCEditor.log.info("- DC editor window["+this.window+"]"); |
---|
176 | this.label = this.view.getDescendantOfName("label"); |
---|
177 | org.isocat.gui.DCEditor.log.info("- DC editor label["+this.label+"]"); |
---|
178 | this.cancelButtonWizard = this.view.getDescendantOfName("cancelButtonWizard"); |
---|
179 | org.isocat.gui.DCEditor.log.info("- DC editor cancel button (wizard) ["+this.cancelButtonWizard+"]"); |
---|
180 | this.saveButtonMenu = this.view.getDescendantOfName("saveButtonMenu"); |
---|
181 | org.isocat.gui.DCEditor.log.info("- DC editor save button (menu) ["+this.saveButtonMenu+"]"); |
---|
182 | this.saveButtonWizard = this.view.getDescendantOfName("saveButtonWizard"); |
---|
183 | org.isocat.gui.DCEditor.log.info("- DC editor save button (wizard) ["+this.saveButtonWizard+"]"); |
---|
184 | this.windowButton = null;//this.view.getDescendantOfName("windowButton"); |
---|
185 | org.isocat.gui.DCEditor.log.info("- DC editor window button["+this.windowButton+"]"); |
---|
186 | this.window = null; |
---|
187 | org.isocat.gui.DCEditor.log.info("- DC editor window["+this.window+"]"); |
---|
188 | this.cdf = this.view.getDescendantOfName("cdf"); |
---|
189 | org.isocat.gui.DCEditor.log.info("- DC editor cdf source["+this.cdf+"]"); |
---|
190 | this.stack = this.view.getDescendantOfName("stackgroup"); |
---|
191 | org.isocat.gui.DCEditor.log.info("- DC editor stack["+this.stack+"]"); |
---|
192 | this.adminInfo = this.view.getDescendantOfName("administrativeInformation"); |
---|
193 | org.isocat.gui.DCEditor.log.info("- DC editor administrative information["+this.adminInfo+"]"); |
---|
194 | this.descrInfo = this.view.getDescendantOfName("descriptiveInformation"); |
---|
195 | org.isocat.gui.DCEditor.log.info("- DC editor descriptive information["+this.descrInfo+"]"); |
---|
196 | this.lingInfo = this.view.getDescendantOfName("linguisticInformation"); |
---|
197 | org.isocat.gui.DCEditor.log.info("- DC editor linguistic information["+this.lingInfo+"]"); |
---|
198 | this.checkButton = this.view.getDescendantOfName("checkButton"); |
---|
199 | org.isocat.gui.DCEditor.log.info("- check button["+this.checkButton+"]"); |
---|
200 | this.viewSplitter = this.view.getDescendantOfName("viewSplitter"); |
---|
201 | org.isocat.gui.DCEditor.log.info("- view splitter"+this.viewSplitter+"]"); |
---|
202 | this.checkView = this.view.getDescendantOfName("CheckResultView"); |
---|
203 | org.isocat.gui.DCEditor.log.info("- check result view"+this.checkView+"]"); |
---|
204 | this.checkResult = this.view.getDescendantOfName("checkResult"); |
---|
205 | org.isocat.gui.DCEditor.log.info("- check result viewer"+this.checkResult+"]"); |
---|
206 | |
---|
207 | // get some of the forms fields |
---|
208 | this.identifier = this.view.getDescendantOfName("identifier"); |
---|
209 | this.version = this.view.getDescendantOfName("version"); |
---|
210 | this.type = this.view.getDescendantOfName("type"); |
---|
211 | this.origin = this.view.getDescendantOfName("origin"); |
---|
212 | this.administrationStatus = this.view.getDescendantOfName("administrationStatus"); |
---|
213 | this.registrationStatus = this.view.getDescendantOfName("registrationStatus"); |
---|
214 | this.effectiveDate = this.view.getDescendantOfName("effectiveDate"); |
---|
215 | this.untilDate = this.view.getDescendantOfName("untilDate"); |
---|
216 | this.explanations = this.view.getDescendantOfName("explanations"); |
---|
217 | this.issues = this.view.getDescendantOfName("issues"); |
---|
218 | this.profiles = this.view.getDescendantOfName("profiles"); |
---|
219 | this.profileMask = this.view.getDescendantOfName("profileMask"); |
---|
220 | org.isocat.gui.DCEditor.log.info("- DC editor profiles list["+this.profiles+"]"); |
---|
221 | this.dataElementNames = this.view.getDescendantOfName("dataElementNames"); |
---|
222 | this.languageMenuLeft = this.view.getDescendantOfName("languageMenuLeft"); |
---|
223 | this.languageMenuRight = this.view.getDescendantOfName("languageMenuRight"); |
---|
224 | this.languageSectionsSplitter = this.view.getDescendantOfName("languageSectionsSplitter"); |
---|
225 | org.isocat.gui.DCEditor.log.info("- DC editor language section splitter["+this.languageSectionsSplitter+"]"); |
---|
226 | this.languageSectionLeft = this.languageSectionsSplitter.getChild("left").getChild("LanguageSection").controller; |
---|
227 | this.languageSectionLeft.setEditor(this); |
---|
228 | org.isocat.gui.DCEditor.log.info("- DC editor language section left["+this.languageSectionLeft+"]"); |
---|
229 | this.languageSectionRight = this.languageSectionsSplitter.getChild("right").getChild("LanguageSection").controller; |
---|
230 | this.languageSectionRight.setEditor(this); |
---|
231 | org.isocat.gui.DCEditor.log.info("- DC editor language section right["+this.languageSectionRight+"]"); |
---|
232 | this.datatypes = this.view.getDescendantOfName("datatypes"); |
---|
233 | this.valueDomain = this.view.getDescendantOfName("ProfileValueDomainEditor").controller; |
---|
234 | this.ruleTypeMask = this.view.getDescendantOfName("ruleTypeMask"); |
---|
235 | this.constraints = this.view.getDescendantOfName("constraints"); |
---|
236 | this.isA = this.view.getDescendantOfName("isA"); |
---|
237 | this.linguisticMenuLeft = this.view.getDescendantOfName("linguisticMenuLeft"); |
---|
238 | this.linguisticMenuRight = this.view.getDescendantOfName("linguisticMenuRight"); |
---|
239 | this.linguisticSectionsSplitter = this.view.getDescendantOfName("linguisticSectionsSplitter"); |
---|
240 | this.linguisticSectionLeft = this.linguisticSectionsSplitter.getChild("left").getChild("LinguisticSection").controller; |
---|
241 | this.linguisticSectionLeft.setEditor(this); |
---|
242 | org.isocat.gui.DCEditor.log.info("- DC editor linguistic section left["+this.linguisticSectionLeft+"]"); |
---|
243 | this.linguisticSectionRight = this.linguisticSectionsSplitter.getChild("right").getChild("LinguisticSection").controller; |
---|
244 | this.linguisticSectionRight.setEditor(this); |
---|
245 | org.isocat.gui.DCEditor.log.info("- DC editor linguistic section right["+this.linguisticSectionRight+"]"); |
---|
246 | |
---|
247 | // get the DC type tabs |
---|
248 | this.simpleComplexTabs = this.view.getDescendantOfName("simpleComplexTabs"); |
---|
249 | this.closedConstrainedTabs = this.view.getDescendantOfName("closedConstrainedTabs"); |
---|
250 | |
---|
251 | // get the indentifier check info area |
---|
252 | this.identifierCheckInfo = this.view.getDescendantOfName("identifierCheckInfo"); |
---|
253 | this.identifierCheckInfo.setVisibility(jsx3.gui.Block.VISIBILITYHIDDEN,true); |
---|
254 | |
---|
255 | // get the type change info area |
---|
256 | this.DCType = null; |
---|
257 | this.typeChangeInfo = this.view.getDescendantOfName("typeChangeInfo"); |
---|
258 | this.typeChangeInfo.setVisibility(jsx3.gui.Block.VISIBILITYHIDDEN,true); |
---|
259 | |
---|
260 | // reset the active checks counter |
---|
261 | this.checks = new Object(); |
---|
262 | |
---|
263 | // reset the change flag |
---|
264 | this.change = false; |
---|
265 | |
---|
266 | // reset the add to basket flag |
---|
267 | this.addToBasket = false; |
---|
268 | |
---|
269 | // by default the cancel button is invisible |
---|
270 | this.cancelButtonWizard.setVisibility(jsx3.gui.Block.VISIBILITYHIDDEN,true); |
---|
271 | |
---|
272 | // reset some form fields |
---|
273 | this.identifier.setValue(""); |
---|
274 | this.version.setValue("0.0.0"); |
---|
275 | this.origin.setValue(""); |
---|
276 | this.administrationStatus.setValue("candidate"); |
---|
277 | this.registrationStatus.setValue("private"); |
---|
278 | this.effectiveDate.setDate(null); |
---|
279 | this.untilDate.setDate(null); |
---|
280 | this.isA.setText("<i>none</i>"); |
---|
281 | |
---|
282 | // make the admin info active |
---|
283 | this.stack.setSelectedIndex(0); |
---|
284 | |
---|
285 | // reset all text/select masks |
---|
286 | var columns = this.view.getDescendantsOfType(jsx3.gui.Matrix.Column,false); |
---|
287 | for (var c=0;c<columns.length;c++) { |
---|
288 | var column = columns[c]; |
---|
289 | var masks = column.getDescendantsOfType(jsx3.gui.TextBox,true); |
---|
290 | for (var m=0;m<masks.length;m++) { |
---|
291 | var mask = masks[m]; |
---|
292 | mask.setWidth("100%"); |
---|
293 | } |
---|
294 | masks = column.getDescendantsOfType(jsx3.gui.Select,true); |
---|
295 | for (var m=0;m<masks.length;m++) { |
---|
296 | var mask = masks[m]; |
---|
297 | mask.setWidth("100%"); |
---|
298 | } |
---|
299 | } |
---|
300 | |
---|
301 | // load the profiles |
---|
302 | var cacheId = "profiles-"+this.view.getId(); |
---|
303 | var profs = org.isocat.loadDynamicCDFDocument(new jsx3.net.URI("http://isocat:8080/isocat/rest/info/profiles.xml"),"Profiles2CDF_xsl",null,cacheId); |
---|
304 | this.profileMask.setXMLId(cacheId); |
---|
305 | |
---|
306 | // set the callbacks for the profile value domains editor |
---|
307 | this.valueDomain.setDelCallback(this,this.delValue); |
---|
308 | this.valueDomain.setChangedCallback(this,this.changed); |
---|
309 | |
---|
310 | // intialize language/linguistic selectors |
---|
311 | var langs = org.isocat.loadDynamicCDFDocument(new jsx3.net.URI("http://isocat:8080/isocat/rest/info/languages.xml"),"Languages2CDF_xsl"); |
---|
312 | var cacheId = "language-"+this.view.getId(); |
---|
313 | |
---|
314 | this.langsLeft = langs.cloneDocument(); |
---|
315 | this.langsLeft.insertRecord({jsxid:"none", jsxtext:"none", jsxdivider:"1"}); |
---|
316 | org.isocat.APP.getCache().setDocument(cacheId+"-left",this.langsLeft); |
---|
317 | this.languageMenuLeft.setXMLId(cacheId+"-left"); |
---|
318 | this.languageMenuLeft.setText("Language"); |
---|
319 | this.languageMenuLeft.setImage("images/flag.png"); |
---|
320 | this.languageMenuLeft.repaint(); |
---|
321 | |
---|
322 | this.langsRight = langs.cloneDocument(); |
---|
323 | this.langsRight.insertRecord({jsxid:"none", jsxtext:"none", jsxdivider:"1"}); |
---|
324 | org.isocat.APP.getCache().setDocument(cacheId+"-right",this.langsRight); |
---|
325 | this.languageMenuRight.setXMLId(cacheId+"-right"); |
---|
326 | this.languageMenuRight.setText("Language"); |
---|
327 | this.languageMenuRight.setImage("images/flag.png"); |
---|
328 | this.languageMenuRight.repaint(); |
---|
329 | |
---|
330 | //this.languageSectionsSplitter.setSubcontainer1Pct("100",true); |
---|
331 | |
---|
332 | langs = org.isocat.loadDynamicCDFDocument(new jsx3.net.URI("http://isocat:8080/isocat/rest/info/languages.xml"),"LinguisticLanguages2CDF_xsl"); |
---|
333 | cacheId = "linguistic-"+this.view.getId(); |
---|
334 | |
---|
335 | this.lingsLeft = langs.cloneDocument(); |
---|
336 | this.lingsLeft.insertRecord({jsxid:"none", jsxtext:"none", jsxdivider:"1"}); |
---|
337 | org.isocat.APP.getCache().setDocument(cacheId+"-left",this.lingsLeft); |
---|
338 | this.linguisticMenuLeft.setXMLId(cacheId+"-left"); |
---|
339 | this.linguisticMenuLeft.setText("Language"); |
---|
340 | this.linguisticMenuLeft.setImage("images/flag.png"); |
---|
341 | this.linguisticMenuLeft.repaint(); |
---|
342 | |
---|
343 | this.lingsRight = langs.cloneDocument(); |
---|
344 | this.lingsRight.insertRecord({jsxid:"none", jsxtext:"none", jsxdivider:"1"}); |
---|
345 | org.isocat.APP.getCache().setDocument(cacheId+"-right",this.lingsRight); |
---|
346 | this.linguisticMenuRight.setXMLId(cacheId+"-right"); |
---|
347 | this.linguisticMenuRight.setText("Language"); |
---|
348 | this.linguisticMenuRight.setImage("images/flag.png"); |
---|
349 | this.linguisticMenuRight.repaint(); |
---|
350 | |
---|
351 | // initialize the datatypes |
---|
352 | var cacheId = "datatypes-"+this.view.getId(); |
---|
353 | org.isocat.loadDynamicCDFDocument(new jsx3.net.URI("http://isocat:8080/isocat/rest/info/data-types.xml"),"Datatypes2CDF_xsl",null,cacheId); |
---|
354 | this.datatypes.setXMLId(cacheId); |
---|
355 | |
---|
356 | // initialize the rule types |
---|
357 | var cacheId = "ruletypes-"+this.view.getId(); |
---|
358 | var ruleTypes = org.isocat.loadDynamicCDFDocument(new jsx3.net.URI("http://isocat:8080/isocat/rest/info/rule-types.xml"),"RuleTypes2CDF_xsl",null,cacheId); |
---|
359 | this.ruleTypeMask.setXMLId(cacheId); |
---|
360 | |
---|
361 | // reset more of the form |
---|
362 | //this.newDataCategory(); |
---|
363 | |
---|
364 | org.isocat.gui.DCEditor.log.info("initialized DC editor["+this+"]"); |
---|
365 | |
---|
366 | this.view.controller = this; |
---|
367 | |
---|
368 | // publish the message using PageBus |
---|
369 | org.isocat.publish("org.isocat.gui.DCEditor.init", this); |
---|
370 | }; |
---|
371 | |
---|
372 | DCEditor_prototype.dcId = function() { |
---|
373 | var id = this.view.getId(); |
---|
374 | if (typeof(this.dc) != 'undefined') |
---|
375 | id = this.dc.id; |
---|
376 | return "dc-"+id; |
---|
377 | }; |
---|
378 | |
---|
379 | DCEditor_prototype.cacheId = function() { |
---|
380 | return "DC-"+this.dcId(); |
---|
381 | }; |
---|
382 | |
---|
383 | DCEditor_prototype.newDataCategory = function(addToBasket) { |
---|
384 | if (typeof(addToBasket) == 'undefined') |
---|
385 | this.addToBasket = false; |
---|
386 | else |
---|
387 | this.addToBasket = addToBasket; |
---|
388 | this.editDataCategory(); |
---|
389 | }; |
---|
390 | |
---|
391 | DCEditor_prototype.editDataCategory = function(dc) { |
---|
392 | org.isocat.gui.Loading.load(this.view,"Loading ...").show(); |
---|
393 | |
---|
394 | this.dc = dc; |
---|
395 | |
---|
396 | var src = null; |
---|
397 | |
---|
398 | if (typeof(dc) == 'undefined') { |
---|
399 | org.isocat.gui.DCEditor.log.info("editing new DC"); |
---|
400 | src = "dc_xml"; |
---|
401 | this.canCheck(false); |
---|
402 | } else { |
---|
403 | org.isocat.gui.DCEditor.log.info("editing existing DC["+dc.id+"]"); |
---|
404 | |
---|
405 | if (!this.lockDataCategory()) { |
---|
406 | //this.close(); |
---|
407 | return false; |
---|
408 | } |
---|
409 | |
---|
410 | // set the title |
---|
411 | this.setTitle(); |
---|
412 | |
---|
413 | // disable the type field |
---|
414 | //this.type.setEnabled(jsx3.gui.Form.STATEDISABLED,true); |
---|
415 | |
---|
416 | // load the DC content |
---|
417 | src = jsx3.net.URI.valueOf("http://isocat:8080/isocat/rest/dc/"+this.dc.id+".dcif?dcif-cleanup=false&parse-xml-constraints=false"); |
---|
418 | |
---|
419 | // we can check an existing DC |
---|
420 | this.checkIcon(); |
---|
421 | this.canCheck(true); |
---|
422 | } |
---|
423 | |
---|
424 | this.check(false); |
---|
425 | |
---|
426 | this.checks = new Object(); |
---|
427 | |
---|
428 | if (src != null) { |
---|
429 | org.isocat.gui.DCEditor.log.info("load uri["+src+"]."); |
---|
430 | org.isocat.loadDynamicCDFDocument(src,"DC2CDF_xsl",null,this.cacheId()); |
---|
431 | |
---|
432 | // update the rest of the interface |
---|
433 | this.update(); |
---|
434 | } |
---|
435 | |
---|
436 | return true; |
---|
437 | }; |
---|
438 | |
---|
439 | DCEditor_prototype.lockDataCategory = function() { |
---|
440 | var locked = false; |
---|
441 | // acquire a lock on the DC |
---|
442 | var lock = org.isocat.profile.lockDC(this.dc.id); |
---|
443 | if (lock == null) { |
---|
444 | // there was an error in getting this lock, probably you can't edit this DC |
---|
445 | org.isocat.APP.alert("Can't edit this DC","Sorry, you can't edit this data category because you can't lock it.",null,"OK"); |
---|
446 | this.lock = null; |
---|
447 | } else { |
---|
448 | var type = lock.selectSingleNode("/*").getNodeName(); |
---|
449 | if (type == 'nolock') { |
---|
450 | // this DC is already locked |
---|
451 | var name = lock.selectSingleNode("/nolock/user").getValue(); |
---|
452 | org.isocat.APP.alert("DC is already locked","Sorry, you can't edit this data category because it is locked by another user ("+name+").",null,"OK"); |
---|
453 | this.lock = null; |
---|
454 | } else if (type == 'lock') { |
---|
455 | org.isocat.gui.DCEditor.log.info("acquired DC lock["+lock+"]"); |
---|
456 | var id = lock.selectSingleNode("/lock/id").getValue(); |
---|
457 | this.lock = {id:id}; |
---|
458 | locked = true; |
---|
459 | } else { |
---|
460 | org.isocat.APP.alert("Can't edit this DC","An error occured and the data category couldn't be locked! Please contact the ISOcat system administrator.",null,"OK"); |
---|
461 | this.lock = null; |
---|
462 | } |
---|
463 | } |
---|
464 | return locked; |
---|
465 | }; |
---|
466 | |
---|
467 | DCEditor_prototype.update = function() { |
---|
468 | org.isocat.gui.DCEditor.log.info("update DC editor["+this+"] ..."); |
---|
469 | |
---|
470 | // update the CDF data source |
---|
471 | this.cdf.setXMLId(this.cacheId()); |
---|
472 | this.cdf.setCDFId(this.dcId()); |
---|
473 | this.cdf.read(true); |
---|
474 | |
---|
475 | org.isocat.gui.DCEditor.log.info("updated the DC editor CDF source with cache["+this.cacheId()+"]."); |
---|
476 | |
---|
477 | this.updateAdminInfo(); |
---|
478 | this.updateDescrInfo(); |
---|
479 | this.updateLingInfo(); |
---|
480 | |
---|
481 | // reset buttons |
---|
482 | this.canSave(false); |
---|
483 | |
---|
484 | this.change = false; |
---|
485 | |
---|
486 | // reset the title |
---|
487 | this.setTitle(); |
---|
488 | |
---|
489 | org.isocat.gui.Loading.load(this.view,"Loading ...").hide(); |
---|
490 | |
---|
491 | org.isocat.gui.DCEditor.log.info("... update DC editor["+this+"]"); |
---|
492 | }; |
---|
493 | |
---|
494 | DCEditor_prototype.updateAdminInfo = function() { |
---|
495 | org.isocat.gui.DCEditor.log.info("update DC editor["+this+"] administrative information ..."); |
---|
496 | |
---|
497 | var cdfDoc = this.cdf.getXML(); |
---|
498 | |
---|
499 | // reset the DC type switch |
---|
500 | this.DCType = null; |
---|
501 | this.typeChangeInfo.setVisibility(jsx3.gui.Block.VISIBILITYHIDDEN,true); |
---|
502 | |
---|
503 | var cacheId = this.cacheId()+"-explanations"; |
---|
504 | org.isocat.APP.getCache().setDocument(cacheId,org.isocat.createSubCDFDocument(cdfDoc,"explanations",true)); |
---|
505 | this.explanations.setXMLId(cacheId); |
---|
506 | this.explanations.repaintData(); |
---|
507 | |
---|
508 | cacheId = this.cacheId()+"-issues"; |
---|
509 | org.isocat.APP.getCache().setDocument(cacheId,org.isocat.createSubCDFDocument(cdfDoc,"issues",true)); |
---|
510 | this.issues.setXMLId(cacheId); |
---|
511 | this.issues.repaintData(); |
---|
512 | |
---|
513 | org.isocat.gui.DCEditor.log.info("... update DC editor["+this+"] administrative information"); |
---|
514 | }; |
---|
515 | |
---|
516 | DCEditor_prototype.updateDescrInfo = function() { |
---|
517 | org.isocat.gui.DCEditor.log.info("update DC editor["+this+"] descriptive information ..."); |
---|
518 | |
---|
519 | var cdfDoc = this.cdf.getXML(); |
---|
520 | |
---|
521 | // profiles |
---|
522 | var profs = org.isocat.createSubCDFDocument(cdfDoc,"profiles",true); |
---|
523 | var cacheId = this.cacheId()+"-profiles"; |
---|
524 | org.isocat.APP.getCache().setDocument(cacheId,profs); |
---|
525 | this.profiles.setXMLId(cacheId); |
---|
526 | this.profiles.repaintData(); |
---|
527 | profs = profs.getRecordIds(); |
---|
528 | if (typeof(profs)=='undefined' || profs.length==0) { |
---|
529 | this.setCheck("profiles","none"); |
---|
530 | } else { |
---|
531 | this.setCheck("profiles","ok"); |
---|
532 | } |
---|
533 | |
---|
534 | |
---|
535 | // data element names |
---|
536 | var cacheId = this.cacheId()+"-datanames"; |
---|
537 | org.isocat.APP.getCache().setDocument(cacheId,org.isocat.createSubCDFDocument(cdfDoc,"datanames",true)); |
---|
538 | this.dataElementNames.setXMLId(cacheId); |
---|
539 | this.dataElementNames.repaintData(); |
---|
540 | |
---|
541 | this.languageSectionLeft.reset(); |
---|
542 | this.languageSectionRight.reset(); |
---|
543 | |
---|
544 | // check the existing language sections |
---|
545 | var langs = this.langsLeft.getRecordIds(); |
---|
546 | for(var i=0;i<langs.length;i++) { |
---|
547 | var lang = this.langsLeft.getRecordNode(langs[i]); |
---|
548 | var tag = lang.getAttribute("tag"); |
---|
549 | var lsec = cdfDoc.selectSingleNode("//record[@jsxid='languagesections']/record[@jsxtext='"+tag+"']"); |
---|
550 | //org.isocat.gui.DCEditor.log.info("- language section["+tag+"]:"+(lsec!=null?"1":"0")); |
---|
551 | lang.setAttribute("jsxselected",(lsec!=null?"1":"0")) |
---|
552 | lang = this.langsRight.getRecordNode(langs[i]); |
---|
553 | lang.setAttribute("jsxselected",(lsec!=null?"1":"0")) |
---|
554 | } |
---|
555 | |
---|
556 | // select the english language section, if it exists |
---|
557 | var english = this.langsLeft.selectSingleNode("//record[@tag='en']"); |
---|
558 | if (english!=null) { |
---|
559 | this.selectLanguageSection(this.languageMenuLeft,english); |
---|
560 | } else { |
---|
561 | org.isocat.gui.DCEditor.log.info("... no english?"); |
---|
562 | this.selectLanguageSection(this.languageMenuLeft,this.langsLeft.selectSingleNode("//record[@tag]")); |
---|
563 | } |
---|
564 | |
---|
565 | this.selectLanguageSection(this.languageMenuRight,this.langsRight.selectSingleNode("//record[@jsxid='none']")); |
---|
566 | |
---|
567 | org.isocat.gui.DCEditor.log.info("... update DC editor["+this+"] descriptive information"); |
---|
568 | }; |
---|
569 | |
---|
570 | DCEditor_prototype.updateLingInfo = function() { |
---|
571 | org.isocat.gui.DCEditor.log.info("update DC editor["+this+"] linguistic information ..."); |
---|
572 | |
---|
573 | var cdfDoc = this.cdf.getXML(); |
---|
574 | |
---|
575 | var dcType = this.cdf.getXML().getRecord("admin").type; |
---|
576 | if (dcType === null) |
---|
577 | dcType = "complex"; |
---|
578 | var cdType = this.cdf.getXML().getRecord("conceptualdomain").type; |
---|
579 | if (cdType === null) |
---|
580 | cdType = "open"; |
---|
581 | |
---|
582 | // complex DC: data type |
---|
583 | var datatype = cdfDoc.getRecordNode("conceptualdomain").getAttribute("datatype-id"); |
---|
584 | if (datatype === null) |
---|
585 | datatype = "datatype-1"; // the id of the default data type: string |
---|
586 | this.datatypes.setValue(datatype); |
---|
587 | |
---|
588 | // when this.datatypes is a tree |
---|
589 | //this.datatypes.selectRecord("datatype-1"); |
---|
590 | //var par = this.datatypes.getRecordNode("datatype-1").getParent(); |
---|
591 | //while (par.getNodeName()=='record') { |
---|
592 | // par.setAttribute("jsxopen","1"); |
---|
593 | // par = par.getParent(); |
---|
594 | //} |
---|
595 | |
---|
596 | // closed DC: value domain |
---|
597 | var cacheId = this.cacheId()+"-valuedomain"; |
---|
598 | if (cdType == "closed") { |
---|
599 | org.isocat.APP.getCache().setDocument(cacheId,org.isocat.createSubCDFDocument(cdfDoc,"conceptualdomain",true)); |
---|
600 | } else { |
---|
601 | org.isocat.APP.getCache().setDocument(cacheId,new jsx3.xml.CDF.Document.newDocument()); // an empty CDF document |
---|
602 | } |
---|
603 | this.valueDomain.setProfiles(this.getProfiles()); |
---|
604 | this.valueDomain.setValues(cacheId); |
---|
605 | |
---|
606 | // constrained DC: constraints |
---|
607 | var cacheId = this.cacheId()+"-constraints"; |
---|
608 | if (cdType == "constrained") { |
---|
609 | org.isocat.APP.getCache().setDocument(cacheId,org.isocat.createSubCDFDocument(cdfDoc,"conceptualdomain",true)); |
---|
610 | } else { |
---|
611 | org.isocat.APP.getCache().setDocument(cacheId,new jsx3.xml.CDF.Document.newDocument()); // an empty CDF document |
---|
612 | } |
---|
613 | this.constraints.setXMLId(cacheId); |
---|
614 | this.constraints.repaintData(); |
---|
615 | |
---|
616 | // simple DC |
---|
617 | this.isARecord = null; |
---|
618 | if (dcType == "simple") { |
---|
619 | this.isARecord = this.cdf.getXML().getRecord("is-a"); |
---|
620 | this.updateIsA(); |
---|
621 | } |
---|
622 | |
---|
623 | this.linguisticSectionLeft.reset(); |
---|
624 | this.linguisticSectionRight.reset(); |
---|
625 | |
---|
626 | // check the existing linguistic sections |
---|
627 | var langs = this.lingsLeft.getRecordIds(); |
---|
628 | for(var i=0;i<langs.length;i++) { |
---|
629 | var lang = this.lingsLeft.getRecordNode(langs[i]); |
---|
630 | var tag = lang.getAttribute("tag"); |
---|
631 | var lsec = cdfDoc.selectSingleNode("//record[@jsxid='linguisticsections']/record[@jsxtext='"+tag+"']"); |
---|
632 | //org.isocat.gui.DCEditor.log.info("- language section["+tag+"]:"+(lsec!=null?"1":"0")); |
---|
633 | lang.setAttribute("jsxselected",(lsec!=null?"1":"0")) |
---|
634 | lang = this.lingsRight.getRecordNode(langs[i]); |
---|
635 | lang.setAttribute("jsxselected",(lsec!=null?"1":"0")) |
---|
636 | } |
---|
637 | |
---|
638 | this.selectLinguisticSection(this.linguisticMenuLeft,this.lingsLeft.selectSingleNode("//record[@jsxid='none']")); |
---|
639 | this.selectLinguisticSection(this.linguisticMenuRight,this.lingsRight.selectSingleNode("//record[@jsxid='none']")); |
---|
640 | |
---|
641 | org.isocat.gui.DCEditor.log.info("... update DC editor["+this+"] linguistic information"); |
---|
642 | }; |
---|
643 | |
---|
644 | DCEditor_prototype.updateLanguageMenu = function(menu,lang,repaint) { |
---|
645 | if (lang != "none") { |
---|
646 | var objRECORD = menu.getRecordNode(lang); |
---|
647 | menu.setText(objRECORD.getAttribute("jsxtext")); |
---|
648 | if (objRECORD.getAttribute("jsximg")!=null) |
---|
649 | menu.setImage(objRECORD.getAttribute("jsximg")); |
---|
650 | else |
---|
651 | menu.setImage("images/flag.png"); |
---|
652 | } else { |
---|
653 | menu.setText("Language"); |
---|
654 | menu.setImage("images/flag.png"); |
---|
655 | } |
---|
656 | |
---|
657 | if (repaint) |
---|
658 | menu.repaint(); |
---|
659 | } |
---|
660 | |
---|
661 | DCEditor_prototype.syncLanguageSectionsMenus = function(src,lang,repaint) { |
---|
662 | var dst = null; |
---|
663 | if (src == this.languageMenuLeft) |
---|
664 | dst = this.languageMenuRight; |
---|
665 | else |
---|
666 | dst = this.languageMenuLeft; |
---|
667 | |
---|
668 | org.isocat.gui.DCEditor.log.info("DCEditor.syncLanguageSectionsMenus:src["+src+"]dst["+dst+"]lang["+lang+"]"); |
---|
669 | |
---|
670 | var langs = dst.getRecordIds(); |
---|
671 | for(var i=0;i<langs.length;i++) |
---|
672 | if (langs[i] == lang) |
---|
673 | dst.getRecordNode(lang).setAttribute("jsxdisabled","1"); // disable the selected lang in the src menu in the dst menu |
---|
674 | else |
---|
675 | dst.getRecordNode(langs[i]).setAttribute("jsxdisabled","0"); |
---|
676 | |
---|
677 | if (repaint) |
---|
678 | dst.repaint(); |
---|
679 | }; |
---|
680 | |
---|
681 | DCEditor_prototype.selectLanguageSection = function(menu,lang) { |
---|
682 | var langid = lang.getAttribute("jsxid"); |
---|
683 | this.updateLanguageMenu(menu,langid,false); |
---|
684 | this.syncLanguageSectionsMenus(menu,langid,false); |
---|
685 | |
---|
686 | // save the previously selected language section (if it has changed) |
---|
687 | var saved = null; |
---|
688 | if (menu == this.languageMenuRight) { |
---|
689 | if (this.languageSectionRight.save(false)) |
---|
690 | saved = this.languageSectionRight.lang; |
---|
691 | } else { |
---|
692 | if (this.languageSectionLeft.save(false)) |
---|
693 | saved = this.languageSectionLeft.lang; |
---|
694 | } |
---|
695 | |
---|
696 | // check the saved language section in the menus |
---|
697 | if (saved!=null) { |
---|
698 | this.langsLeft.getRecordNode(saved.getAttribute("jsxid")).setAttribute("jsxselected","1"); |
---|
699 | this.langsRight.getRecordNode(saved.getAttribute("jsxid")).setAttribute("jsxselected","1"); |
---|
700 | } |
---|
701 | |
---|
702 | this.languageMenuRight.repaint(); |
---|
703 | this.languageMenuLeft.repaint(); |
---|
704 | |
---|
705 | if (langid!="none") { |
---|
706 | if (menu == this.languageMenuRight) { |
---|
707 | if (this.languageSectionsSplitter.getSubcontainer1Pct() == "100") { |
---|
708 | this.languageSectionsSplitter.setSubcontainer1Pct("50",true); |
---|
709 | } |
---|
710 | } else { |
---|
711 | if (this.languageSectionsSplitter.getSubcontainer1Pct() == "0") { |
---|
712 | this.languageSectionsSplitter.setSubcontainer1Pct("50",true); |
---|
713 | } |
---|
714 | } |
---|
715 | |
---|
716 | this.showLanguageSection(menu,lang); |
---|
717 | } else { |
---|
718 | if (menu == this.languageMenuRight) { |
---|
719 | if (this.languageSectionsSplitter.getSubcontainer1Pct() != "100") |
---|
720 | this.languageSectionsSplitter.setSubcontainer1Pct("100",true); |
---|
721 | this.languageSectionRight.reset(); |
---|
722 | this.languageSectionRight.disable(); |
---|
723 | } else { |
---|
724 | if (this.languageSectionsSplitter.getSubcontainer1Pct() != "0") |
---|
725 | this.languageSectionsSplitter.setSubcontainer1Pct("0",true); |
---|
726 | this.languageSectionLeft.reset(); |
---|
727 | this.languageSectionLeft.disable(); |
---|
728 | } |
---|
729 | } |
---|
730 | }; |
---|
731 | |
---|
732 | DCEditor_prototype.showLanguageSection = function(src,lang) { |
---|
733 | var dst = null; |
---|
734 | if (src == this.languageMenuLeft) |
---|
735 | dst = this.languageSectionLeft; |
---|
736 | else |
---|
737 | dst = this.languageSectionRight; |
---|
738 | |
---|
739 | var lsec = this.cdf.getXML().selectSingleNode("//record[@jsxid='languagesections']/record[@language='"+lang.getAttribute("jsxid")+"']"); |
---|
740 | org.isocat.gui.DCEditor.log.info("DCEditor.showLanguageSection(src["+src+"]dst["+dst+"]lang["+lang+"]):lsec["+lsec+"]"); |
---|
741 | |
---|
742 | dst.enable(); |
---|
743 | if (lsec!=null) { |
---|
744 | // use the existing one |
---|
745 | dst.editLanguageSection(lang,lsec,this.cdf.getXML()); |
---|
746 | } else { |
---|
747 | // check if a record with id 'languagesections' exists |
---|
748 | var ls = this.cdf.getXML().getRecordNode('languagesections'); |
---|
749 | if (ls == null) |
---|
750 | this.cdf.getXML().insertRecord({jsxid:'languagesections'},this.dcId()); |
---|
751 | // create a new one, and use that |
---|
752 | var id = jsx3.xml.CDF.getKey(); |
---|
753 | lsec = {jsxid:id, language:lang.getAttribute("jsxid"), jsxtext:lang.getAttribute("tag")}; |
---|
754 | lsec = this.cdf.getXML().insertRecord(lsec,'languagesections',true); |
---|
755 | org.isocat.gui.DCEditor.log.info("DCEditor.showLanguageSection(...):added lsec["+id+"]["+lsec+"]"); |
---|
756 | dst.editLanguageSection(lang,lsec,this.cdf.getXML()); |
---|
757 | } |
---|
758 | }; |
---|
759 | |
---|
760 | DCEditor_prototype.updateLinguisticMenu = function(menu,lang,repaint) { |
---|
761 | if (lang != "none") { |
---|
762 | var objRECORD = menu.getRecordNode(lang); |
---|
763 | menu.setText(objRECORD.getAttribute("jsxtext")); |
---|
764 | if (objRECORD.getAttribute("jsximg")!=null) |
---|
765 | menu.setImage(objRECORD.getAttribute("jsximg")); |
---|
766 | else |
---|
767 | menu.setImage("images/flag.png"); |
---|
768 | } else { |
---|
769 | menu.setText("Language"); |
---|
770 | menu.setImage("images/flag.png"); |
---|
771 | } |
---|
772 | |
---|
773 | if (repaint) |
---|
774 | menu.repaint(); |
---|
775 | } |
---|
776 | |
---|
777 | DCEditor_prototype.syncLinguisticSectionsMenus = function(src,lang,repaint) { |
---|
778 | var dst = null; |
---|
779 | if (src == this.linguisticMenuLeft) |
---|
780 | dst = this.linguisticMenuRight; |
---|
781 | else |
---|
782 | dst = this.linguisticMenuLeft; |
---|
783 | |
---|
784 | org.isocat.gui.DCEditor.log.info("DCEditor.syncLinguisticSectionsMenus:src["+src+"]dst["+dst+"]lang["+lang+"]"); |
---|
785 | |
---|
786 | var langs = dst.getRecordIds(); |
---|
787 | for(var i=0;i<langs.length;i++) |
---|
788 | if (langs[i] == lang) |
---|
789 | dst.getRecordNode(lang).setAttribute("jsxdisabled","1"); // disable the selected lang in the src menu in the dst menu |
---|
790 | else |
---|
791 | dst.getRecordNode(langs[i]).setAttribute("jsxdisabled","0"); |
---|
792 | |
---|
793 | if (repaint) |
---|
794 | dst.repaint(); |
---|
795 | }; |
---|
796 | |
---|
797 | DCEditor_prototype.selectLinguisticSection = function(menu,lang) { |
---|
798 | var langid = lang.getAttribute("jsxid"); |
---|
799 | this.updateLinguisticMenu(menu,langid,false); |
---|
800 | this.syncLinguisticSectionsMenus(menu,langid,false); |
---|
801 | |
---|
802 | // save the previously selected linguistic section (if it has changed) |
---|
803 | var saved = null; |
---|
804 | if (menu == this.linguisticMenuRight) { |
---|
805 | if (this.linguisticSectionRight.save(false)) |
---|
806 | saved = this.linguisticSectionRight.lang; |
---|
807 | } else { |
---|
808 | if (this.linguisticSectionLeft.save(false)) |
---|
809 | saved = this.linguisticSectionLeft.lang; |
---|
810 | } |
---|
811 | |
---|
812 | // check the saved linguistic section in the menus |
---|
813 | if (saved!=null) { |
---|
814 | this.lingsLeft.getRecordNode(saved.getAttribute("jsxid")).setAttribute("jsxselected","1"); |
---|
815 | this.lingsRight.getRecordNode(saved.getAttribute("jsxid")).setAttribute("jsxselected","1"); |
---|
816 | } |
---|
817 | |
---|
818 | this.linguisticMenuRight.repaint(); |
---|
819 | this.linguisticMenuLeft.repaint(); |
---|
820 | |
---|
821 | if (langid!="none") { |
---|
822 | if (menu == this.linguisticMenuRight) { |
---|
823 | if (this.linguisticSectionsSplitter.getSubcontainer1Pct() == "100") { |
---|
824 | this.linguisticSectionsSplitter.setSubcontainer1Pct("50",true); |
---|
825 | } |
---|
826 | } else { |
---|
827 | if (this.linguisticSectionsSplitter.getSubcontainer1Pct() == "0") { |
---|
828 | this.linguisticSectionsSplitter.setSubcontainer1Pct("50",true); |
---|
829 | } |
---|
830 | } |
---|
831 | |
---|
832 | this.showLinguisticSection(menu,lang); |
---|
833 | } else { |
---|
834 | if (menu == this.linguisticMenuRight) { |
---|
835 | if (this.linguisticSectionsSplitter.getSubcontainer1Pct() != "100") |
---|
836 | this.linguisticSectionsSplitter.setSubcontainer1Pct("100",true); |
---|
837 | this.linguisticSectionRight.reset(); |
---|
838 | this.linguisticSectionRight.disable(); |
---|
839 | } else { |
---|
840 | if (this.linguisticSectionsSplitter.getSubcontainer1Pct() != "0") |
---|
841 | this.linguisticSectionsSplitter.setSubcontainer1Pct("0",true); |
---|
842 | this.linguisticSectionLeft.reset(); |
---|
843 | this.linguisticSectionLeft.disable(); |
---|
844 | } |
---|
845 | } |
---|
846 | }; |
---|
847 | |
---|
848 | DCEditor_prototype.showLinguisticSection = function(src,lang) { |
---|
849 | var dst = null; |
---|
850 | if (src == this.linguisticMenuLeft) |
---|
851 | dst = this.linguisticSectionLeft; |
---|
852 | else |
---|
853 | dst = this.linguisticSectionRight; |
---|
854 | |
---|
855 | var lsec = this.cdf.getXML().selectSingleNode("//record[@jsxid='linguisticsections']/record[@language='"+lang.getAttribute("jsxid")+"']"); |
---|
856 | org.isocat.gui.DCEditor.log.info("DCEditor.showLinguisticSection(src["+src+"]dst["+dst+"]lang["+lang+"]):lsec["+lsec+"]"); |
---|
857 | |
---|
858 | dst.enable(); |
---|
859 | if (lsec!=null) { |
---|
860 | // use the existing one |
---|
861 | dst.editLinguisticSection(lang,lsec,this.cdf.getXML()); |
---|
862 | } else { |
---|
863 | // check if a record with id 'linguisticsections' exists |
---|
864 | var ls = this.cdf.getXML().getRecordNode('linguisticsections'); |
---|
865 | if (ls == null) |
---|
866 | this.cdf.getXML().insertRecord({jsxid:'linguisticsections'},this.dcId()); |
---|
867 | // create a new one, and use that |
---|
868 | var id = jsx3.xml.CDF.getKey(); |
---|
869 | lsec = {jsxid:id, language:lang.getAttribute("jsxid"), jsxtext:lang.getAttribute("tag"), type:dst.domainType }; |
---|
870 | lsec = this.cdf.getXML().insertRecord(lsec,'linguisticsections',true); |
---|
871 | org.isocat.gui.DCEditor.log.info("DCEditor.showLinguisticSection(...):added lsec["+id+"]["+lsec+"]"); |
---|
872 | dst.editLinguisticSection(lang,lsec,this.cdf.getXML()); |
---|
873 | } |
---|
874 | }; |
---|
875 | |
---|
876 | DCEditor_prototype.addExplanation = function() { |
---|
877 | var id = jsx3.xml.CDF.getKey(); |
---|
878 | var rec = this.explanations.insertRecord({jsxid:id,jsxtext:''}); |
---|
879 | jsx3.sleep(function() { this.explanations.focusCellById(id,"jsxtext"); },"focusCell",this,true); |
---|
880 | this.changed(); |
---|
881 | }; |
---|
882 | |
---|
883 | DCEditor_prototype.addIssue = function() { |
---|
884 | var id = jsx3.xml.CDF.getKey(); |
---|
885 | var rec = this.issues.insertRecord({jsxid:id,jsxtext:''}); |
---|
886 | jsx3.sleep(function() { this.issues.focusCellById(id,"jsxtext"); },"focusCell",this,true); |
---|
887 | this.changed(); |
---|
888 | }; |
---|
889 | |
---|
890 | DCEditor_prototype.addProfile = function() { |
---|
891 | var rec = this.profiles.insertRecord({jsxid:'profile-0',jsxtext:''}); |
---|
892 | jsx3.sleep(function() { this.profiles.focusCellById('profile-0',"jsxtext"); },"focusCell",this,true); |
---|
893 | this.changed(); |
---|
894 | this.profilesChanged(); |
---|
895 | }; |
---|
896 | |
---|
897 | DCEditor_prototype.addDataElementName = function() { |
---|
898 | var id = jsx3.xml.CDF.getKey(); |
---|
899 | var rec = this.dataElementNames.insertRecord({jsxid:id,jsxtext:'',source:''}); |
---|
900 | jsx3.sleep(function() { this.dataElementNames.focusCellById(id,"jsxtext"); },"focusCell",this,true); |
---|
901 | this.changed(); |
---|
902 | }; |
---|
903 | |
---|
904 | DCEditor_prototype.addConstraint = function() { |
---|
905 | var id = jsx3.xml.CDF.getKey(); |
---|
906 | var rec = this.constraints.insertRecord({jsxid:id,jsxtext:''}); |
---|
907 | jsx3.sleep(function() { this.constraints.focusCellById(id,"jsxtext"); },"focusCell",this,true); |
---|
908 | this.changed(); |
---|
909 | }; |
---|
910 | |
---|
911 | DCEditor_prototype.profilesChanged = function() { |
---|
912 | var profDoc = this.getProfiles(); |
---|
913 | org.isocat.gui.DCEditor.log.info("DCEditor.profilesChanged():profs["+profDoc+"]"); |
---|
914 | // update profile check |
---|
915 | var profs = profDoc.getRecordIds(); |
---|
916 | if (typeof(profs)=='undefined' || profs.length==0) { |
---|
917 | this.setCheck("profiles","none"); |
---|
918 | org.isocat.APP.alert("Profile membership","A data category should be a member of at least one profile!",null,"OK"); |
---|
919 | } else { |
---|
920 | this.setCheck("profiles","ok"); |
---|
921 | } |
---|
922 | // propagate changes to the ProfileValueDomainEditor |
---|
923 | this.valueDomain.setProfiles(profDoc,this.valueDomain.hasValues()); |
---|
924 | // trigger changed |
---|
925 | this.changed(); |
---|
926 | }; |
---|
927 | |
---|
928 | DCEditor_prototype.getProfiles = function() { |
---|
929 | var profs = this.profiles.getXML().cloneDocument(); |
---|
930 | org.isocat.gui.DCEditor.log.info("DCEditor.getProfiles(...):profs["+profs+"]"); |
---|
931 | profs = jsx3.xml.CDF.Document.wrap(profs); |
---|
932 | org.isocat.gui.DCEditor.log.info("DCEditor.getProfiles(...):profs["+profs+"]"); |
---|
933 | var recs = profs.getRecordIds(); |
---|
934 | org.isocat.gui.DCEditor.log.info("DCEditor.getProfiles(...):recs["+recs+"]"); |
---|
935 | for (var i = 0; i<recs.length; i++) { |
---|
936 | var rec = profs.getRecordNode(recs[i]); |
---|
937 | org.isocat.gui.DCEditor.log.info("DCEditor.getProfiles(...):rec["+i+"]["+recs[i]+"]["+rec+"]"); |
---|
938 | rec.setAttribute("jsxtext",this.profileMask.getRecord(recs[i]).jsxtext); |
---|
939 | org.isocat.gui.DCEditor.log.info("DCEditor.getProfiles(...):rec["+i+"]["+recs[i]+"]["+rec+"]"); |
---|
940 | } |
---|
941 | return profs; |
---|
942 | }; |
---|
943 | |
---|
944 | DCEditor_prototype.delValue = function(id) { |
---|
945 | // signal the linguistic sections |
---|
946 | var vid = id.replace(/.*-/,''); |
---|
947 | for (var langs = this.cdf.getXML().selectNodeIterator("//record[@jsxid='linguisticsections']/record/@jsxtext");langs.hasNext();) { |
---|
948 | var lang = langs.next().getValue(); |
---|
949 | var val = "lingsec-conceptualdomain-"+lang+"-value-"+vid; |
---|
950 | var rec = this.cdf.deleteRecord(val,false); |
---|
951 | if (rec != null) |
---|
952 | org.isocat.gui.DCEditor.log.info("value["+val+"] deleted from LS["+lang+"]"); |
---|
953 | } |
---|
954 | this.linguisticSectionLeft.delValue(vid); |
---|
955 | this.linguisticSectionRight.delValue(vid); |
---|
956 | }; |
---|
957 | |
---|
958 | DCEditor_prototype.getValues = function() { |
---|
959 | return this.valueDomain.getValues(); |
---|
960 | }; |
---|
961 | |
---|
962 | DCEditor_prototype.editIsA = function() { |
---|
963 | var list = org.isocat.APP.getRootBlock().loadAndCache("components/DCList.xml",true).controller; |
---|
964 | list.setSingleSelect(); |
---|
965 | if (this.isARecord != null) { |
---|
966 | var values = new Array(1); |
---|
967 | values[0] = this.isARecord.id; |
---|
968 | list.preselectValues(new jsx3.util.List(values)); |
---|
969 | } |
---|
970 | |
---|
971 | //check if the DC is member of the undecided/unavailable profile |
---|
972 | var q = null; |
---|
973 | if ((this.getProfiles().getRecord("profile-0")!=null) || (this.getProfiles().getRecord("profile--1")!=null)) { |
---|
974 | // any simple DC can be linked |
---|
975 | q = new org.isocat.data.Query(org.isocat.profile.user(),"simple",new Array()); |
---|
976 | org.isocat.gui.DCEditor.log.info("DCEditor.editIsA():query for any simple DC"); |
---|
977 | } else { |
---|
978 | // only simple DCs from the selected profiles can be linked |
---|
979 | q = new org.isocat.data.Query(org.isocat.profile.user(),"simple",this.getProfiles().getRecordIds()); |
---|
980 | org.isocat.gui.DCEditor.log.info("EDEditor.editIsA():query for simple DCs belonging to selected profiles"); |
---|
981 | } |
---|
982 | |
---|
983 | list.callback(this,this.setIsA); |
---|
984 | list.load(q); |
---|
985 | }; |
---|
986 | |
---|
987 | DCEditor_prototype.setIsA = function(values) { |
---|
988 | var dc = values.get(0); |
---|
989 | if (dc != null) { |
---|
990 | // need the following CDF record: @jsxid='is-a' @id=<id> @jsxtext=<name> @name=<name> identifier=<identifier> |
---|
991 | if (dc.getAttribute("id")!="0") { |
---|
992 | this.isARecord = {jsxid:"is-a",id:dc.getAttribute("id"),jsxtext:dc.getAttribute("name"),name:dc.getAttribute("name"),identifier:dc.getAttribute("identifier")}; |
---|
993 | this.updateIsA(); |
---|
994 | org.isocat.gui.DCEditor.log.info("simple DC ["+this+"] is a is ["+this.isARecord.id+","+this.isARecord.jsxtext+"]"); |
---|
995 | } else { |
---|
996 | this.deleteIsA(); |
---|
997 | } |
---|
998 | } |
---|
999 | return true; |
---|
1000 | }; |
---|
1001 | |
---|
1002 | DCEditor_prototype.deleteIsA = function() { |
---|
1003 | this.isARecord = null; |
---|
1004 | this.updateIsA(); |
---|
1005 | org.isocat.gui.DCEditor.log.info("simple DC ["+this+"] is a set to none"); |
---|
1006 | this.changed(); |
---|
1007 | }; |
---|
1008 | |
---|
1009 | DCEditor_prototype.updateIsA = function() { |
---|
1010 | var text="<i>none</i>"; |
---|
1011 | if (this.isARecord != null) { |
---|
1012 | var text = "/"+this.isARecord.identifier+"/"; |
---|
1013 | if (this.isARecord.identifier != this.isARecord.name) |
---|
1014 | text += " ("+this.isARecord.name+")"; |
---|
1015 | } |
---|
1016 | this.isA.setText(text,true); |
---|
1017 | this.changed(); |
---|
1018 | }; |
---|
1019 | |
---|
1020 | DCEditor_prototype.changed = function() { |
---|
1021 | this.change = true; |
---|
1022 | this.setTitle(); |
---|
1023 | this.canSave(true); |
---|
1024 | this.canCheck(false); |
---|
1025 | }; |
---|
1026 | |
---|
1027 | DCEditor_prototype.changedType = function() { |
---|
1028 | var type = this.type.getValue(); |
---|
1029 | this.changed(); |
---|
1030 | this.setDCType(type); |
---|
1031 | |
---|
1032 | org.isocat.gui.DCEditor.log.info("DCEditor: old type["+this.DCType+"] new type["+type+"]"); |
---|
1033 | |
---|
1034 | var icon = this.typeChangeInfo.getChild("image"); |
---|
1035 | var text = this.typeChangeInfo.getChild("label"); |
---|
1036 | if (this.DCType != type) { |
---|
1037 | if (this.DCType=='closed') { |
---|
1038 | this.typeChangeInfo.setVisibility(jsx3.gui.Block.VISIBILITYVISIBLE,true); |
---|
1039 | icon.setSrc("http://isocat:8080/Tango/16x16/status/dialog-warning.png"); |
---|
1040 | icon.repaint(); |
---|
1041 | text.setText("value domains will be deleted",true); |
---|
1042 | } else if (this.DCType=='constrained') { |
---|
1043 | this.typeChangeInfo.setVisibility(jsx3.gui.Block.VISIBILITYVISIBLE,true); |
---|
1044 | icon.setSrc("http://isocat:8080/Tango/16x16/status/dialog-warning.png"); |
---|
1045 | icon.repaint(); |
---|
1046 | text.setText("constraints will be deleted",true); |
---|
1047 | } else if (this.DCType=='simple') { |
---|
1048 | this.typeChangeInfo.setVisibility(jsx3.gui.Block.VISIBILITYVISIBLE,true); |
---|
1049 | icon.setSrc("http://isocat:8080/Tango/16x16/status/dialog-warning.png"); |
---|
1050 | icon.repaint(); |
---|
1051 | text.setText("value domain relationships will be deleted",true); |
---|
1052 | } else { |
---|
1053 | this.typeChangeInfo.setVisibility(jsx3.gui.Block.VISIBILITYHIDDEN,true); |
---|
1054 | } |
---|
1055 | } else { |
---|
1056 | this.typeChangeInfo.setVisibility(jsx3.gui.Block.VISIBILITYHIDDEN,true); |
---|
1057 | } |
---|
1058 | }; |
---|
1059 | |
---|
1060 | DCEditor_prototype.setDCType = function(type) { |
---|
1061 | if (this.DCType == null) |
---|
1062 | this.DCType = type; |
---|
1063 | if (type == 'container') { |
---|
1064 | org.isocat.gui.DCEditor.log.info("container DC"); |
---|
1065 | this.simpleComplexTabs.setSelectedIndex(2,true); |
---|
1066 | } else if (type == 'simple') { |
---|
1067 | org.isocat.gui.DCEditor.log.info("simple DC"); |
---|
1068 | this.simpleComplexTabs.setSelectedIndex(0,true); |
---|
1069 | } else { |
---|
1070 | this.simpleComplexTabs.setSelectedIndex(1,true); |
---|
1071 | org.isocat.gui.DCEditor.log.info("complex DC"); |
---|
1072 | if (type == 'open') { |
---|
1073 | this.closedConstrainedTabs.setVisibility(jsx3.gui.Block.VISIBILITYHIDDEN,true); |
---|
1074 | org.isocat.gui.DCEditor.log.info("open complex DC"); |
---|
1075 | } else { |
---|
1076 | this.closedConstrainedTabs.setVisibility(jsx3.gui.Block.VISIBILITYVISIBLE,true); |
---|
1077 | if (type == 'closed') { |
---|
1078 | this.closedConstrainedTabs.setSelectedIndex(0,true); |
---|
1079 | org.isocat.gui.DCEditor.log.info("closed complex DC"); |
---|
1080 | } else { |
---|
1081 | this.closedConstrainedTabs.setSelectedIndex(1,true); |
---|
1082 | org.isocat.gui.DCEditor.log.info("constrained complex DC"); |
---|
1083 | } |
---|
1084 | } |
---|
1085 | } |
---|
1086 | this.linguisticSectionLeft.setDCType(type); |
---|
1087 | this.linguisticSectionRight.setDCType(type); |
---|
1088 | }; |
---|
1089 | |
---|
1090 | DCEditor_prototype.canSave = function(enable) { |
---|
1091 | org.isocat.gui.DCEditor.log.info("DCEditor.canSave("+enable+")"); |
---|
1092 | if (enable) { |
---|
1093 | if (this.identifier.getValue()=='') { |
---|
1094 | org.isocat.gui.DCEditor.log.info("DCEditor.canSave(...):empty identifier"); |
---|
1095 | enable = false; |
---|
1096 | } |
---|
1097 | if (this.type.getValue()=='') { |
---|
1098 | org.isocat.gui.DCEditor.log.info("DCEditor.canSave(...):empty type"); |
---|
1099 | enable = false; |
---|
1100 | } |
---|
1101 | if (this.anyError()) { |
---|
1102 | org.isocat.gui.DCEditor.log.info("DCEditor.canSave(...):some error"); |
---|
1103 | enable = false; |
---|
1104 | } |
---|
1105 | } |
---|
1106 | org.isocat.gui.DCEditor.log.info("DCEditor.canSave(...):enable["+enable+"]"); |
---|
1107 | |
---|
1108 | if (enable) { |
---|
1109 | this.saveButtonMenu.setEnabled(jsx3.gui.Form.STATEENABLED,true); |
---|
1110 | this.saveButtonWizard.setEnabled(jsx3.gui.Form.STATEENABLED,true); |
---|
1111 | } else { |
---|
1112 | this.saveButtonMenu.setEnabled(jsx3.gui.Form.STATEDISABLED,true); |
---|
1113 | this.saveButtonWizard.setEnabled(jsx3.gui.Form.STATEDISABLED,true); |
---|
1114 | } |
---|
1115 | }; |
---|
1116 | |
---|
1117 | DCEditor_prototype.canCheck = function(enable) { |
---|
1118 | if (enable) { |
---|
1119 | this.checkButton.setEnabled(jsx3.gui.Form.STATEENABLED,true); |
---|
1120 | } else { |
---|
1121 | this.checkButton.setEnabled(jsx3.gui.Form.STATEDISABLED,true); |
---|
1122 | } |
---|
1123 | }; |
---|
1124 | |
---|
1125 | DCEditor_prototype.checkIdentifier = function() { |
---|
1126 | var icon = this.identifierCheckInfo.getChild("image"); |
---|
1127 | var text = this.identifierCheckInfo.getChild("label"); |
---|
1128 | icon.setSrc("http://isocat:8080/famfamfam/silk/icons/hourglass.png"); |
---|
1129 | icon.repaint(); |
---|
1130 | text.setText("checking ...",true); |
---|
1131 | this.identifierCheckInfo.setVisibility(jsx3.gui.Block.VISIBILITYVISIBLE,true); |
---|
1132 | this.identifier.setEnabled(jsx3.gui.Form.STATEDISABLED,true); |
---|
1133 | this.canSave(false); |
---|
1134 | if (org.isocat.trim(this.identifier.getValue())!='') { |
---|
1135 | var url = "http://isocat:8080/isocat/rest/user/"+escape(org.isocat.profile.user())+"/search.xml?fields=identifier&scope=both&keywords="+escape(this.identifier.getValue()); |
---|
1136 | org.isocat.asyncLoadDocument(url,null,this,this.checkedIdentifier); |
---|
1137 | this.setCheck("identifier","checking"); |
---|
1138 | } else { |
---|
1139 | org.isocat.gui.DCEditor.log.info("identifier is empty"); |
---|
1140 | icon.setSrc("http://isocat:8080/Tango/16x16/status/dialog-error.png"); |
---|
1141 | icon.repaint(); |
---|
1142 | text.setText("identifier is empty",true); |
---|
1143 | this.setCheck("identifier","empty"); |
---|
1144 | } |
---|
1145 | }; |
---|
1146 | |
---|
1147 | DCEditor_prototype.checkedIdentifier = function(doc,req) { |
---|
1148 | this.identifier.setEnabled(jsx3.gui.Form.STATEENABLED,true); |
---|
1149 | var icon = this.identifierCheckInfo.getChild("image"); |
---|
1150 | var text = this.identifierCheckInfo.getChild("label"); |
---|
1151 | if (doc != null) { |
---|
1152 | org.isocat.gui.DCEditor.log.info("checked identifier["+doc+"]."); |
---|
1153 | var cid = 0; |
---|
1154 | if (typeof(this.dc)!='undefined') |
---|
1155 | cid = this.dc.id; |
---|
1156 | var uid = org.isocat.profile.id(); |
---|
1157 | if (typeof(this.dc)!='undefined') |
---|
1158 | uid = this.dc.owner_id; |
---|
1159 | // find DCs with the same name (owned by the logged in user) |
---|
1160 | var xp = "//dc[identifier='"+this.identifier.getValue()+"'][owner/@id="+uid+"]"; |
---|
1161 | var ids = doc.selectNodes(xp); |
---|
1162 | org.isocat.gui.DCEditor.log.info("found ids["+ids.size()+"]."); |
---|
1163 | if (ids.size()==0) { |
---|
1164 | // doesn't exist yet |
---|
1165 | org.isocat.gui.DCEditor.log.info("owner/identifier combo doesn't exist yet"); |
---|
1166 | icon.setSrc("http://isocat:8080/famfamfam/silk/icons/tick.png"); |
---|
1167 | icon.repaint(); |
---|
1168 | text.setText("",true); |
---|
1169 | this.setCheck("identifier","ok"); |
---|
1170 | this.canSave(true); |
---|
1171 | // if there are public (TODO: shared) matches suggest those |
---|
1172 | xp = "//dc[identifier='"+this.identifier.getValue()+"'][scope='public']"; |
---|
1173 | ids = doc.selectNodes(xp); |
---|
1174 | if (ids.size()==1) { |
---|
1175 | var dup = doc.selectSingleNode(xp); |
---|
1176 | var msg = "Maybe this data category already exists. Can it be this public one?"; |
---|
1177 | msg += "<p>"; |
---|
1178 | msg += '<a href="#" onclick="javascript:org.isocat.showDataCategoryInWindow(\''+dup.selectSingleNode("id").getValue()+'\')">'+dup.selectSingleNode("name").getValue()+'</a>'; |
---|
1179 | msg += "</p>"; |
---|
1180 | org.isocat.APP.alert("Data Category suggestion",msg,null,"Close",{nonModal:true}); |
---|
1181 | } else if (ids.size()>1) { |
---|
1182 | var msg = "Maybe this data category already exists. Can it be one of those, which are public available?"; |
---|
1183 | msg += "<ol>"; |
---|
1184 | for (var iter = ids.iterator();iter.hasNext();) { |
---|
1185 | var dup = iter.next(); |
---|
1186 | msg += '<li><a href="#" onclick="javascript:org.isocat.showDataCategoryInWindow(\''+dup.selectSingleNode("id").getValue()+'\')">'+dup.selectSingleNode("name").getValue()+'</a></li>'; |
---|
1187 | } |
---|
1188 | msg += "</ol>"; |
---|
1189 | org.isocat.APP.alert("Data Category suggestions",msg,null,"Close",{nonModal:true}); |
---|
1190 | } else if (ids.size()==0) { |
---|
1191 | // check if the identifier is a valid local QName |
---|
1192 | var xml = "<"+this.identifier.getValue()+"/>"; |
---|
1193 | var xdoc = new jsx3.xml.Document(); |
---|
1194 | xdoc.loadXML(xml); |
---|
1195 | var err = xdoc.getError(); |
---|
1196 | if (err.code != 0) { |
---|
1197 | org.isocat.gui.DCEditor.log.info("XML check failed for identifier: "+err.description); |
---|
1198 | icon.setSrc("http://isocat:8080/Tango/16x16/status/dialog-error.png"); |
---|
1199 | icon.repaint(); |
---|
1200 | text.setText("identifier is invalid",true); |
---|
1201 | this.setCheck("identifier","invalid XML"); |
---|
1202 | this.canSave(false); |
---|
1203 | org.isocat.APP.alert("This identifier is invalid","An identifier should be a valid local part of a qualified name as specified in the XML standard! This means, for example, that it isn't allowed to start with a number or to contain any spaces. You won't be able to save this (new) data category.",null,"OK"); |
---|
1204 | } |
---|
1205 | } |
---|
1206 | } else { |
---|
1207 | // check if this DC is in the set |
---|
1208 | var member = false; |
---|
1209 | for (var iter = ids.iterator();iter.hasNext();) { |
---|
1210 | if (iter.next().selectSingleNode("id").getValue() == cid) { |
---|
1211 | member = true; |
---|
1212 | break; |
---|
1213 | } |
---|
1214 | } |
---|
1215 | if (!member) { |
---|
1216 | org.isocat.gui.DCEditor.log.info("owner/identifier combo does exist already"); |
---|
1217 | icon.setSrc("http://isocat:8080/Tango/16x16/status/dialog-warning.png"); |
---|
1218 | icon.repaint(); |
---|
1219 | text.setText("identifier already in use",true); |
---|
1220 | var msg = "The registry already contains " + (ids.size()==1?"a data category":"data categories") +" with this identifier and owned by you:"; |
---|
1221 | msg += "<ol>"; |
---|
1222 | for (var iter = ids.iterator();iter.hasNext();) { |
---|
1223 | var dup = iter.next(); |
---|
1224 | msg += '<li><a href="#" onclick="javascript:org.isocat.showDataCategoryInWindow(\''+dup.selectSingleNode("id").getValue()+'\')">'+dup.selectSingleNode("name").getValue()+'</a></li>'; |
---|
1225 | } |
---|
1226 | msg += "</ol>"; |
---|
1227 | org.isocat.APP.alert("Data Category is known",msg,null,"OK",{nonModal:true}); |
---|
1228 | this.setCheck("identifier","ok"); |
---|
1229 | this.canSave(true); |
---|
1230 | } else { |
---|
1231 | org.isocat.gui.DCEditor.log.info("found dc.id["+cid+"]"); |
---|
1232 | icon.setSrc("http://isocat:8080/famfamfam/silk/icons/tick.png"); |
---|
1233 | icon.repaint(); |
---|
1234 | text.setText("",true); |
---|
1235 | this.setCheck("identifier","ok"); |
---|
1236 | this.canSave(true); |
---|
1237 | } |
---|
1238 | } |
---|
1239 | } else { |
---|
1240 | org.isocat.gui.DCEditor.log.info("failed to check identifier"); |
---|
1241 | icon.setSrc("http://isocat:8080/Tango/16x16/status/dialog-error.png"); |
---|
1242 | icon.repaint(); |
---|
1243 | text.setText("couldn't validate the indentifier",true); |
---|
1244 | this.setCheck("identifier","failed"); |
---|
1245 | this.canSave(false); |
---|
1246 | org.isocat.APP.alert("Error validating identifier","An error occurred while validating the identifier! You won't be able to save this new data category. Please contact the system administrator.",null,"OK"); |
---|
1247 | } |
---|
1248 | }; |
---|
1249 | |
---|
1250 | DCEditor_prototype.checkConstraint = function(matrix,id,col,value) { |
---|
1251 | var res = true; |
---|
1252 | |
---|
1253 | var attr = col.getPath(); |
---|
1254 | org.isocat.gui.DCEditor.log.info("column["+attr+"]"); |
---|
1255 | |
---|
1256 | var session = null; |
---|
1257 | if (id=="jsxautorow") { |
---|
1258 | session = matrix.getAutoRowSession(); |
---|
1259 | org.isocat.gui.DCEditor.log.info("autorow["+session+"]"); |
---|
1260 | } else { |
---|
1261 | session = matrix.getRecord(id); |
---|
1262 | org.isocat.gui.DCEditor.log.info("rec["+session+"]"); |
---|
1263 | } |
---|
1264 | |
---|
1265 | var rtype = session["rule-type"]; |
---|
1266 | var rule = session["jsxtext"]; |
---|
1267 | if (attr == "rule-type") |
---|
1268 | rtype = value; |
---|
1269 | if (attr == "jsxtext") |
---|
1270 | rule = value; |
---|
1271 | org.isocat.gui.DCEditor.log.info("rule-type["+rtype+"] rule["+rule+"]"); |
---|
1272 | |
---|
1273 | if ((attr == "jsxtext") || (attr == "rule-type")) { // only check when the rule type or the rule changed |
---|
1274 | if ((typeof(rtype)!='undefined') && (typeof(rule)!='undefined')) { |
---|
1275 | var rid = this.ruleTypeMask.getXML().selectSingleNode("//record[@jsxtext='"+rtype+"']/@jsxid").getValue(); |
---|
1276 | var rec = this.ruleTypeMask.getRecord(rid); |
---|
1277 | org.isocat.gui.DCEditor.log.info("rule-type["+rtype+"] needs XML["+(rec.xml=='true')+"]"); |
---|
1278 | |
---|
1279 | if (rec.xml=='true') { |
---|
1280 | var xdoc = new jsx3.xml.Document(); |
---|
1281 | xdoc.loadXML(rule); |
---|
1282 | var err = xdoc.getError(); |
---|
1283 | if (err.code != 0) { |
---|
1284 | res = false; |
---|
1285 | org.isocat.gui.DCEditor.log.info("XML check failed for rule["+rule+"]: "+err.description); |
---|
1286 | org.isocat.APP.alert("This rule is invalid","A rule of type '"+rtype+"' needs to be wellformed XML! The XML parser reported the following error: <p>"+err.description+"</p> Due to this error you won't be able to save this (new) data category.",null,"OK"); |
---|
1287 | this.setCheck("constraint-"+session["jsxid"],"invalid-XML"); |
---|
1288 | } else { |
---|
1289 | org.isocat.gui.DCEditor.log.info("XML check succeeded for rule["+rule+"]"); |
---|
1290 | this.setCheck("constraint-"+session["jsxid"],"ok"); |
---|
1291 | } |
---|
1292 | } else |
---|
1293 | this.setCheck("constraint-"+session["jsxid"],"ok"); // free text constraints are always ok |
---|
1294 | } |
---|
1295 | } |
---|
1296 | |
---|
1297 | this.canSave(res); |
---|
1298 | return res; |
---|
1299 | }; |
---|
1300 | |
---|
1301 | DCEditor_prototype.setCheck = function(id,status) { |
---|
1302 | this.checks[id] = status; |
---|
1303 | org.isocat.gui.DCEditor.log.info("check["+id+"]:"+this.checks[id]); |
---|
1304 | }; |
---|
1305 | |
---|
1306 | DCEditor_prototype.anyError = function() { |
---|
1307 | var res = false; |
---|
1308 | for (check in this.checks) { |
---|
1309 | if (this.checks[check] != "ok") { |
---|
1310 | org.isocat.gui.DCEditor.log.info("check error["+check+"]:"+this.checks[check]); |
---|
1311 | res = true; |
---|
1312 | //break; |
---|
1313 | } |
---|
1314 | } |
---|
1315 | return res; |
---|
1316 | }; |
---|
1317 | |
---|
1318 | DCEditor_prototype.save = function() { |
---|
1319 | var saveDC = org.isocat.APP.getRootBlock().loadAndCache("components/SaveDC.xml",true); |
---|
1320 | if (typeof(this.dc) == 'undefined') |
---|
1321 | saveDC.controller.setType("CREATE"); |
---|
1322 | saveDC.controller.callback(this,this._save); |
---|
1323 | saveDC.repaint(); |
---|
1324 | saveDC.controller.focus(); |
---|
1325 | }; |
---|
1326 | |
---|
1327 | DCEditor_prototype._save = function(change) { |
---|
1328 | this.cdf.write(); |
---|
1329 | org.isocat.gui.DCEditor.log.info("Synced CDF source with cache["+this.cacheId()+"]."); |
---|
1330 | |
---|
1331 | //assemble the complete CDF document again |
---|
1332 | var cdfDoc = this.cdf.getXML(); |
---|
1333 | org.isocat.replaceSubCDFDocument(cdfDoc,"admin","explanations",this.explanations.getXML(),true); |
---|
1334 | org.isocat.replaceSubCDFDocument(cdfDoc,"admin","issues",this.issues.getXML(),true); |
---|
1335 | org.isocat.replaceSubCDFDocument(cdfDoc,"descr","profiles",this.getProfiles(),true); |
---|
1336 | org.isocat.replaceSubCDFDocument(cdfDoc,"descr","datanames",this.dataElementNames.getXML(),true); |
---|
1337 | |
---|
1338 | // save active language sections |
---|
1339 | this.languageSectionLeft.save(false); |
---|
1340 | this.languageSectionRight.save(false); |
---|
1341 | |
---|
1342 | // save conceptual domain |
---|
1343 | var type = this.type.getValue() |
---|
1344 | if (type != 'simple') { |
---|
1345 | if (type == 'closed') { |
---|
1346 | org.isocat.replaceSubCDFDocument(cdfDoc,"dc-"+(typeof(this.dc) == 'undefined'?0:this.dc.id),"conceptualdomain",this.valueDomain.getValues(),true); |
---|
1347 | } else if (type == 'constrained') { |
---|
1348 | org.isocat.replaceSubCDFDocument(cdfDoc,"dc-"+(typeof(this.dc) == 'undefined'?0:this.dc.id),"conceptualdomain",this.constraints.getXML(),true); |
---|
1349 | } |
---|
1350 | var cd = cdfDoc.getRecordNode("conceptualdomain"); |
---|
1351 | cd.setAttribute("type",type); |
---|
1352 | cd.setAttribute("datatype",this.datatypes.getRecord(this.datatypes.getValue()).jsxtext); |
---|
1353 | cd.setAttribute("datatype-id",this.datatypes.getValue()); |
---|
1354 | } |
---|
1355 | |
---|
1356 | // save the simple DC isA relation |
---|
1357 | if (this.isARecord != null) { |
---|
1358 | cdfDoc.insertRecord(this.isARecord,"dc-"+(typeof(this.dc) == 'undefined'?0:this.dc.id)); |
---|
1359 | } else { |
---|
1360 | // remove any existing isA record in the CDF doc |
---|
1361 | cdfDoc.deleteRecord("is-a"); |
---|
1362 | } |
---|
1363 | |
---|
1364 | // save active language sections |
---|
1365 | this.linguisticSectionLeft.save(false); |
---|
1366 | this.linguisticSectionRight.save(false); |
---|
1367 | |
---|
1368 | // get the change document |
---|
1369 | var changes = org.isocat.createSubCDFDocument(cdfDoc,"changes",true); |
---|
1370 | changes.insertRecord({jsxid:jsx3.xml.CDF.getKey(), jsxtext:change}); |
---|
1371 | org.isocat.replaceSubCDFDocument(cdfDoc,"admin","changes",changes,true); |
---|
1372 | |
---|
1373 | // remove all autorow records |
---|
1374 | var autorow = null; |
---|
1375 | do { |
---|
1376 | autorow = cdfDoc.deleteRecord("jsxautorow"); |
---|
1377 | } while (autorow != null); |
---|
1378 | |
---|
1379 | // convert the CDF document to DCIF |
---|
1380 | var dcifDoc = org.isocat.transformXML(cdfDoc,"CDF2DC_xsl"); |
---|
1381 | if (dcifDoc == null) { |
---|
1382 | org.isocat.gui.DCEditor.log.info("org.isocat.gui.DCEditor.save("+this.cacheId()+"):failed to transform!"); |
---|
1383 | org.isocat.APP.alert("Saving the Data Category failed","The DC couldn't be saved! Contact the ISOcat system administrator.",null,"OK"); |
---|
1384 | this.canSave(false); |
---|
1385 | return; |
---|
1386 | } |
---|
1387 | |
---|
1388 | var uri = "http://isocat:8080/isocat/rest"; |
---|
1389 | if (typeof(this.dc) == 'undefined') { |
---|
1390 | uri += "/dc"; |
---|
1391 | } else { |
---|
1392 | uri += "/user/"+escape(org.isocat.profile.user()); |
---|
1393 | uri += "/session/"+escape(org.isocat.profile.session().id); |
---|
1394 | uri += "/lock/"+escape(this.lock.id); |
---|
1395 | uri += "/dc/"+escape(this.dc.id); |
---|
1396 | } |
---|
1397 | |
---|
1398 | var method = "POST"; |
---|
1399 | if (typeof(this.dc) == 'undefined') |
---|
1400 | method = "PUT"; |
---|
1401 | |
---|
1402 | org.isocat.gui.DCEditor.log.info("accessing service uri["+uri+"]["+method+"]["+dcifDoc+"]"); |
---|
1403 | |
---|
1404 | //var req = new jsx3.net.Request().open(method,uri,false,org.isocat.profile.user(),org.isocat.profile.pass()); |
---|
1405 | var req = new jsx3.net.Request().open(method,uri,false); |
---|
1406 | req.setRequestHeader("Content-Type","application/xml");// IE doesn't set this automagically (FF does), and otherwise NK won't pass it on to the ISOcat accessors |
---|
1407 | req.setRequestHeader("Accept","application/x-dcif+xml");// we want the DCIF of the updated/new DC |
---|
1408 | req.send(dcifDoc.toString()); |
---|
1409 | |
---|
1410 | var status = req.getStatus(); |
---|
1411 | org.isocat.gui.DCEditor.log.info("service uri["+uri+"]["+method+"] returned HTTP status["+status+"]"); |
---|
1412 | |
---|
1413 | if ((status==200) || (status==201)) { |
---|
1414 | org.isocat.gui.DCEditor.log.info("service uri["+uri+"]["+method+"]["+status+"] response["+req.getResponseText()+"]"); |
---|
1415 | var dcifDoc = new jsx3.xml.Document(); |
---|
1416 | dcifDoc.loadXML(req.getResponseText()); |
---|
1417 | //org.isocat.gui.DCEditor.log.info("DC["+dcifDoc+"]"); |
---|
1418 | //var id = dcifDoc.selectSingleNode("/dcif:dataCategorySelection/dcif:dataCategory/@isocat:id",{dcif:'http://www.isocat.org/ns/dcif', isocat:'http://www.isocat.org/'}).getValue(); ... results in 'Multiple colons are not allowed in a name' error in IE |
---|
1419 | var id = null; |
---|
1420 | for (var iter = dcifDoc.getChildIterator();iter.hasNext();) { |
---|
1421 | var node = iter.next(); |
---|
1422 | if (node.getBaseName() == 'dataCategory') { |
---|
1423 | id = node.getAttribute("isocat:id"); |
---|
1424 | } |
---|
1425 | } |
---|
1426 | if (id==null) |
---|
1427 | org.isocat.APP.alert("Error","Sorry, the identity of this DC can't be determined! Please contact the ISOcat system administrator.",null,"OK") |
---|
1428 | |
---|
1429 | org.isocat.gui.DCEditor.log.info("DC["+dcifDoc+"]["+id+"]"); |
---|
1430 | |
---|
1431 | if (typeof(this.dc) == 'undefined') { |
---|
1432 | // the DC now exists and has an id |
---|
1433 | this.dc = {id:id}; |
---|
1434 | // and we now need a lock on it |
---|
1435 | if (!this.lockDataCategory()) |
---|
1436 | this.close(); // this should be almost impossible ... the owner would have to quickly lock it in another browser window |
---|
1437 | // also rename the window |
---|
1438 | if (this.window != null) |
---|
1439 | this.window.setName("window-edit-DC-"+this.dc.id); |
---|
1440 | // ask if we need to add it to the basket |
---|
1441 | var view = this.view; |
---|
1442 | if (this.addToBasket) { |
---|
1443 | this.basket(); |
---|
1444 | } else { |
---|
1445 | org.isocat.APP.confirm("Add to basket","Add this new Data Category to the basket?", |
---|
1446 | function(dialog) { |
---|
1447 | jsx3.GO(view.getId()).controller.basket(dialog); |
---|
1448 | }, |
---|
1449 | null,"Yes","No",1); |
---|
1450 | } |
---|
1451 | } |
---|
1452 | |
---|
1453 | // disable the type field, it can't be changed anymore |
---|
1454 | //this.type.setEnabled(jsx3.gui.Form.STATEDISABLED,true); |
---|
1455 | |
---|
1456 | // convert the DCIF document to CDF |
---|
1457 | var cdfDoc = org.isocat.transformXML(dcifDoc,"DC2CDF_xsl"); |
---|
1458 | cdfDoc = jsx3.xml.CDF.Document.wrap(cdfDoc); |
---|
1459 | cdfDoc.convertProperties(org.isocat.APP.getProperties()); |
---|
1460 | |
---|
1461 | // update the cached doc |
---|
1462 | org.isocat.APP.getCache().setDocument(this.cacheId(),cdfDoc); |
---|
1463 | |
---|
1464 | // reload the form with the DCIF so we get all ids at the right places ... TODO: prevent that this resets all kind of UI elements ... |
---|
1465 | this.update(); |
---|
1466 | |
---|
1467 | // now we can check the DC |
---|
1468 | this.canCheck(true); |
---|
1469 | if (this.checkButton.getState()==jsx3.gui.ToolbarButton.STATEON) { |
---|
1470 | this.check(true); |
---|
1471 | org.isocat.gui.DCEditor.log.info("rechecked the DC"); |
---|
1472 | } else { |
---|
1473 | org.isocat.gui.DCEditor.log.info("skipped rechecking the DC"); |
---|
1474 | } |
---|
1475 | |
---|
1476 | // tell all listeners this DC is updated |
---|
1477 | org.isocat.publish("org.isocat.DC.reload",this.dc.id); |
---|
1478 | } else if (status==403) { |
---|
1479 | org.isocat.APP.alert("Failed to save the DC","Sorry, you lost your edit lock on this DC.",null,"OK") |
---|
1480 | org.isocat.gui.DCEditor.log.info("failed to save the DC["+org.isocat.profile.user()+"]["+this.identifier.getValue()+"]:status["+status+"]"); |
---|
1481 | } else if (status==409) { |
---|
1482 | org.isocat.APP.alert("Failed to save the DC","Sorry, this DC already exists so the save failed.",null,"OK") |
---|
1483 | org.isocat.gui.DCEditor.log.info("failed to save the DC["+org.isocat.profile.user()+"]["+this.identifier.getValue()+"]:status["+status+"]"); |
---|
1484 | } else { |
---|
1485 | org.isocat.APP.alert("Failed to save the DC","Sorry, an error occurred on the server and the DC couldn't be saved.",null,"OK") |
---|
1486 | org.isocat.gui.DCEditor.log.info("failed to save the DC["+org.isocat.profile.user()+"]["+this.identifier.getValue()+"]:status["+status+"]"); |
---|
1487 | } |
---|
1488 | |
---|
1489 | this.canSave(false); |
---|
1490 | this.setTitle(); |
---|
1491 | return true; |
---|
1492 | }; |
---|
1493 | |
---|
1494 | DCEditor_prototype.basket = function(dialog) { |
---|
1495 | var dc = org.isocat.data.DC.load(this.dc.id); |
---|
1496 | org.isocat.addToBasket(dc); |
---|
1497 | if (typeof(dialog)!='undefined') { |
---|
1498 | dialog.doClose(); |
---|
1499 | } |
---|
1500 | } |
---|
1501 | |
---|
1502 | DCEditor_prototype.cancel = function() { |
---|
1503 | if (this.window != null) { |
---|
1504 | var close = true; |
---|
1505 | var view = this.view; |
---|
1506 | if (this.change) { |
---|
1507 | org.isocat.APP.confirm("Close this DC Editor","There are unsaved changes! Do you really want to close this editor?", |
---|
1508 | function(dialog) { |
---|
1509 | jsx3.GO(view.getId()).controller.close(dialog); |
---|
1510 | }, |
---|
1511 | null,"Yes","No",2); |
---|
1512 | close=false; |
---|
1513 | } |
---|
1514 | if (close) |
---|
1515 | this.close(); |
---|
1516 | } |
---|
1517 | return close; |
---|
1518 | }; |
---|
1519 | |
---|
1520 | DCEditor_prototype.close = function(dialog) { |
---|
1521 | if (this.lock != null) { |
---|
1522 | org.isocat.profile.unlockDC(this.lock.id); |
---|
1523 | } |
---|
1524 | if (this.window != null) { |
---|
1525 | org.isocat.gui.DCEditor.log.info("this.window["+this.window+"].doClose() ..."); |
---|
1526 | this.window.doClose(); |
---|
1527 | org.isocat.gui.DCEditor.log.info("... done"); |
---|
1528 | } |
---|
1529 | if (typeof(dialog)!='undefined') { |
---|
1530 | dialog.doClose(); |
---|
1531 | } |
---|
1532 | } |
---|
1533 | |
---|
1534 | DCEditor_prototype.check = function(show) { |
---|
1535 | if (show) { |
---|
1536 | // show the check result view |
---|
1537 | if (this.viewSplitter.getSubcontainer1Pct() == "100") { |
---|
1538 | this.viewSplitter.setSubcontainer1Pct("80",true); |
---|
1539 | } |
---|
1540 | |
---|
1541 | // load the loading overlay |
---|
1542 | org.isocat.gui.Loading.load(this.checkView,"Checking ...").show(); |
---|
1543 | |
---|
1544 | // request the check |
---|
1545 | var uri = "http://isocat:8080/isocat/rest/dc/"+this.dc.id+"/check"; |
---|
1546 | org.isocat.asyncLoadDynamicCDFDocument(new jsx3.net.URI(uri),"Check2CDF_xsl",null,"check-dc-"+this.dc.id,this,this.checked); |
---|
1547 | } else { |
---|
1548 | // hide the check result view |
---|
1549 | if (this.viewSplitter.getSubcontainer1Pct() != "100") { |
---|
1550 | this.viewSplitter.setSubcontainer1Pct("100",true); |
---|
1551 | } |
---|
1552 | } |
---|
1553 | }; |
---|
1554 | |
---|
1555 | DCEditor_prototype.checked = function(doc,req) { |
---|
1556 | org.isocat.gui.Loading.load(this.checkView).hide(); |
---|
1557 | if (doc!=null) { |
---|
1558 | this.checkResult.setXMLId("check-dc-"+this.dc.id); |
---|
1559 | this.checkResult.repaintData(); |
---|
1560 | |
---|
1561 | // determine the check result |
---|
1562 | this.dc.check = req.getResponseXML().selectSingleNode('/check/@result').getValue(); |
---|
1563 | |
---|
1564 | // update the check icon |
---|
1565 | this.checkIcon(); |
---|
1566 | } else { |
---|
1567 | // hide the check result view |
---|
1568 | if (this.viewSplitter.getSubcontainer1Pct() != "100") { |
---|
1569 | this.viewSplitter.setSubcontainer1Pct("100",true); |
---|
1570 | } |
---|
1571 | org.isocat.gui.DCViewer.log.info("The DC check call failed. The HTTP Status code is: " + req.getStatus()); |
---|
1572 | org.isocat.APP.alert("DC checking failed","The DC couldn't be checked! Contact the ISOcat system administrator.",null,"OK"); |
---|
1573 | } |
---|
1574 | }; |
---|
1575 | |
---|
1576 | DCEditor_prototype.checkIcon = function() { |
---|
1577 | // set the correct check icon |
---|
1578 | if (typeof(this.dc.check)!='undefined') { |
---|
1579 | var prop = "icon: check "+this.dc.check; |
---|
1580 | if (org.isocat.APP.getProperties().containsKey(prop)) { |
---|
1581 | this.checkButton.setDynamicProperty("jsximage",prop,true) |
---|
1582 | this.checkButton.repaint(); |
---|
1583 | } |
---|
1584 | } |
---|
1585 | } |
---|
1586 | |
---|
1587 | DCEditor_prototype.setTitle = function() { |
---|
1588 | var title = "New Data Category"; |
---|
1589 | if (typeof(this.dc) != 'undefined') |
---|
1590 | title = this.dc.name + " - " + this.dc.version; |
---|
1591 | if (this.identifier.getValue() != '') |
---|
1592 | title = this.identifier.getValue() + " - " + this.version.getValue(); |
---|
1593 | |
---|
1594 | if (this.change) |
---|
1595 | title += " *"; |
---|
1596 | |
---|
1597 | org.isocat.gui.DCEditor.log.info("set DC editor title["+title+"]."); |
---|
1598 | |
---|
1599 | if (this.window != null) { |
---|
1600 | this.label.setText("",true); |
---|
1601 | this.window.getCaptionBar().setText(title,true); |
---|
1602 | //this.windowButton.setEnabled(jsx3.gui.Form.STATEDISABLED,true);; |
---|
1603 | } else { |
---|
1604 | this.label.setText(title,true); |
---|
1605 | //this.windowButton.setEnabled(jsx3.gui.Form.STATEENABLED,true);; |
---|
1606 | } |
---|
1607 | }; |
---|
1608 | |
---|
1609 | DCEditor_prototype.setWindow = function(window) { |
---|
1610 | this.window = window; |
---|
1611 | this.setTitle(); |
---|
1612 | this.cancelButtonWizard.setVisibility(jsx3.gui.Block.VISIBILITYVISIBLE,true); |
---|
1613 | var close = this.window.getDescendantOfName("btnClose"); |
---|
1614 | // remove existing close button listeners |
---|
1615 | close.unsubscribeAll(jsx3.gui.Interactive.EXECUTE); |
---|
1616 | close.setEvent("",jsx3.gui.Interactive.EXECUTE); |
---|
1617 | // register our own listener |
---|
1618 | close.subscribe(jsx3.gui.Interactive.EXECUTE,this,this.cancel); |
---|
1619 | }; |
---|
1620 | |
---|
1621 | DCEditor_prototype.focus = function() { |
---|
1622 | this.view.focus(); |
---|
1623 | |
---|
1624 | jsx3.sleep(function() { this.identifier.focus(); },"focusDCEditor",this,true); |
---|
1625 | org.isocat.gui.DCEditor.log.info("set DC editor focus to identifier field."); |
---|
1626 | |
---|
1627 | // delayed till everything is painted ... |
---|
1628 | this.setDCType(this.cdf.getXML().getRecord("admin").type); |
---|
1629 | }; |
---|
1630 | |
---|
1631 | DCEditor_prototype.focusDescrSection = function() { |
---|
1632 | //jsx3.sleep(function() { this.profiles.setValue(this.profiles.getSelectedIds()); },"revealSelectedProfile",this,true); |
---|
1633 | } |
---|
1634 | }); |
---|