1 | jsx3.util.Logger.getLogger("org.isocat").info("Loading class[org.isocat.gui.SaveDC]"); |
---|
2 | |
---|
3 | /** |
---|
4 | * The SaveDC controller |
---|
5 | * @author Menzo.Windhouwer@mpi.nl |
---|
6 | */ |
---|
7 | jsx3.lang.Class.defineClass("org.isocat.gui.SaveDC", null, [], function(SaveDC, SaveDC_prototype) { |
---|
8 | |
---|
9 | /** |
---|
10 | * The class logger |
---|
11 | */ |
---|
12 | SaveDC.log = jsx3.util.Logger.getLogger("org.isocat.gui.SaveDC"); |
---|
13 | |
---|
14 | /** |
---|
15 | * The root block of the component |
---|
16 | */ |
---|
17 | SaveDC_prototype.view; |
---|
18 | |
---|
19 | /** |
---|
20 | * The dialog title |
---|
21 | */ |
---|
22 | SaveDC_prototype.title; |
---|
23 | |
---|
24 | /** |
---|
25 | * The ok button |
---|
26 | */ |
---|
27 | SaveDC_prototype.okButton; |
---|
28 | |
---|
29 | /** |
---|
30 | * The DCS name field |
---|
31 | */ |
---|
32 | SaveDC_prototype.descField; |
---|
33 | |
---|
34 | /** |
---|
35 | * The callback function |
---|
36 | */ |
---|
37 | SaveDC_prototype.callbackFunc; |
---|
38 | |
---|
39 | /** |
---|
40 | * The help tabs |
---|
41 | */ |
---|
42 | SaveDC_prototype.help; |
---|
43 | |
---|
44 | /** |
---|
45 | * Constructor |
---|
46 | */ |
---|
47 | SaveDC_prototype.init = function(view) { |
---|
48 | org.isocat.gui.SaveDC.log.info("initialize SaveDC["+this+"]"); |
---|
49 | |
---|
50 | this.view = view; |
---|
51 | org.isocat.gui.SaveDC.log.info("- SaveDC view["+this.view+"]"); |
---|
52 | this.title = this.view.getDescendantOfName("windowBar") |
---|
53 | org.isocat.gui.SaveDC.log.info("- title["+this.title+"]"); |
---|
54 | this.okButton = this.view.getDescendantOfName("ok") |
---|
55 | org.isocat.gui.SaveDC.log.info("- ok button["+this.okButton+"]"); |
---|
56 | this.descField = this.view.getDescendantOfName("descField") |
---|
57 | org.isocat.gui.SaveDC.log.info("- description field["+this.descField+"]"); |
---|
58 | this.type = "SAVE"; |
---|
59 | org.isocat.gui.SaveDC.log.info("- type["+this.type+"]"); |
---|
60 | this.callbackCtxt = null; |
---|
61 | this.callbackFunc = null; |
---|
62 | org.isocat.gui.SaveDC.log.info("- callback["+this.callbackCtxt+"]["+this.callbackFunc+"]"); |
---|
63 | this.help = this.view.getDescendantOfName("help") |
---|
64 | org.isocat.gui.SaveDC.log.info("- help["+this.help+"]"); |
---|
65 | |
---|
66 | org.isocat.gui.SaveDC.log.info("initialized SaveDC["+this+"]"); |
---|
67 | |
---|
68 | this.view.controller = this; |
---|
69 | |
---|
70 | // publish the message using PageBus |
---|
71 | org.isocat.publish("org.isocat.gui.SaveDC.init", this); |
---|
72 | }; |
---|
73 | |
---|
74 | /** |
---|
75 | * Set focus to the first field |
---|
76 | */ |
---|
77 | SaveDC_prototype.focus = function() { |
---|
78 | this.view.focus(); |
---|
79 | // TIBCO hack: first the dialog needs to claim focus, then we can move the focus to the DCS name field, the sleep takes care of the delay |
---|
80 | jsx3.sleep(function() { this.descField.focus();},"focusSaveDC",this,true); |
---|
81 | }; |
---|
82 | |
---|
83 | /** |
---|
84 | * The actual save is requested |
---|
85 | */ |
---|
86 | SaveDC_prototype.save = function() { |
---|
87 | var res = false; |
---|
88 | if (this.type == "CREATE") { |
---|
89 | if (org.isocat.trim(this.descField.getValue())=='') { |
---|
90 | this.help.setSelectedIndex(2,true); |
---|
91 | this.descField.focus(); |
---|
92 | org.isocat.gui.SaveDC.log.info("invalid change description"); |
---|
93 | return res; |
---|
94 | } else |
---|
95 | org.isocat.gui.SaveDC.log.info("valid change description"); |
---|
96 | } |
---|
97 | |
---|
98 | if (this.callbackFunc != null) { |
---|
99 | org.isocat.gui.SaveDC.log.info("call save DC callback"); |
---|
100 | res = this.callbackFunc.call(this.callbackCtxt,this.descField.getValue()); |
---|
101 | } else |
---|
102 | res = true; |
---|
103 | |
---|
104 | org.isocat.gui.SaveDC.log.info("save DC["+res+"]"); |
---|
105 | return res; |
---|
106 | }; |
---|
107 | |
---|
108 | /** |
---|
109 | * Is this a first save? |
---|
110 | */ |
---|
111 | SaveDC_prototype.setType = function(type) { |
---|
112 | this.type = type; |
---|
113 | if (this.type == "CREATE") { |
---|
114 | this.help.setSelectedIndex(1,true); |
---|
115 | } |
---|
116 | }; |
---|
117 | |
---|
118 | /** |
---|
119 | * Set the callback function |
---|
120 | */ |
---|
121 | SaveDC_prototype.callback = function(ctxt,func) { |
---|
122 | this.callbackCtxt = ctxt; |
---|
123 | this.callbackFunc = func; |
---|
124 | }; |
---|
125 | |
---|
126 | }); |
---|