├── LICENSE
├── README.md
├── SimpleTable.js
├── Widget.html
├── Widget.js
├── config.json
├── css
└── style.css
├── help
├── Action_Delete.png
├── Action_Download.png
├── Action_Edit.png
├── Action_Load.png
├── Configure-icon.png
├── Configure.png
├── InstallFolder.png
├── LoadFromFile.png
├── SaveNewSession.png
├── SaveSessionPanel.png
├── SaveToFile.png
├── SessionsLoaded.png
└── icon.png
├── images
├── download_icon.png
├── download_icon_hover.png
└── icon.png
├── manifest.json
├── nls
└── strings.js
├── release.txt
└── setting
├── Setting.html
├── Setting.js
└── css
└── style.css
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "{}"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright {yyyy} {name of copyright owner}
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # SaveSession-Widget
2 | The SaveSession Widget for ArcGIS Web AppBuilder enables users to save the current map settings into a session and restore them again later. A saved session includes the extent, visible layers and annotations of the current map. Sessions may be saved and loaded from files so they can be shared with others.
3 |
4 | ##Using the Widget
5 | The SaveSession Widget is an in-panel widget that will be displayed in the toolbar of your WebApp Builder application. Click the  icon display the SaveSession panel.
6 |
7 | 
8 |
9 | ### Saving a Session
10 | Once you have the map just the way you want it - zoomed to the area and layers turned on, enter a name for the session and click the Save button. The session will be added to the Saved Sessions list.
11 |
12 | 
13 |
14 | ### Restoring a Session
15 | To return the map to the same state as when you saved the session, you can double-click the title of the session to load the map.
16 |
17 | ### Managing Sessions in the List
18 | Hover over the Actions column for a session entry to reveal the actions that can be performed on the entry.
19 |
20 | **Load Map** = will load the restore the selected session to the current map
21 |
22 | 
23 |
24 | **Download Map** = will save the session entry to a file that may be shared.
25 |
26 | 
27 |
28 | **Edit** = allows the user to change the session name
29 |
30 | 
31 |
32 | **Move Up - Down ** = lets you arrange the entries in the session list in the desired order
33 |
34 | **Delete** = click the Delete button to remove the entry from the list
35 |
36 | 
37 |
38 | ### Sharing Sessions
39 | Saved Sessions may be shared with other users or another browser on the same PC by saving the session to a file and then loading the session from the file into the session list.
40 |
41 | To save a single session to a file, click the Download Map action for the entry. To save all sessions in the list to a file, click the Save to file link.
42 |
43 | 
44 |
45 | To load the sessions from a file, click the Load from file link to display the Load sessions from file dialog
46 |
47 | 
48 |
49 | Click the Choose File button and select the file to load. The selected file must be a saved session file. All sessions from the file will be loaded. If a loaded session has the same name as an existing session, a number will be appended to the session to make the name unique.
50 |
51 | 
52 |
53 |
54 | ## Adding the Widget to the Web AppBuilder
55 | To add this widget to your ArcGIS WebApp Builder:
56 |
57 | * download the zip file of the widget
58 | * unzip the contents into client\stemapp\widgets\SaveSession directory
59 |
60 | 
61 |
62 | * edit the \client\stemapp\config.json and enter the SaveSession widget in the widgets entry
63 |
64 | Example:
65 |
66 | "widgets": [
67 | {
68 | "uri": "widgets/SaveSession/Widget"
69 | }
70 | ...
71 | ]
72 |
73 | ## Configuring the Widget
74 | Using the Web AppBuilder, click the edit icon on the SaveSession widget in the in-panel widgets to display the Configure Dialog.
75 |
76 | 
77 |
78 | 
79 |
80 | **Use Server To Download File** = All browsers support downloading a file from a server. Some browsers like Chrome or Edge can support downloading a file of data without a round trip to the server by using a data url. Visit [http://caniuse.com/#feat=download](http://caniuse.com/#feat=download) to see if your browser supports downloading from data urls. To enable downloading from a data url, uncheck the box. To enable downloading from a server side service, check the box and enter a Url for Save to File.
81 |
82 | **Url for Save To File** = the Url that will return a file for the given data. The SaveSession widget will post the data to the url and the web service should respond with the file as an attachment. This is only needed if Use Server To Download File is checked.
83 |
84 | **Filename for All Sessions** = the file name to use when the Save to File link is clicked.
85 |
86 | **Filename for 1 Session** = the file name to use when the Download action is used to save a single session to a file. Include the "{name}" placeholder that will be replaced with the session name at runtime.
87 |
88 | ##FAQ
89 | ###The Save to File link does not work?
90 | Visit [http://caniuse.com/#feat=download](http://caniuse.com/#feat=download) to see if your browser supports downloading from data urls. If not, then you'll need to enable the Use Server To Download File option and create a service that returns the session file as an attachment.
91 |
92 | *Note that a web service that downloads the session file is not included in the widget. It lives outside the widget on your own web server.*
93 |
94 | ##Sponsors
95 | **Thanks to the City of Garland, Texas for sponsoring the initial development of the SaveSession Widget and releasing it to the community.**
96 |
--------------------------------------------------------------------------------
/SimpleTable.js:
--------------------------------------------------------------------------------
1 | ///////////////////////////////////////////////////////////////////////////
2 | // Copyright © 2014 Esri. All Rights Reserved.
3 | //
4 | // Licensed under the Apache License Version 2.0 (the "License");
5 | // you may not use this file except in compliance with the License.
6 | // You may obtain a copy of the License at
7 | //
8 | // http://www.apache.org/licenses/LICENSE-2.0
9 | //
10 | // Unless required by applicable law or agreed to in writing, software
11 | // distributed under the License is distributed on an "AS IS" BASIS,
12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | // See the License for the specific language governing permissions and
14 | // limitations under the License.
15 | ///////////////////////////////////////////////////////////////////////////
16 |
17 | define(['dojo/_base/declare',
18 | 'dijit/_WidgetBase',
19 | 'dijit/_TemplatedMixin',
20 | 'dojo/Evented',
21 | 'dojo/_base/lang',
22 | 'dojo/_base/html',
23 | 'dojo/_base/array',
24 | 'dojo/on',
25 | 'dojo/query',
26 | 'jimu/utils'
27 | ],
28 | function (declare, _WidgetBase, _TemplatedMixin, Evented, lang, html, array, on, query,
29 | jimuUtils) {
30 | return declare([_WidgetBase, _TemplatedMixin, Evented], {
31 | baseClass: 'jimu-simple-table',
32 | declaredClass: 'jimu.dijit.SimpleTable',
33 | templateString: '
' +
34 | '
' +
35 | '
' +
36 | '
' +
37 | '
' +
38 | ' ' +
39 | ' ' +
40 | ' ' +
41 | '
' +
42 | '
' +
43 | '
' +
44 | '
',
45 | _name: null,
46 | _rowIndex: 0,
47 | _rowHeight: 30,
48 | _headHeight: 36,
49 | REPEATING_ERROR: "REPEATING_ERROR",
50 | _classSimpleTableRow: 'simple-table-row',
51 | _classFirstSimpleTableRow: 'first-simple-table-row',
52 | _classLastSimpleTableRow: 'last-simple-table-row',
53 | _classJimuStateDisabled: 'jimu-state-disabled',
54 | _classRowUpDiv: 'row-up-div',
55 | _classRowDownDiv: 'row-down-div',
56 |
57 | //options:
58 | autoHeight: true, //if true, automatically calculate the height
59 | selectable: false,
60 | fields: null,
61 | /*
62 | //fieldInfo's attributes:
63 | //name:field name
64 | //title:field title
65 | //type:text radio checkbox actions empty extension
66 | //class:class name of th and td
67 | //width:width of the field column, auto is default.
68 | //hidden:default false.If true,the field column will be hidden.
69 | //if text
70 | //editable:the text can be edited if true.
71 | //unique:field value is unique in the column.
72 | //if actions
73 | //actions:['up','down','edit','delete']
74 | //if extension
75 | //create //function
76 | //setValue //function
77 | //getValue //function
78 | */
79 |
80 | //public methods:
81 | //clear
82 | //clearEmptyRows
83 | //addEmptyRow
84 | //addRows
85 | //addRow
86 | //deleteRow
87 | //editRow
88 | //selectRow
89 | //getRows
90 | //getSelectedRow
91 | //getSelectedRowData
92 | //getData
93 | //getRowData
94 | //getRowDataArrayByFieldValue
95 |
96 | //events:
97 | //row-click
98 | //row-dblclick
99 | //row-select
100 | //rows-clear
101 | //row-add
102 | //row-edit
103 | //row-delete
104 | //row-up
105 | //row-down
106 | //actions-edit
107 |
108 | //css classes:
109 | //simple-table-title
110 | //simple-table-row
111 | //simple-table-field
112 | //simple-table-cell
113 |
114 | postMixInProperties: function () {
115 | this.nls = window.jimuNls.simpleTable;
116 | },
117 |
118 | postCreate: function () {
119 | this.inherited(arguments);
120 | this._initSelf();
121 | },
122 |
123 | startup: function () {
124 | this.inherited(arguments);
125 | this._updateUI();
126 | },
127 |
128 | _initSelf: function () {
129 | this._initAttachPoints();
130 |
131 | this.own(
132 | jimuUtils.bindClickAndDblclickEvents(this.table,
133 | lang.hitch(this, function (evt) {
134 | var target = evt.target || evt.srcElement;
135 | var tr = jimuUtils.getAncestorDom(target, function (dom) {
136 | return html.hasClass(dom, 'simple-table-row') && html.hasClass(dom, 'not-empty');
137 | }, this.tbody);
138 | if (tr) {
139 | this.selectRow(tr);
140 | this._onClickRow(tr);
141 | }
142 | }), lang.hitch(this, function (evt) {
143 | var target = evt.target || evt.srcElement;
144 | var tr = jimuUtils.getAncestorDom(target, function (dom) {
145 | return html.hasClass(dom, 'simple-table-row') && html.hasClass(dom, 'not-empty');
146 | }, this.tbody);
147 | if (tr) {
148 | this.selectRow(tr);
149 | this._onDblClickRow(tr);
150 | }
151 | }))
152 | );
153 |
154 | var num = Math.random().toString();
155 | this._name = 'jimu_table_' + num.slice(2, num.length);
156 | this.thead = query('thead', this.domNode)[0];
157 | this.tbody = query('tbody', this.domNode)[0];
158 |
159 | if (this.fields && this.fields.length > 0) {
160 | var tr = html.create('tr', {}, this.thead);
161 | array.forEach(this.fields, lang.hitch(this, function (item) {
162 | var width = 'auto';
163 | if (item.type === 'actions') {
164 | item.name = 'actions';
165 | }
166 |
167 | if (item.hidden) {
168 | width = 1;
169 | } else if (item.width !== undefined && item.width !== null) {
170 | width = item.width;
171 | } else if (item.type === 'actions') {
172 | if (!item.name) {
173 | item.width = this._calculateActionsWidth(item) + 20;
174 | width = item.width;
175 | }
176 | }
177 |
178 | html.create('col', {
179 | width: width
180 | }, this.colgroup);
181 | var th = html.create('th', {
182 | innerHTML: item.title,
183 | title: item.title
184 | }, tr);
185 |
186 | html.addClass(th, 'simple-table-field');
187 |
188 | if (item.hidden) {
189 | html.addClass(th, 'hidden-column');
190 | }
191 |
192 | if (item['class']) {
193 | html.addClass(th, item['class']);
194 | }
195 | html.addClass(th, item.name);
196 | }));
197 |
198 | //clone thead
199 | html.empty(this.headDiv);
200 | var tableDiv = lang.clone(this.tableDiv);
201 | html.place(tableDiv, this.headDiv);
202 |
203 | //this.addEmptyRow();
204 | } else {
205 | this.fields = null;
206 | }
207 | },
208 |
209 | _initAttachPoints: function () {
210 | this.table = query('table', this.bodyDiv)[0];
211 | this.colgroup = query('colgroup', this.bodyDiv)[0];
212 | this.head = query('thead', this.bodyDiv)[0];
213 | this.tbody = query('tbody', this.bodyDiv)[0];
214 | },
215 |
216 | clear: function () {
217 | var trs = this._getNotEmptyRows();
218 | html.empty(this.tbody);
219 | array.forEach(trs, lang.hitch(this, function (tr) {
220 | this._onDeleteRow(tr);
221 | }));
222 | //this.addEmptyRow();
223 | this._updateUI();
224 | this._rowIndex = 0;
225 | this._onClearRows(trs);
226 | },
227 |
228 | // clearEmptyRows: function() {
229 | // var trs = this._getEmptyRows();
230 | // array.forEach(trs, lang.hitch(this, function(tr) {
231 | // html.destroy(tr);
232 | // }));
233 | // this._updateUI();
234 | // },
235 |
236 | // addEmptyRow: function() {
237 | // if (!this.fields) {
238 | // return;
239 | // }
240 |
241 | // this.clearEmptyRows();
242 | // var length = this.fields.length;
243 | // var tr = html.create('tr', {
244 | // 'class': 'simple-table-row empty'
245 | // }, this.tbody);
246 | // for (var i = 0; i < length; i++) {
247 | // html.create('td', {
248 | // 'class': 'simple-table-cell empty-td'
249 | // }, tr);
250 | // }
251 | // this._updateRowClassName();
252 | // },
253 |
254 | addRows: function (rowsData) {
255 | var results = [];
256 | if (this.fields && rowsData && rowsData.length > 0) {
257 | array.forEach(rowsData, lang.hitch(this, function (item) {
258 | results.push(this.addRow(item, true));
259 | }));
260 | }
261 | this._updateUI();
262 | return results;
263 | },
264 |
265 | //example:{name1:value1,name2:value2...}
266 | addRow: function (rowData, /* optional */ dontUpdateUI) {
267 | this._rowIndex++;
268 | var result = {
269 | success: false,
270 | tr: null,
271 | errorCode: null,
272 | errorMessage: null,
273 | repeatFields: null
274 | };
275 | if (!this.fields || (typeof rowData !== 'object')) {
276 | return result;
277 | }
278 |
279 | var uniqueFieldMetas = array.filter(this.fields, lang.hitch(this, function (item) {
280 | return item.type === 'text' && item.unique === true;
281 | }));
282 |
283 | var repeatFieldMetas = array.filter(uniqueFieldMetas, lang.hitch(this, function (item) {
284 | var sameValueRows = this.getRowDataArrayByFieldValue(item.name, rowData[item.name]);
285 | return sameValueRows.length > 0;
286 | }));
287 |
288 | if (repeatFieldMetas.length > 0) {
289 | result.errorCode = this.REPEATING_ERROR;
290 | result.errorMessage = "repeating data";
291 | result.repeatFields = repeatFieldMetas;
292 | return result;
293 | }
294 |
295 | // this.clearEmptyRows();
296 | var tr = html.create("tr", {
297 | 'class': "simple-table-row not-empty"
298 | }, this.tbody);
299 | var rowId = 'row' + this._rowIndex;
300 | html.setAttr(tr, 'rowId', rowId);
301 |
302 | array.forEach(this.fields, lang.hitch(this, function (fieldMeta) {
303 | var fieldData = rowData[fieldMeta.name];
304 | var type = fieldMeta.type;
305 | var td = null;
306 | if (type === 'actions') {
307 | td = this._createActionsTd(tr, fieldMeta);
308 | } else {
309 | if (type === "text") {
310 | td = this._createTextTd(tr, fieldMeta, fieldData);
311 | } else if (type === "radio") {
312 | td = this._createRadioTd(tr, fieldMeta, fieldData);
313 | } else if (type === 'checkbox') {
314 | td = this._createCheckboxTd(tr, fieldMeta, fieldData);
315 | } else if (type === "empty") {
316 | td = this._createEmptyTd(tr, fieldMeta);
317 | } else if (type === "extension") {
318 | td = this._createExtensionTd(tr, fieldMeta, fieldData);
319 | }
320 | if (fieldMeta.hidden) {
321 | html.addClass(td, 'hidden-column');
322 | }
323 | }
324 | }));
325 |
326 | // attach item as attribute of tr so can retrieve later
327 | tr.item = rowData;
328 |
329 | if (!dontUpdateUI) {
330 | this._updateUI();
331 | }
332 | result.success = true;
333 | result.tr = tr;
334 | result.errorMessage = null;
335 | this._onAddRow(tr);
336 | return result;
337 | },
338 |
339 | deleteRow: function (tr) {
340 | if (tr) {
341 | html.destroy(tr);
342 | this._updateUI();
343 | this._onDeleteRow(tr);
344 | // var trs = this._getAllRows();
345 | // if(trs.length === 0){
346 | // this.addEmptyRow();
347 | // }
348 | }
349 | },
350 |
351 | selectRow: function (tr) {
352 | if (this.selectable) {
353 | var trs = query('.simple-table-row', this.tbody);
354 | trs.removeClass('jimu-state-active');
355 | html.addClass(tr, 'jimu-state-active');
356 | this._onSelectRow(tr);
357 | }
358 | },
359 |
360 | _updateUI: function () {
361 | this._updateRowClassName();
362 | this._updateHeight();
363 | },
364 |
365 | _updateHeight: function () {
366 | if (this.autoHeight) {
367 | var rows = this.getRows();
368 | var trCount = rows.length > 0 ? rows.length : 1;
369 | // var count = trCount + 1;
370 | var height = this._headHeight + this._rowHeight * trCount + 1;
371 | html.setStyle(this.domNode, 'height', height + 'px');
372 | // this.bodyDiv.style.overflowY = 'hidden';
373 | }
374 | },
375 |
376 | _updateRowClassName: function () {
377 | var originalFirtTr = query('.' + this._classFirstSimpleTableRow, this.tbody)[0];
378 | if (originalFirtTr) {
379 | var originalFirstUpDiv = query('.' + this._classRowUpDiv, originalFirtTr)[0];
380 | if (originalFirstUpDiv) {
381 | html.removeClass(originalFirstUpDiv, this._classJimuStateDisabled);
382 | }
383 | }
384 |
385 | var originalLastTr = query('.' + this._classLastSimpleTableRow, this.tbody)[0];
386 | if (originalLastTr) {
387 | var originalLastDownDiv = query('.' + this._classRowDownDiv, originalLastTr)[0];
388 | if (originalLastDownDiv) {
389 | html.removeClass(originalLastDownDiv, this._classJimuStateDisabled);
390 | }
391 | }
392 |
393 | var trs = query('.' + this._classSimpleTableRow, this.tbody);
394 | trs.removeClass('odd');
395 | trs.removeClass('even');
396 | trs.removeClass(this._classFirstSimpleTableRow);
397 | trs.removeClass(this._classLastSimpleTableRow);
398 |
399 | array.forEach(trs, lang.hitch(this, function (tr, index) {
400 | if (index % 2 === 0) {
401 | html.addClass(tr, 'odd');
402 | } else {
403 | html.addClass(tr, 'even');
404 | }
405 | }));
406 |
407 | if (trs.length > 0) {
408 | var firstTr = trs[0];
409 | html.addClass(firstTr, this._classFirstSimpleTableRow);
410 | var firstUpDiv = query('.' + this._classRowUpDiv, firstTr)[0];
411 | if (firstUpDiv) {
412 | html.addClass(firstUpDiv, this._classJimuStateDisabled);
413 | }
414 |
415 | var lastTr = trs[trs.length - 1];
416 | html.addClass(lastTr, this._classLastSimpleTableRow);
417 | var lastDownDiv = query('.' + this._classRowDownDiv, lastTr)[0];
418 | if (lastDownDiv) {
419 | html.addClass(lastDownDiv, this._classJimuStateDisabled);
420 | }
421 | }
422 | },
423 |
424 | _createTextTd: function (tr, fieldMeta, fieldData) {
425 | var td = null;
426 | if (fieldMeta.editable) {
427 | td = this._createEditableTextTd(tr, fieldMeta, fieldData);
428 | } else {
429 | td = this._createNormalTextTd(tr, fieldMeta, fieldData);
430 | }
431 | return td;
432 | },
433 |
434 | _createNormalTextTd: function (tr, fieldMeta, fieldData) {
435 | var strTd = '' +
436 | '
';
437 | var td = html.toDom(strTd);
438 | html.addClass(td, fieldMeta.name);
439 | var textDiv = query('div', td)[0];
440 | textDiv.innerHTML = fieldData || "";
441 | textDiv.title = fieldData || "";
442 | if (fieldMeta['class']) {
443 | html.addClass(td, fieldMeta['class']);
444 | }
445 | html.place(td, tr);
446 | return td;
447 | },
448 |
449 | _createEditableTextTd: function (tr, fieldMeta, fieldData) {
450 | var tdStr = '' +
451 | '' +
452 | '
';
453 | var td = html.toDom(tdStr);
454 | html.addClass(td, 'simple-table-cell');
455 | html.place(td, tr);
456 | if (fieldMeta['class']) {
457 | html.addClass(td, fieldMeta['class']);
458 | }
459 | var editableDiv = query('div', td)[0];
460 | var editableInput = query('input', td)[0];
461 | editableDiv.innerHTML = fieldData || "";
462 | if (editableDiv.innerHTML !== "") {
463 | editableDiv.title = editableDiv.innerHTML;
464 | }
465 | editableInput.value = editableDiv.innerHTML;
466 | /*
467 | this.own(on(editableDiv, 'dblclick', lang.hitch(this, function (event) {
468 | event.stopPropagation();
469 | // do not enable edit mode on double click
470 |
471 | editableInput.value = editableDiv.innerHTML;
472 | html.setStyle(editableDiv, 'display', 'none');
473 | html.setStyle(editableInput, 'display', 'inline');
474 | editableInput.focus();
475 | })));
476 | */
477 |
478 | // trigger blur on enter key
479 | this.own(on(editableInput, 'keypress', lang.hitch(this, function (e) {
480 | if (e.keyCode === dojo.keys.ENTER) {
481 | editableInput.blur();
482 | }
483 |
484 | })));
485 | this.own(on(editableInput, 'blur', lang.hitch(this, function () {
486 | editableInput.value = lang.trim(editableInput.value);
487 | var oldValue = editableDiv.innerHTML;
488 | var newValue = editableInput.value;
489 | if (newValue !== '') {
490 | if (fieldMeta.unique) {
491 | var sameValueRows = this.getRowDataArrayByFieldValue(fieldMeta.name, newValue, tr);
492 | if (sameValueRows.length > 0) {
493 | editableInput.value = oldValue;
494 | } else {
495 | editableDiv.innerHTML = newValue;
496 | }
497 | } else {
498 | editableDiv.innerHTML = newValue;
499 | }
500 | } else {
501 | editableInput.value = oldValue;
502 | }
503 | // update item
504 | tr.item[fieldMeta.name] = editableDiv.innerHTML;
505 |
506 | html.setStyle(editableInput, 'display', 'none');
507 | html.setStyle(editableDiv, 'display', 'block');
508 | this._onEditRow(tr);
509 | })));
510 | return td;
511 | },
512 |
513 | _createRadioTd: function (tr, fieldMeta, fieldData) {
514 | var tdStr = ' ';
515 | var td = html.toDom(tdStr);
516 | html.addClass(td, 'simple-table-cell');
517 | html.place(td, tr);
518 | if (fieldMeta['class']) {
519 | html.addClass(td, fieldMeta['class']);
520 | }
521 | var radio = query('input', td)[0];
522 | if (fieldMeta.radio && fieldMeta.radio === "row") {
523 | radio.name = this._name + this._rowIndex;
524 | } else {
525 | radio.name = this._name + fieldMeta.name;
526 | }
527 |
528 | radio.checked = fieldData === true;
529 | return td;
530 | },
531 |
532 | _createCheckboxTd: function (tr, fieldMeta, fieldData) {
533 | var tdStr = ' ';
534 | var td = html.toDom(tdStr);
535 | html.addClass(td, 'simple-table-cell');
536 | html.place(td, tr);
537 | if (fieldMeta['class']) {
538 | html.addClass(td, fieldMeta['class']);
539 | }
540 | var checkbox = query('input', td)[0];
541 | checkbox.checked = fieldData === true;
542 | return td;
543 | },
544 |
545 | _createActionsTd: function (tr, fieldMeta) {
546 | var tdStr = '' +
547 | '
';
548 | var td = html.toDom(tdStr);
549 | html.addClass(td, 'simple-table-cell');
550 | var actionItemParent = query(".action-item-parent", td)[0];
551 | html.place(td, tr);
552 | if (fieldMeta['class']) {
553 | html.addClass(td, fieldMeta['class']);
554 | }
555 |
556 | array.forEach(fieldMeta.actions, lang.hitch(this, function (item) {
557 | if (item === 'up') {
558 | var moveupDiv = html.create('div', {
559 | 'class': 'action-item jimu-float-leading row-up-div jimu-icon jimu-icon-up'
560 | }, actionItemParent);
561 | moveupDiv.title = this.nls.moveUp;
562 | this.own(on(moveupDiv, 'click', lang.hitch(this, function (event) {
563 | event.stopPropagation();
564 |
565 | if (!this.onBeforeRowUp(tr)) {
566 | return;
567 | }
568 | var trs = query('.simple-table-row', this.tbody);
569 | var index = array.indexOf(trs, tr);
570 | if (index > 0) {
571 | var newIndex = index - 1;
572 | var trRef = trs[newIndex];
573 | if (trRef) {
574 | html.place(tr, trRef, 'before');
575 | this._updateUI();
576 | this.emit('row-up', tr);
577 | }
578 | }
579 | })));
580 | } else if (item === 'down') {
581 | var movedownDiv = html.create('div', {
582 | 'class': 'action-item jimu-float-leading row-down-div jimu-icon jimu-icon-down'
583 | }, actionItemParent);
584 | movedownDiv.title = this.nls.moveDown;
585 | this.own(on(movedownDiv, 'click', lang.hitch(this, function (event) {
586 | event.stopPropagation();
587 |
588 | if (!this.onBeforeRowDown(tr)) {
589 | return;
590 | }
591 | var trs = query('.simple-table-row', this.tbody);
592 | var index = array.indexOf(trs, tr);
593 | if (index < trs.length - 1) {
594 | var newIndex = index + 1;
595 | var trRef = trs[newIndex];
596 | if (trRef) {
597 | html.place(tr, trRef, 'after');
598 | this._updateUI();
599 | this.emit('row-down', tr);
600 | }
601 | }
602 | })));
603 | } else if (item === 'load') {
604 | var loadDiv = html.create('div', {
605 | 'class': 'action-item jimu-float-leading row-load-div jimu-icon jimu-icon-load'
606 | }, actionItemParent);
607 | loadDiv.title = "Load Map";
608 | this.own(on(loadDiv, 'click', lang.hitch(this, function (event) {
609 | event.stopPropagation();
610 |
611 | this._onActionsLoad(tr);
612 | })));
613 | } else if (item === 'download') {
614 | var loadDiv = html.create('div', {
615 | 'class': 'action-item jimu-float-leading row-load-div jimu-icon jimu-icon-download'
616 | }, actionItemParent);
617 | loadDiv.title = "Download Map";
618 | this.own(on(loadDiv, 'click', lang.hitch(this, function (event) {
619 | event.stopPropagation();
620 |
621 | this._onActionsDownload(tr);
622 | })));
623 | } else if (item === 'edit') {
624 | var editDiv = html.create('div', {
625 | 'class': 'action-item jimu-float-leading row-edit-div jimu-icon jimu-icon-edit'
626 | }, actionItemParent);
627 | editDiv.title = this.nls.edit;
628 | this.own(on(editDiv, 'click', lang.hitch(this, function (event) {
629 | event.stopPropagation();
630 |
631 | if (!this.onBeforeRowEdit(tr)) {
632 | return;
633 | }
634 | this._onActionsEdit(tr);
635 | })));
636 | } else if (item === 'delete') {
637 | var deleteDiv = html.create('div', {
638 | 'class': 'action-item jimu-float-leading row-delete-div jimu-icon jimu-icon-delete'
639 | }, actionItemParent);
640 | deleteDiv.title = this.nls.deleteRow;
641 | this.own(on(deleteDiv, 'click', lang.hitch(this, function (event) {
642 | event.stopPropagation();
643 |
644 | if (!this.onBeforeRowDelete(tr)) {
645 | return;
646 | }
647 | this.deleteRow(tr);
648 | })));
649 | }
650 | }));
651 | var width = this._calculateActionsWidth(fieldMeta) + 'px';
652 | html.setStyle(actionItemParent, 'width', width);
653 | return td;
654 | },
655 |
656 | _calculateActionsWidth: function (fieldMeta) {
657 | var items = array.map(fieldMeta.actions, function (item) {
658 | return item === 'load' || item === 'up' || item === 'down' || item === 'edit' || item === 'delete' || item === 'download';
659 | });
660 | return items.length * 30;
661 | },
662 |
663 | _createEmptyTd: function (tr, fieldMeta) {
664 | var td = html.create('td', {
665 | 'class': fieldMeta.name
666 | }, tr);
667 | html.addClass(td, 'simple-table-cell');
668 | html.addClass(td, 'empty-text-td');
669 | if (fieldMeta['class']) {
670 | html.addClass(td, fieldMeta['class']);
671 | }
672 | return td;
673 | },
674 |
675 | _createExtensionTd: function (tr, fieldMeta, fieldData) {
676 | var td = html.create('td', {
677 | 'class': fieldMeta.name
678 | }, tr);
679 | html.addClass(td, 'simple-table-cell');
680 | html.addClass(td, 'extension-td');
681 | if (fieldMeta['class']) {
682 | html.addClass(td, fieldMeta['class']);
683 | }
684 | if (fieldMeta.create && typeof fieldMeta.create === 'function') {
685 | fieldMeta.create(td);
686 | }
687 | if (fieldMeta.setValue && typeof fieldMeta.setValue === 'function') {
688 | fieldMeta.setValue(td, fieldData);
689 | }
690 | return td;
691 | },
692 |
693 | editRow: function (tr, rowData) {
694 | var result = {
695 | success: false,
696 | tr: null,
697 | errorCode: null,
698 | errorMessage: null,
699 | repeatFields: null
700 | };
701 | if (!this.fields || (typeof rowData !== 'object')) {
702 | return result;
703 | }
704 | if (!html.isDescendant(tr, this.tbody)) {
705 | return result;
706 | }
707 | var allFieldMetas = lang.mixin([], this.fields);
708 | var uniqueFieldMetas = array.filter(allFieldMetas, lang.hitch(this, function (item) {
709 | return item.type === 'text' && item.unique === true;
710 | }));
711 |
712 | var repeatFieldMetas = array.filter(uniqueFieldMetas, lang.hitch(this, function (item) {
713 | var sameValueRows = this.getRowDataArrayByFieldValue(item.name, rowData[item.name], tr);
714 | return sameValueRows.length > 0;
715 | }));
716 |
717 | if (repeatFieldMetas.length > 0) {
718 | result.errorCode = this.REPEATING_ERROR;
719 | result.errorMessage = "repeating data";
720 | result.repeatFields = repeatFieldMetas;
721 | return result;
722 | }
723 | var tds = query('.simple-table-cell', tr);
724 | array.forEach(this.fields, lang.hitch(this, function (fieldMeta, idx) {
725 | if (!rowData.hasOwnProperty(fieldMeta.name)) {
726 | return;
727 | }
728 | var td = tds[idx];
729 | var fieldData = rowData[fieldMeta.name];
730 | var type = fieldMeta.type;
731 | if (type === 'text') {
732 | if (fieldMeta.editable) {
733 | this._editEditableText(td, fieldMeta, fieldData);
734 | } else {
735 | this._editNormalText(td, fieldMeta, fieldData);
736 | }
737 | } else if (type === 'radio') {
738 | this._editRadio(td, fieldMeta, fieldData);
739 | } else if (type === 'checkbox') {
740 | this._editCheckbox(td, fieldMeta, fieldData);
741 | } else if (type === 'extension') {
742 | this._editExtension(td, fieldMeta, fieldData);
743 | }
744 | }));
745 | result.success = true;
746 | result.tr = tr;
747 | result.errorMessage = null;
748 | this._onEditRow(tr);
749 | return result;
750 | },
751 |
752 | _editNormalText: function (td, fieldMeta, fieldData) {
753 | /*jshint unused: false*/
754 | var normalTextDiv = query('div', td)[0];
755 | normalTextDiv.innerHTML = fieldData || "";
756 | normalTextDiv.title = normalTextDiv.innerHTML;
757 | },
758 |
759 | _editEditableText: function (td, fieldMeta, fieldData) {
760 | /*jshint unused: false*/
761 | var editableDiv = query('div', td)[0];
762 | editableDiv.innerHTML = fieldData || "";
763 | var editableInput = query('input', td)[0];
764 | editableInput.value = editableDiv.innerHTML;
765 | },
766 |
767 | _editRadio: function (td, fieldMeta, fieldData) {
768 | /*jshint unused: false*/
769 | var radio = query('input', td)[0];
770 | radio.checked = fieldData === true;
771 | },
772 |
773 | _editCheckbox: function (td, fieldMeta, fieldData) {
774 | /*jshint unused: false*/
775 | var checkbox = query('input', td)[0];
776 | checkbox.checked = fieldData === true;
777 | },
778 |
779 | _editExtension: function (td, fieldMeta, fieldData) {
780 | if (fieldMeta.setValue && typeof fieldMeta.setValue === 'function') {
781 | fieldMeta.setValue(td, fieldData);
782 | }
783 | },
784 |
785 | _getAllRows: function () {
786 | return query('.simple-table-row', this.tbody);
787 | },
788 |
789 | _getNotEmptyRows: function () {
790 | var trs = this._getAllRows();
791 | return array.filter(trs, lang.hitch(this, function (tr) {
792 | return !html.hasClass(tr, 'empty');
793 | }));
794 | },
795 |
796 | _getEmptyRows: function () {
797 | var trs = this._getAllRows();
798 | return array.filter(trs, lang.hitch(this, function (tr) {
799 | return html.hasClass(tr, 'empty');
800 | }));
801 | },
802 |
803 | getRows: function () {
804 | return this._getNotEmptyRows();
805 | },
806 |
807 | getSelectedRow: function () {
808 | var result = null;
809 | var trs = query('.simple-table-row', this.tbody);
810 | var filterTrs = array.filter(trs, lang.hitch(this, function (tr) {
811 | return !html.hasClass(tr, 'empty') && html.hasClass(tr, 'jimu-state-active');
812 | }));
813 | if (filterTrs.length > 0) {
814 | result = filterTrs[0];
815 | }
816 | return result;
817 | },
818 |
819 | getSelectedRowData: function () {
820 | var result = null;
821 | var tr = this.getSelectedRow();
822 | if (tr) {
823 | result = this._getRowDataByTr(tr);
824 | }
825 | return result;
826 | },
827 |
828 | getData: function ( /*optional*/ ignoredTr) {
829 | var trs = this._getNotEmptyRows();
830 | if (ignoredTr) {
831 | trs = array.filter(trs, lang.hitch(this, function (tr) {
832 | return tr !== ignoredTr;
833 | }));
834 | }
835 | var result = array.map(trs, lang.hitch(this, function (tr) {
836 | return this._getRowDataByTr(tr);
837 | }));
838 | return result;
839 | },
840 |
841 | getRowData: function (tr) {
842 | return this._getRowDataByTr(tr);
843 | },
844 |
845 | _getRowDataByTr: function (tr) {
846 | var rowData = null;
847 | if (tr) {
848 | rowData = {};
849 | } else {
850 | return null;
851 | }
852 | array.forEach(this.fields, lang.hitch(this, function (fieldMeta) {
853 | var type = fieldMeta.type;
854 | if (type === 'actions') {
855 | return;
856 | }
857 | var name = fieldMeta.name;
858 | rowData[name] = null;
859 | var td = query('.' + name, tr)[0];
860 | if (td) {
861 | if (type === 'text') {
862 | if (fieldMeta.editable) {
863 | var editableDiv = query('div', td)[0];
864 | rowData[name] = editableDiv.innerHTML;
865 | } else {
866 | var normalTextDiv = query('div', td)[0];
867 | rowData[name] = normalTextDiv.innerHTML;
868 | }
869 | } else if (type === 'radio') {
870 | var radio = query('input', td)[0];
871 | rowData[name] = radio.checked;
872 | } else if (type === 'checkbox') {
873 | var checkbox = query('input', td)[0];
874 | rowData[name] = checkbox.checked;
875 | } else if (type === 'extension') {
876 | if (fieldMeta.getValue && typeof fieldMeta.getValue === 'function') {
877 | rowData[name] = fieldMeta.getValue(td, fieldMeta);
878 | }
879 | }
880 | }
881 | }));
882 | return rowData;
883 | },
884 |
885 | getRowDataArrayByFieldValue: function (fieldName, fieldValue, /*optional*/ ignoredTr) {
886 | var result = [];
887 | if (!this.fields) {
888 | return [];
889 | }
890 | var validField = array.some(this.fields, lang.hitch(this, function (item) {
891 | return item.name === fieldName;
892 | }));
893 | if (!validField) {
894 | return [];
895 | }
896 | var rows = this.getData(ignoredTr);
897 | result = array.filter(rows, lang.hitch(this, function (row) {
898 | /* jshint eqeqeq: false*/
899 | return row[fieldName] == fieldValue;
900 | }));
901 | return result;
902 | },
903 |
904 | /**
905 | * return all the data items from the table
906 | */
907 | getItems: function () {
908 | var trs = [],
909 | result = [];
910 |
911 | trs = this._getNotEmptyRows();
912 |
913 | var result = array.map(trs, lang.hitch(this, function (tr) {
914 | return tr.item;
915 | }));
916 | return result;
917 | },
918 |
919 | /**
920 | * set edit mode on all cells in given row - except for action cell
921 | * @param {TableRow} tr table row dom node
922 | */
923 | _setEditModeOnRow: function (tr) {
924 | var tds = query('.simple-table-cell', tr);
925 | array.forEach(tds, lang.hitch(this, function (td, idx) {
926 | if (html.hasClass(td, "actions")) {
927 | // skip actions
928 | return;
929 | }
930 | this._setEditModeOnCell(td);
931 | }));
932 | },
933 |
934 | /**
935 | * enable Edit Mode on the given cell
936 | * @param {TableCell} td table cell dom node
937 | */
938 | _setEditModeOnCell: function (td) {
939 |
940 | var editableDiv = query('div', td)[0];
941 | var editableInput = query('input', td)[0];
942 | editableInput.value = editableDiv.innerHTML;
943 | html.setStyle(editableDiv, 'display', 'none');
944 | html.setStyle(editableInput, 'display', 'inline');
945 | editableInput.focus();
946 | },
947 |
948 | _onClickRow: function (tr) {
949 | this.emit('row-click', tr);
950 | },
951 |
952 | _onDblClickRow: function (tr) {
953 | var args = {
954 | element: tr,
955 | item: tr.item
956 | };
957 | this.emit('row-dblclick', args);
958 | },
959 |
960 | _onSelectRow: function (tr) {
961 | this.emit('row-select', tr);
962 | },
963 |
964 | _onAddRow: function (tr) {
965 | this.emit('row-add', tr);
966 | },
967 |
968 | _onEditRow: function (tr) {
969 | this.emit('row-edit', tr);
970 | },
971 |
972 | _onDeleteRow: function (tr) {
973 | var args = {
974 | element: tr,
975 | item: tr.item
976 | };
977 | this.emit('row-delete', args);
978 | },
979 |
980 | _onEnterRow: function (tr) {
981 | this.emit('row-enter', tr);
982 | },
983 |
984 | _onClearRows: function (trs) {
985 | this.emit('rows-clear', trs);
986 | },
987 |
988 | _onActionsEdit: function (tr) {
989 | this.emit('actions-edit', tr);
990 |
991 | this._setEditModeOnRow(tr);
992 | },
993 |
994 | _onActionsLoad: function (tr) {
995 | var args = {
996 | element: tr,
997 | item: tr.item
998 | };
999 | this.emit('actions-load', args);
1000 | },
1001 |
1002 | _onActionsDownload: function (tr) {
1003 | var args = {
1004 | element: tr,
1005 | item: tr.item
1006 | };
1007 | this.emit('actions-download', args);
1008 | },
1009 |
1010 | onBeforeRowUp: function (tr) {
1011 | /*jshint unused : false*/
1012 | return true;
1013 | },
1014 |
1015 | onBeforeRowDown: function (tr) {
1016 | /*jshint unused : false*/
1017 | return true;
1018 | },
1019 |
1020 | onBeforeRowEdit: function (tr) {
1021 | /*jshint unused : false*/
1022 | return true;
1023 | },
1024 |
1025 | onBeforeRowDelete: function (tr) {
1026 | /*jshint unused : false*/
1027 | return true;
1028 | }
1029 | });
1030 | });
--------------------------------------------------------------------------------
/Widget.html:
--------------------------------------------------------------------------------
1 |
2 |
Save the current map settings
3 |
4 |
5 |
6 | Name:
7 |
8 |
9 |
Save
10 |
Enter the name for the session
11 |
12 |
13 |
14 |
Saved Sessions
15 |
16 |
17 |
21 |
22 |
23 |
27 |
--------------------------------------------------------------------------------
/Widget.js:
--------------------------------------------------------------------------------
1 | ///////////////////////////////////////////////////////////////////////////
2 | // Copyright © 2015 Softwhere Solutions
3 | // All Rights Reserved.
4 | //
5 | // Licensed under the Apache License Version 2.0 (the "License");
6 | // you may not use this file except in compliance with the License.
7 | // You may obtain a copy of the License at
8 | //
9 | // http://www.apache.org/licenses/LICENSE-2.0
10 | //
11 | // Unless required by applicable law or agreed to in writing, software
12 | // distributed under the License is distributed on an "AS IS" BASIS,
13 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | // See the License for the specific language governing permissions and
15 | // limitations under the License.
16 | ///////////////////////////////////////////////////////////////////////////
17 | /*global console, define, dojo, FileReader */
18 |
19 | define(['dojo/_base/declare',
20 | 'jimu/BaseWidget',
21 | 'dijit/_WidgetsInTemplateMixin',
22 | 'dojo/_base/lang',
23 | 'dojo/_base/array',
24 | 'dojo/_base/html',
25 | 'dojo/dom-attr',
26 | 'dojo/query',
27 | 'dojo/on',
28 | 'dojo/topic',
29 | 'dojo/string',
30 | 'dojo/json',
31 | 'dojo/Deferred',
32 | 'dojo/promise/all',
33 | 'esri/geometry/Extent',
34 | 'esri/graphic',
35 | 'esri/layers/GraphicsLayer',
36 | 'esri/layers/FeatureLayer',
37 | 'esri/layers/ImageParameters',
38 | 'esri/layers/ArcGISDynamicMapServiceLayer',
39 | 'esri/layers/ArcGISTiledMapServiceLayer',
40 | 'jimu/ConfigManager',
41 | 'jimu/MapManager',
42 | 'jimu/dijit/Popup',
43 | 'jimu/dijit/Message',
44 | 'jimu/LayerInfos/LayerInfos',
45 | './SimpleTable',
46 | 'dijit/form/TextBox'
47 | ],
48 | function (declare,
49 | BaseWidget,
50 | _WidgetsInTemplateMixin,
51 | lang,
52 | array,
53 | html,
54 | domAttr,
55 | query,
56 | on,
57 | topic,
58 | string,
59 | JSON,
60 | Deferred,
61 | all,
62 | Extent,
63 | Graphic,
64 | GraphicsLayer,
65 | FeatureLayer,
66 | ImageParameters,
67 | ArcGISDynamicMapServiceLayer,
68 | ArcGISTiledMapServiceLayer,
69 | ConfigManager,
70 | MapManager,
71 | Popup,
72 | Message,
73 | LayerInfos,
74 | Table,
75 | TextBox) {
76 | //To create a widget, you need to derive from BaseWidget.
77 | return declare([BaseWidget, _WidgetsInTemplateMixin], {
78 | // Custom widget code goes here
79 |
80 | baseClass: 'jimu-widget-savesession',
81 |
82 | // name of sessions string in local storage
83 | storageKey: "sessions",
84 |
85 | // the saved sessions
86 | sessions: [],
87 |
88 | postCreate: function () {
89 | this.inherited(arguments);
90 |
91 | // setup save to file
92 | this.saveToFileForm.action = this.config.saveToFileUrl;
93 | this.saveToFileName.value = this.config.defaultFileName;
94 |
95 |
96 | this.loadSavedSessionsFromStorage();
97 |
98 | this.initSavedSessionUI();
99 |
100 | this.initNewSessionUI();
101 |
102 | this.refreshLoadFileUI();
103 |
104 | console.log('SaveSession :: postCreate :: completed');
105 | },
106 |
107 | startup: function () {
108 | this.inherited(arguments);
109 | console.log('SaveSession :: startup');
110 | },
111 |
112 | onOpen: function () {
113 | console.log('SaveSession :: onOpen');
114 | },
115 |
116 | /**
117 | * create the table of saved sessions
118 | */
119 | initSavedSessionUI: function () {
120 | var tableSettings = {
121 | autoHeight: true,
122 | fields: [
123 | {
124 | "name": "name",
125 | "title": "Session",
126 | "type": "text",
127 | "class": "session-name",
128 | "unique": true,
129 | "hidden": false,
130 | "editable": true
131 | },
132 | {
133 | "name": "actions",
134 | "title": "Actions",
135 | "type": "actions",
136 | "class": "actions",
137 | "actions": ['load', 'download', 'edit', 'up', 'down', 'delete']
138 | }
139 | ],
140 | selectable: false
141 | };
142 |
143 | this.sessionTable = new Table(tableSettings);
144 | this.sessionTable.placeAt(this.savedSessionContainer);
145 | this.sessionTable.startup();
146 |
147 | // listend for events on session table
148 | this.own(on(this.sessionTable, 'row-delete', lang.hitch(this, 'onSessionTableChanged')));
149 | this.own(on(this.sessionTable, 'row-up', lang.hitch(this, 'onSessionTableChanged')));
150 | this.own(on(this.sessionTable, 'row-down', lang.hitch(this, 'onSessionTableChanged')));
151 | this.own(on(this.sessionTable, 'row-edit', lang.hitch(this, 'onSessionTableChanged')));
152 | this.own(on(this.sessionTable, 'actions-load', lang.hitch(this, 'onLoadSessionClicked')));
153 | this.own(on(this.sessionTable, 'row-dblclick', lang.hitch(this, 'onLoadSessionClicked')));
154 | this.own(on(this.sessionTable, 'actions-download', lang.hitch(this, 'onSaveItemToFileClicked')));
155 |
156 | this.sessionTable.addRows(this.sessions);
157 | console.log('SaveSession :: initSavedSessionUI :: session table created');
158 | },
159 |
160 | /**
161 | * reload the table with the saved sessions
162 | */
163 | refreshSavedSessionUI: function () {
164 | this.sessionTable.clear();
165 | this.sessionTable.addRows(this.sessions);
166 | console.log('SaveSession :: refreshSavedSessionUI :: session table refreshed');
167 | },
168 |
169 | /**
170 | * set up the UI for New Session
171 | */
172 | initNewSessionUI: function () {
173 | this.refreshNewSessionUI();
174 | this.own(this.sessionNameTextBox.on('change', lang.hitch(this, 'refreshNewSessionUI')));
175 | this.own(this.sessionNameTextBox.on('keypress', lang.hitch(this, 'onKeyPressed')));
176 | console.log('SaveSession :: initNewSessionUI :: end');
177 | },
178 |
179 | /**
180 | * enable the save file link when there are sessions
181 | */
182 | refreshLoadFileUI: function () {
183 |
184 | var sessionString = "",
185 | hasSessions = false;
186 |
187 | hasSessions = this.sessions && this.sessions.length > 0;
188 | if (!hasSessions) {
189 | domAttr.set(this.saveToFileButton, "disabled", "true");
190 | html.addClass(this.saveToFileButton, "jimu-state-disabled");
191 | console.log('SaveSession :: refreshLoadFileUI :: save to file button disabled');
192 | } else {
193 | domAttr.remove(this.saveToFileButton, "disabled");
194 | html.removeClass(this.saveToFileButton, "jimu-state-disabled");
195 | console.log('SaveSession :: refreshLoadFileUI :: save to file button enabled');
196 | }
197 |
198 | // use a data url to save the file, if not using a server url
199 | // if useServerToDownloadFile, use a form post to a service instead
200 | if (!this.config.useServerToDownloadFile) {
201 | // also set the save to link if has sessions
202 | // this uses data url to prompt user to download
203 | if (hasSessions) {
204 | sessionString = JSON.stringify(this.sessions);
205 | // must convert special chars to url encoding
206 | sessionString = encodeURIComponent(sessionString);
207 | domAttr.set(this.saveToFileButton, "href", "data:application/octet-stream," + sessionString);
208 | domAttr.set(this.saveToFileButton, "download", this.config.fileNameForAllSessions);
209 | console.log('SaveSession :: refreshLoadFileUI :: data url set on saveToFileButton');
210 | }
211 | }
212 | },
213 |
214 | /**
215 | * when a key is pressed, check the session name
216 | * @param {Object} e event args
217 | */
218 | onKeyPressed: function (e) {
219 |
220 | if (e.keyCode === dojo.keys.ENTER) {
221 | this.onSaveButtonClicked();
222 | }
223 |
224 | setTimeout(lang.hitch(this, 'refreshNewSessionUI'), 0);
225 | console.log('SaveSession :: onKeyPressed :: end');
226 | },
227 |
228 | /**
229 | * enable the save button when a valid entry is in textbox
230 | */
231 | refreshNewSessionUI: function () {
232 | var sessionName = "",
233 | isValid = false;
234 | sessionName = this.sessionNameTextBox.get("value");
235 |
236 | // must have a valid session name to enable save
237 | isValid = this.isValidSessionName(sessionName);
238 |
239 | if (!isValid) {
240 | domAttr.set(this.saveButton, "disabled", "true");
241 | html.addClass(this.saveButton, "jimu-state-disabled");
242 | console.log('SaveSession :: refreshNewSessionUI :: save button disabled');
243 | } else {
244 | domAttr.remove(this.saveButton, "disabled");
245 | html.removeClass(this.saveButton, "jimu-state-disabled");
246 | console.log('SaveSession :: refreshNewSessionUI :: save button enabled');
247 | }
248 |
249 | this.inputText.innerHTML = this.getMesageForSessionName(sessionName);
250 | console.log('SaveSession :: refreshNewSessionUI :: end');
251 | },
252 |
253 | /**
254 | * checks if the given name is valid - has text and is not already taken
255 | * @param {String} sessionName name for the session
256 | * @returns {Boolean} true if the given session name is not already entered
257 | */
258 | isValidSessionName: function (name) {
259 |
260 | if (!name) {
261 | return false;
262 | }
263 |
264 | // check for duplicates
265 | var hasSameName = array.some(this.sessions, function (session) {
266 | return session.name === name;
267 | }, this);
268 |
269 | return !hasSameName;
270 | },
271 |
272 | /**
273 | * checks if the given name is valid - has text and is not already taken
274 | * @param {String} sessionName name for the session
275 | * @returns {String} true if the given session name is not already entered
276 | */
277 | getUniqueSessionName: function (name, idx) {
278 |
279 | idx = idx || 0; // default to 0
280 |
281 | idx += 1;
282 |
283 | var newName = name + " " + String(idx);
284 |
285 | if (!this.isValidSessionName(newName)) {
286 |
287 | newName = this.getUniqueSessionName(name, idx);
288 | }
289 |
290 | return newName;
291 | },
292 |
293 | /**
294 | * returns input text for session name
295 | * @param {String} sessionName name for the session
296 | * @returns {String} a help message
297 | */
298 | getMesageForSessionName: function (name) {
299 |
300 | var text = "",
301 | hasSameName = false;
302 |
303 | if (!name) {
304 | text = "Enter the name for the session";
305 | }
306 |
307 | // check for duplicates
308 | hasSameName = array.some(this.sessions, function (session) {
309 | return session.name === name;
310 | }, this);
311 |
312 | if (hasSameName) {
313 | text = "Enter a unique name for the session";
314 | }
315 |
316 | return text;
317 | },
318 |
319 | /**
320 | * when the save button is clicked, add the session to local storage
321 | */
322 | onSaveButtonClicked: function () {
323 | console.log('SaveSession :: onSaveButtonClicked :: begin');
324 | var session,
325 | sessionName = "";
326 | sessionName = this.sessionNameTextBox.get("value");
327 |
328 | if (!this.isValidSessionName(sessionName)) {
329 | console.log('SaveSession :: onSaveButtonClicked :: invalid sesion name = ', sessionName);
330 | return;
331 | }
332 |
333 | session = this.getSettingsForCurrentMap();
334 | session.name = sessionName;
335 | this.sessions.push(session);
336 | console.log("SaveSession :: onSaveButtonClicked :: added session = ", session);
337 |
338 | this.storeSessions();
339 |
340 | this.sessionTable.addRow(session);
341 | this.refreshLoadFileUI();
342 | this.refreshNewSessionUI();
343 | console.log('SaveSession :: onSaveButtonClicked :: end');
344 | },
345 |
346 | /**
347 | * get the sessions from the table and store them
348 | */
349 | onSessionTableChanged: function (e) {
350 | console.log('SaveSession :: onSessionTableChanged :: begin');
351 |
352 | // store changed sessions
353 | this.sessions = this.sessionTable.getItems();
354 | this.storeSessions();
355 |
356 | // and update ui
357 | this.refreshLoadFileUI();
358 | this.refreshNewSessionUI();
359 |
360 | console.log('SaveSession :: onSessionTableChanged :: session stored');
361 | },
362 |
363 | /**
364 | * Load the session when clicked in Table
365 | * @param {Object} e the event args - item = session
366 | */
367 | onLoadSessionClicked: function (e) {
368 | var session = e.item;
369 | console.log('SaveSession :: onLoadSessionClicked :: session = ', session);
370 | this.loadSession(session);
371 | },
372 |
373 | /**
374 | * prompt to upload file
375 | * @param {Object} e the event args
376 | */
377 | onLoadFromFileButtonClicked: function (e) {
378 |
379 | var popup = new Popup({
380 | titleLabel: "Load sessions from file",
381 | autoHeight: true,
382 | content: "Choose the file to load: ",
383 | container: 'main-page',
384 | width: 400,
385 | height: 200,
386 | buttons: [{
387 | label: "Ok",
388 | key: dojo.keys.ENTER,
389 | onClick: lang.hitch(this, function () {
390 | console.log('SaveSession :: onLoadFromFile :: ok');
391 | var fileInput,
392 | fileName;
393 |
394 | // get file from input
395 | fileInput = query('#file-to-load', popup.domNode)[0];
396 | fileName = fileInput.files[0];
397 | popup.close();
398 | this.loadSavedSessionsFromFile(fileName);
399 | })
400 |
401 | }, {
402 | label: "Cancel",
403 | key: dojo.keys.ESCAPE,
404 | onClick: lang.hitch(this, function () {
405 | console.log('SaveSession :: onLoadFromFile :: canceled');
406 | popup.close();
407 | })
408 | }],
409 | onClose: lang.hitch(this, function () {
410 | console.log('SaveSession :: onLoadFromFile :: closed');
411 | })
412 | });
413 | console.log('SaveSession :: onLoadFromFileButtonClicked :: ');
414 | },
415 |
416 | /**
417 | * save sessions to file
418 | * @param {Object} e the event args
419 | */
420 | onSaveToFileButtonClicked: function (e) {
421 |
422 | if (!this.config.useServerToDownloadFile) {
423 | // skipping since there is no url to submit to
424 | console.log('SaveSession :: onSaveToFileButtonClicked :: saveToFileForm submit canceled.');
425 | return;
426 | }
427 |
428 | var sessionString = JSON.stringify(this.sessions);
429 |
430 | // update form values
431 | this.saveToFileName.value = this.config.fileNameForAllSessions;
432 | this.saveToFileContent.value = sessionString;
433 |
434 | // trigger the post to server side
435 | this.saveToFileForm.submit();
436 |
437 | console.log('SaveSession :: onSaveToFileButtonClicked :: end');
438 | },
439 |
440 | /**
441 | * save the single item to file
442 | * @param {Object} e the event args
443 | */
444 | onSaveItemToFileClicked: function (e) {
445 |
446 | var sessionString = "",
447 | fileName = "",
448 | sessions = [];
449 |
450 | fileName = string.substitute(this.config.fileNameTplForSession, e.item);
451 |
452 | sessions.push(e.item);
453 | sessionString = JSON.stringify(sessions);
454 |
455 | // update form values
456 | this.saveToFileName.value = fileName;
457 | this.saveToFileContent.value = sessionString;
458 |
459 | // trigger the post to server side
460 | this.saveToFileForm.submit();
461 |
462 | console.log('SaveSession :: onSaveItemToFileClicked :: end');
463 | },
464 |
465 | /**
466 | * load the session definitions from the given text file
467 | * @param {Object} file reference to text file to load
468 | */
469 | loadSavedSessionsFromFile: function (file) {
470 | console.log('SaveSession :: loadSavedSessionsFromFile :: begin for file = ', file);
471 |
472 | var sessionsString = "",
473 | sessionsToLoad = null,
474 | reader,
475 | msg,
476 | loadedCount = 0,
477 | me = this;
478 |
479 | reader = new FileReader();
480 |
481 | // when the file is loaded
482 | reader.onload = function () {
483 | var sessionsString = reader.result;
484 |
485 | if (!sessionsString) {
486 | console.warn("SaveSession :: loadSavedSessionsFromFile : no sessions to load");
487 | msg = new Message({
488 | message: "No sessions found in the file.",
489 | type: 'message'
490 | });
491 | return;
492 | }
493 |
494 | sessionsToLoad = JSON.parse(sessionsString);
495 | console.log("SaveSession :: loadSavedSessionsFromFile : sessions found ", sessionsToLoad);
496 |
497 | array.forEach(sessionsToLoad, function (sessionToLoad) {
498 | var isValid = me.isValidSessionName(sessionToLoad.name);
499 | if (!isValid) {
500 | // fix the session name
501 | sessionToLoad.name = me.getUniqueSessionName(sessionToLoad.name);
502 | console.log("SaveSession :: loadSavedSessionsFromFile :: session name changed to " + sessionToLoad.name);
503 | }
504 |
505 | // refresh tabl
506 | this.sessions.push(sessionToLoad);
507 | this.sessionTable.addRow(sessionToLoad);
508 | loadedCount += 1;
509 | }, me);
510 |
511 | // do not call refresh ui since session table will trigger change event
512 | me.storeSessions();
513 | me.refreshLoadFileUI();
514 |
515 | msg = new Message({
516 | message: String(loadedCount) + " sessions loaded from the file.",
517 | type: 'message'
518 | });
519 |
520 | console.log('SaveSession :: loadSavedSessionsFromFile :: end for file = ', file);
521 | };
522 |
523 | // starting reading, and continue when load event fired
524 | reader.readAsText(file);
525 | },
526 |
527 | /**
528 | * Apply the settings from the given session to the current map
529 | * @param {Object} sessionToLoad a session
530 | */
531 | loadSession: function (sessionToLoad) {
532 |
533 | var onMapChanged,
534 | extentToLoad;
535 |
536 | if (sessionToLoad.webmapId && sessionToLoad.webmapId !== this.map.itemId) {
537 | console.log('SaveSession :: loadSession :: changing webmap = ', sessionToLoad.webmapId);
538 |
539 |
540 | onMapChanged = topic.subscribe("mapChanged", lang.hitch(this, function (newMap) {
541 |
542 | console.log('SaveSession :: loadSession :: map changed from ', this.map.itemId, ' to ', newMap.itemId);
543 |
544 | // update map reference here
545 | // since this.map still refers to old map?
546 | // ConfigManager has not recreated widget with new map yet
547 | this.map = newMap;
548 |
549 | // do not listen any more
550 | onMapChanged.remove();
551 |
552 | // load the rest of the session
553 | this.loadSession(sessionToLoad);
554 | }));
555 |
556 |
557 | ConfigManager.getInstance()._onMapChanged({
558 | "itemId": sessionToLoad.webmapId
559 | });
560 |
561 | // do not continue until webmap is changed
562 | return;
563 | }
564 |
565 | // zoom the map
566 | if (sessionToLoad.extent) {
567 | extentToLoad = new Extent(sessionToLoad.extent);
568 | this.map.setExtent(extentToLoad).then(function () {
569 | console.log('SaveSession :: loadSession :: new extent = ', extentToLoad);
570 | }, function () {
571 | var msg = new Message({
572 | message: string.substitute("An error occurred zooming to the ${name} map.", sessionToLoad),
573 | type: 'error'
574 | });
575 | });
576 | }
577 |
578 | // load the saved graphics
579 | this.setGraphicsOnCurrentMap(sessionToLoad.graphics);
580 |
581 |
582 | // toggle layers
583 | if (sessionToLoad.layers) {
584 | this.setLayersOnMap(sessionToLoad.layers);
585 | }
586 |
587 | // fire custom event
588 | topic.publish("SaveSession/SessionLoaded", sessionToLoad);
589 |
590 | console.log('SaveSession :: loadSession :: session = ', sessionToLoad);
591 | },
592 |
593 | /**
594 | * apply settings to layers
595 | * @param {Array} array of layer settings to apply to map
596 | */
597 | setLayersOnMap: function (settings) {
598 | var propName = "",
599 | layerSettings,
600 | layer,
601 | addGraphicsToLayer,
602 | visibleLayers = [],
603 | removeItem = [],
604 | i = 0;
605 |
606 | array.forEach(settings, function (layerSettings) {
607 | layer = this.map.getLayer(layerSettings.id);
608 | if (!layer) {
609 | console.log('SaveSession :: setLayersOnMap :: no layer found with id = ', propName);
610 | layer = this.addLayerToMap(layerSettings);
611 | // exit here? or re-apply settings
612 | return;
613 | }
614 |
615 | // set visible
616 | if (layer.setVisibility) {
617 | layer.setVisibility(layerSettings.isVisible);
618 | console.log('SaveSession :: loadSession :: set visibility = ', layerSettings.isVisible, ' for layer : id=', layer.id);
619 | }
620 |
621 | if (layerSettings.visibleLayers && layer.setVisibleLayers) {
622 |
623 | var visibleLayers = lang.clone(layerSettings.visibleLayers);
624 | if (!layerSettings.visibleLayers.length) {
625 | // for no visible layers use array of -1
626 | // drackleyad :: note that in order to properly interpret a layer as truly 'off', it requires an array consisting only of three '-1' values
627 | visibleLayers = [-1, -1, -1];
628 | } else {
629 | // has some visible layers
630 | removeItem = [];
631 | array.forEach(visibleLayers, function (visibleLayer, index) {
632 | if (visibleLayer === -1) {
633 | removeItem.push(index);
634 | }
635 | });
636 |
637 | for (i = removeItem.length; i-- > 0;) {
638 | visibleLayers.splice(i, 1);
639 | }
640 | }
641 |
642 | layer.setVisibleLayers(visibleLayers);
643 | }
644 |
645 | console.log('SaveSession :: loadSession :: setLayersOnMap completed for layer = ', layer.id);
646 | }, this);
647 |
648 | // fire custom event
649 | topic.publish("layersChanged");
650 |
651 | // fire refresh event
652 | LayerInfos.getInstance(this.map, this.map.itemInfo).then(function (layerInfosObject) { // fire change event to trigger update
653 | on.emit(layerInfosObject, "updated");
654 | on.emit(layerInfosObject, "layerInfosChanged");
655 | //layerInfosObject.onlayerInfosChanged();
656 | });
657 |
658 | },
659 |
660 | /**
661 | * create a new map layer with the given settings
662 | * @param {Object} layerSettings settings for the layer
663 | * @return {Object} layer oject
664 | */
665 | addLayerToMap: function (layerSettings) {
666 | console.log('SaveSession :: addLayerToMap :: adding layer = ', layerSettings);
667 | var layer,
668 | options;
669 | switch (layerSettings.type) {
670 | case "ArcGISDynamicMapServiceLayer":
671 | options = lang.clone(layerSettings.options);
672 | options.imageParameters = new ImageParameters();
673 | lang.mixin(options.imageParameters, layerSettings.options.imageParameters);
674 | layer = new ArcGISDynamicMapServiceLayer(layerSettings.url, options);
675 | console.log('SaveSession :: addLayerToMap :: created ArcGISDynamicMapServiceLayer layer = ', layer);
676 | break;
677 | case "FeatureLayer":
678 | layer = new FeatureLayer(layerSettings.url, layerSettings.options);
679 | console.log('SaveSession :: addLayerToMap :: created Feature layer = ', layer);
680 | break;
681 | case "ArcGISTiledMapServiceLayer":
682 | layer = new ArcGISTiledMapServiceLayer(layerSettings.url, layerSettings.options);
683 | console.log('SaveSession :: addLayerToMap :: created ArcGISTiledMapServiceLayer layer = ', layer);
684 | break;
685 | default:
686 | console.log('SaveSession :: addLayerToMap :: unsupported layer type = ', layerSettings.type);
687 | break;
688 | }
689 |
690 | if (layerSettings.name) {
691 | layer.name = layerSettings.name;
692 | }
693 |
694 | // The bottom most layer has an index of 0.
695 | this.map.addLayer(layer, layerSettings.order);
696 | console.log('SaveSession :: addLayerToMap :: created layer for ', layer.id, ' using settings = ', layerSettings);
697 | return layer;
698 | },
699 |
700 | /**
701 | * returns the session object for the current map
702 | * @returns {Object} map settings for session
703 | */
704 | getSettingsForCurrentMap: function () {
705 |
706 | var settings = {
707 | name: "",
708 | webmapId: "",
709 | extent: null,
710 | layers: [],
711 | graphics: []
712 | };
713 |
714 | settings.extent = this.map.extent;
715 | settings.webmapId = this.map.itemId;
716 |
717 | settings.graphics = this.getGraphicsForCurrentMap();
718 |
719 | // have to use async to get layers
720 | this.getLayerSettingsForCurrentMap().then(function (layerSettings) {
721 | settings.layers = layerSettings;
722 | console.log('SaveSession :: getSettingsForCurrentMap :: layerSettings completed = ', layerSettings);
723 | }, function (err) {
724 | var msg = new Message({
725 | message: string.substitute("An error getting the layers from the current map."),
726 | type: 'error'
727 | });
728 | });
729 |
730 | return settings;
731 | },
732 |
733 | /**
734 | * async return the settings for the current layers on the map
735 | * @returns {Array} returns an array of layers defs to save
736 | */
737 | getLayerSettingsForCurrentMap: function () {
738 | var def = new Deferred();
739 | this.getLayerObjectsFromMap().then(lang.hitch(this, function (result) {
740 | console.log('SaveSession :: getLayerSettingsForCurrentMap :: layersObects = ', result);
741 | try {
742 | var settings = [],
743 | layerSettings,
744 | maxIndex = result.layerObjects.length;
745 | array.forEach(result.layerObjects, function (layer, idx) {
746 | // layer settings uses layerId as property name
747 | layerSettings = this.getSettingsForLayer(layer);
748 | layerSettings.order = maxIndex - idx; // The bottom most layer has an index of 0. so reverse order
749 | settings.push(layerSettings);
750 | }, this);
751 |
752 | def.resolve(settings);
753 | } catch (err) {
754 | console.error('SaveSession :: getLayerSettingsForCurrentMap :: error getting layersObects = ', err);
755 | def.reject(err);
756 | }
757 |
758 | }), lang.hitch(this, function (err) {
759 | console.error('SaveSession :: getLayerSettingsForCurrentMap :: error getting layersObects = ', err);
760 | def.reject(err);
761 | }));
762 |
763 | return def.promise;
764 | },
765 |
766 | /**
767 | * return the settings to store for the given layer
768 | * @param {esri.layers.Layer} layer the layer to get the settings for
769 | * @returns {Object} the settings object to store for the given layer
770 | */
771 | getSettingsForLayer: function (layer) {
772 | var layerSettings = {
773 | id: layer.id,
774 | name: layer.name,
775 | type: "",
776 | isVisible: layer.visible,
777 | visibleLayers: layer.visibleLayers || null,
778 | url: layer.url,
779 | options: null
780 | };
781 |
782 | layerSettings.type = this.getLayerType(layer);
783 |
784 | switch (layerSettings.type) {
785 | case "ArcGISDynamicMapServiceLayer":
786 | layerSettings.options = this.getOptionsForDynamicLayer(layer);
787 | break;
788 | case "FeatureLayer":
789 | layerSettings.options = this.getOptionsForFeatureLayer(layer);
790 | console.log('SaveSession :: getSettingsForLayer :: added options for feature layer = ', layerSettings);
791 | break;
792 | case "ArcGISTiledMapServiceLayer":
793 | layerSettings.options = this.getOptionsForTiledLayer(layer);
794 | console.log('SaveSession :: getSettingsForLayer :: added options for tiled layer = ', layerSettings);
795 | break;
796 |
797 | default:
798 | console.log('SaveSession :: getSettingsForLayer :: no options for layer type = ', layerSettings.type);
799 | break;
800 | }
801 |
802 | console.log('SaveSession :: getSettingsForCurrentMap :: settings ', layerSettings, ' added for layer = ', layer.id);
803 | return layerSettings;
804 | },
805 |
806 | /**
807 | * return the options object to create the given layer
808 | * @param {esri.layers.ArcGISDynamicMapServiceLayer} layer the ArcGISDynamicMapServiceLayer
809 | * @returns {Object} Object with properties for the ArcGISDynamicMapServiceLayer constructor
810 | */
811 | getOptionsForDynamicLayer: function (layer) {
812 | var ip,
813 | options = {
814 | id: layer.id,
815 | imageParameters: null,
816 | opacity: layer.opacity,
817 | refreshInterval: layer.refreshInterval,
818 | visible: layer.visible
819 | };
820 |
821 | if (layer.imageFormat) {
822 | ip = {
823 | format: layer.imageFormat,
824 | dpi: layer.dpi
825 | };
826 |
827 | options.imageParameters = ip;
828 | }
829 |
830 | console.log('SaveSession :: getOptionsForDynamicLayer :: options = ', options, ' for layer = ', layer.id);
831 | return options;
832 | },
833 |
834 | /**
835 | * return the options object to create the given layer
836 | * @param {esri.layers.FeatureLayer} layer the FeatureLayer
837 | * @returns {Object} Object with properties for the FeatureLayer constructor
838 | */
839 | getOptionsForFeatureLayer: function (layer) {
840 |
841 | var options = {
842 | id: layer.id,
843 | mode: FeatureLayer.MODE_ONDEMAND,
844 | outFields: ["*"],
845 | opacity: layer.opacity,
846 | refreshInterval: layer.refreshInterval,
847 | visible: layer.visible
848 | };
849 |
850 | // TODO: get mode?
851 |
852 | console.log('SaveSession :: getOptionsForFeatureLayer :: options = ', options, ' for layer = ', layer.id);
853 | return options;
854 | },
855 |
856 | /**
857 | * return the options object to create the given layer
858 | * @param {esri.layers.ArcGISTiledMapServiceLayer} layer the Tiled layer
859 | * @returns {Object} Object with properties for the ArcGISTiledMapServiceLayer constructor
860 | */
861 | getOptionsForTiledLayer: function (layer) {
862 |
863 | var options = {
864 | id: layer.id,
865 | opacity: layer.opacity,
866 | refreshInterval: layer.refreshInterval,
867 | visible: layer.visible
868 | };
869 |
870 | console.log('SaveSession :: getOptionsForTiledLayer :: options = ', options, ' for layer = ', layer.id);
871 | return options;
872 | },
873 |
874 | /**
875 | * return all the settings for the current graphic layers
876 | * @returns {Array} array of settings objects for each graphic layer
877 | */
878 | getGraphicsForCurrentMap: function () {
879 | var settings = [],
880 | graphicLayer,
881 | layerSettings;
882 |
883 | // always add the default graphics layer
884 | layerSettings = this.getSettingsFromGraphicsLayer(this.map.graphics);
885 | settings.push(layerSettings);
886 |
887 | // save the graphics for other layers
888 | array.forEach(this.map.graphicsLayerIds, function (layerId) {
889 | graphicLayer = this.map.getLayer(layerId);
890 | if (graphicLayer.graphics.length > 0) {
891 | // if there are graphics then save the settings
892 | layerSettings = this.getSettingsFromGraphicsLayer(graphicLayer);
893 | settings.push(layerSettings);
894 | }
895 | }, this);
896 |
897 | console.log('SaveSession :: getGraphicsForCurrentMap :: settings added for graphics = ', settings);
898 | return settings;
899 | },
900 |
901 | /**
902 | * create settings object from the given graphics Layer
903 | * @param {GraphicLayer} graphicLayer a graphics layer
904 | * @returns {Object} the settings to store for the graphics layer
905 | */
906 | getSettingsFromGraphicsLayer: function (graphicLayer) {
907 | var settings = {
908 | id: graphicLayer.id,
909 | graphics: []
910 | };
911 |
912 | // set the graphics from the layer
913 | array.forEach(graphicLayer.graphics, function (g) {
914 | settings.graphics.push(g.toJson());
915 | }, this);
916 |
917 | console.log('SaveSession :: getSettingsFromGraphicsLayer :: settings ', settings, ' added for graphicLayer = ', graphicLayer);
918 | return settings;
919 | },
920 |
921 | /**
922 | * add the graphics defined in the settings to the current map
923 | * @param {Object} settings = object with property for each graphic layer
924 | */
925 | setGraphicsOnCurrentMap: function (settings) {
926 | var propName = "",
927 | settingsForLayer,
928 | graphicsLayer,
929 | addGraphicsToLayer;
930 |
931 | // helper function to add all graphics defined in the settings to the given graphics layer
932 | addGraphicsToLayer = function (graphicsLayer, settingsForLayer) {
933 | // add to default graphics layer
934 | array.forEach(settingsForLayer.graphics, function (g) {
935 | var graphic = new Graphic(g);
936 | graphicsLayer.add(graphic);
937 | }, this);
938 | };
939 |
940 | array.forEach(settings, function (settingsForLayer, i) {
941 | if (settingsForLayer.id === "map_graphics") {
942 | // already exists by default so add graphics
943 | addGraphicsToLayer(this.map.graphics, settingsForLayer);
944 | } else {
945 | // add a new layer
946 | graphicsLayer = new GraphicsLayer({
947 | id: settingsForLayer.id
948 | });
949 |
950 | // add the graphics layer at the index - The bottom most layer has an index of 0.
951 | //var idx = i - 1; // adjust to account for default map graphics at first index in settings
952 | // adds the graphiclayers on top of other layers, since index not specified
953 | this.map.addLayer(graphicsLayer);
954 |
955 | addGraphicsToLayer(graphicsLayer, settingsForLayer);
956 | }
957 | }, this);
958 |
959 | console.log("SaveSession :: setGraphicsOnCurrentMap :: graphics added to the map");
960 | },
961 |
962 | clearAllGraphicsOnMap: function () {
963 | // clear the default layer
964 | this.map.graphics.clear();
965 |
966 | // remove the other graphics layers
967 | array.forEach(this.map.graphicsLayerIds, function (layerId) {
968 | var layer = this.map.getLayer(layerId);
969 | this.map.removeLayer(layer);
970 | }, this);
971 | console.log("SaveSession :: clearAllGraphicsOnMap :: graphics removed from the map");
972 | },
973 |
974 | /**
975 | * save the current sessions to local storage
976 | */
977 | storeSessions: function () {
978 | var stringToStore = JSON.stringify(this.sessions);
979 | localStorage.setItem(this.storageKey, stringToStore);
980 | console.log("SaveSession :: storeSessions :: completed");
981 | },
982 |
983 | /**
984 | * read the saved sessions from storage
985 | */
986 | loadSavedSessionsFromStorage: function () {
987 | var storedString = "",
988 | storedSessions = null;
989 |
990 | storedString = localStorage.getItem("sessions");
991 | if (!storedString) {
992 | console.log("SaveSession :: loadSavedSessionsFromStorage : no stored sessions to load");
993 | return;
994 | }
995 |
996 | storedSessions = JSON.parse(storedString);
997 | console.log("SaveSession :: loadSavedSessionsFromStorage : sessions found ", storedSessions);
998 |
999 | // replace to current sessions
1000 | this.sessions = storedSessions;
1001 | console.log("SaveSession :: loadSavedSessionsFromStorage : end");
1002 | },
1003 |
1004 | getLayerObjectsFromMap: function () {
1005 | return LayerInfos.getInstance(this.map, this.map.itemInfo).then(function (layerInfosObject) {
1006 | var layerInfos = [],
1007 | defs = [];
1008 | /*
1009 | layerInfosObject.traversal(function (layerInfo) {
1010 | layerInfos.push(layerInfo);
1011 | });
1012 | */
1013 | layerInfos = layerInfosObject.getLayerInfoArray();
1014 |
1015 | defs = array.map(layerInfos, function (layerInfo) {
1016 | return layerInfo.getLayerObject();
1017 | });
1018 | return all(defs).then(function (layerObjects) {
1019 | var resultArray = [];
1020 | array.forEach(layerObjects, function (layerObject, i) {
1021 | layerObject.id = layerObject.id || layerInfos[i].id;
1022 | resultArray.push(layerObject);
1023 | });
1024 | return {
1025 | layerInfosObject: layerInfosObject,
1026 | layerInfos: layerInfos,
1027 | layerObjects: resultArray
1028 | };
1029 | });
1030 | });
1031 | },
1032 |
1033 | /**
1034 | * returns the last part of the declaredClass for the given layer object
1035 | * @param {esri.layers.Layer} layer the map layer object
1036 | * @returns {String} the layer type
1037 | */
1038 | getLayerType: function (layer) {
1039 |
1040 | var layerTypeArray = [],
1041 | layerType = "";
1042 |
1043 | if (!layer) {
1044 | return "";
1045 | }
1046 |
1047 | layerTypeArray = layer.declaredClass.split(".");
1048 | layerType = layerTypeArray[layerTypeArray.length - 1];
1049 | return layerType;
1050 | }
1051 |
1052 | });
1053 | });
--------------------------------------------------------------------------------
/config.json:
--------------------------------------------------------------------------------
1 | {
2 | "useServerToDownloadFile": false,
3 | "saveToFileUrl": "",
4 | "fileNameForAllSessions": "COGMAP_Sessions.json",
5 | "fileNameTplForSession": "COGMAP_Sessions_${name}.json"
6 | }
--------------------------------------------------------------------------------
/css/style.css:
--------------------------------------------------------------------------------
1 | div.jimu-widget-savesession .textbox {
2 | width: 250px;
3 | }
4 |
5 | div.jimu-widget-savesession .form-control {
6 | padding: 5px 0 5px 0;
7 | }
8 |
9 | div.jimu-widget-savesession .jimu-icon {
10 | margin-left: 5px;
11 | margin-right: 5px;
12 | }
13 |
14 | .jimu-icon-load {
15 | background-position: -0px -60px;
16 | width: 16px;
17 | height: 16px;
18 | }
19 |
20 | .jimu-icon-load.jimu-state-disabled {
21 | background-position: -63px -60px;
22 | width: 16px;
23 | height: 16px;
24 | }
25 |
26 | .jimu-icon-load.jimu-state-hover {
27 | background-position: -21px -60px;
28 | width: 16px;
29 | height: 16px;
30 | }
31 |
32 | .jimu-icon-load:hover {
33 | background-position: -21px -60px;
34 | width: 16px;
35 | height: 16px;
36 | }
37 |
38 | .jimu-icon-download {
39 | background-image: url("../images/download_icon.png");
40 | width: 15px;
41 | height: 16px;
42 | }
43 |
44 | .jimu-icon-download.jimu-state-disabled {
45 | background-image: url("../images/download_icon.png");
46 | width: 15px;
47 | height: 16px;
48 | }
49 |
50 | .jimu-icon-download.jimu-state-hover,
51 | .jimu-icon-download:hover {
52 | background-image: url("../images/download_icon_hover.png");
53 | width: 15px;
54 | height: 16px;
55 | }
56 |
57 | div.jimu-widget-savesession .input-text {
58 | display: inline;
59 | color: silver;
60 | }
61 |
62 | .jimu-widget-savesession .help-text {
63 | color: silver;
64 | }
65 |
66 | .jimu-widget-savesession a.link-btn:visited,
67 | .jimu-widget-savesession a.link-btn {
68 | padding: 10px;
69 | color: #518dca;
70 | }
71 |
72 | .jimu-widget-savesession a.link-btn:hover {
73 | color: blue;
74 | }
75 |
76 | .jimu-widget-savesession a.link-btn.jimu-state-disabled:visited,
77 | .jimu-widget-savesession a.link-btn.jimu-state-disabled:hover,
78 | .jimu-widget-savesession a.link-btn.jimu-state-disabled {
79 | padding: 10px;
80 | color: gray;
81 | pointer-events: none;
82 | text-decoration: none;
83 | }
84 |
85 | #load-file-panel {
86 | margin-top: 10px;
87 | width: 200px;
88 | margin-left: auto;
89 | margin-right: auto;
90 | }
--------------------------------------------------------------------------------
/help/Action_Delete.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/softwhere/SaveSession-Widget/8ccfb3bdd02f94727465ac4e3149bfaafdc9e1f4/help/Action_Delete.png
--------------------------------------------------------------------------------
/help/Action_Download.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/softwhere/SaveSession-Widget/8ccfb3bdd02f94727465ac4e3149bfaafdc9e1f4/help/Action_Download.png
--------------------------------------------------------------------------------
/help/Action_Edit.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/softwhere/SaveSession-Widget/8ccfb3bdd02f94727465ac4e3149bfaafdc9e1f4/help/Action_Edit.png
--------------------------------------------------------------------------------
/help/Action_Load.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/softwhere/SaveSession-Widget/8ccfb3bdd02f94727465ac4e3149bfaafdc9e1f4/help/Action_Load.png
--------------------------------------------------------------------------------
/help/Configure-icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/softwhere/SaveSession-Widget/8ccfb3bdd02f94727465ac4e3149bfaafdc9e1f4/help/Configure-icon.png
--------------------------------------------------------------------------------
/help/Configure.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/softwhere/SaveSession-Widget/8ccfb3bdd02f94727465ac4e3149bfaafdc9e1f4/help/Configure.png
--------------------------------------------------------------------------------
/help/InstallFolder.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/softwhere/SaveSession-Widget/8ccfb3bdd02f94727465ac4e3149bfaafdc9e1f4/help/InstallFolder.png
--------------------------------------------------------------------------------
/help/LoadFromFile.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/softwhere/SaveSession-Widget/8ccfb3bdd02f94727465ac4e3149bfaafdc9e1f4/help/LoadFromFile.png
--------------------------------------------------------------------------------
/help/SaveNewSession.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/softwhere/SaveSession-Widget/8ccfb3bdd02f94727465ac4e3149bfaafdc9e1f4/help/SaveNewSession.png
--------------------------------------------------------------------------------
/help/SaveSessionPanel.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/softwhere/SaveSession-Widget/8ccfb3bdd02f94727465ac4e3149bfaafdc9e1f4/help/SaveSessionPanel.png
--------------------------------------------------------------------------------
/help/SaveToFile.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/softwhere/SaveSession-Widget/8ccfb3bdd02f94727465ac4e3149bfaafdc9e1f4/help/SaveToFile.png
--------------------------------------------------------------------------------
/help/SessionsLoaded.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/softwhere/SaveSession-Widget/8ccfb3bdd02f94727465ac4e3149bfaafdc9e1f4/help/SessionsLoaded.png
--------------------------------------------------------------------------------
/help/icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/softwhere/SaveSession-Widget/8ccfb3bdd02f94727465ac4e3149bfaafdc9e1f4/help/icon.png
--------------------------------------------------------------------------------
/images/download_icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/softwhere/SaveSession-Widget/8ccfb3bdd02f94727465ac4e3149bfaafdc9e1f4/images/download_icon.png
--------------------------------------------------------------------------------
/images/download_icon_hover.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/softwhere/SaveSession-Widget/8ccfb3bdd02f94727465ac4e3149bfaafdc9e1f4/images/download_icon_hover.png
--------------------------------------------------------------------------------
/images/icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/softwhere/SaveSession-Widget/8ccfb3bdd02f94727465ac4e3149bfaafdc9e1f4/images/icon.png
--------------------------------------------------------------------------------
/manifest.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "SaveSession",
3 | "platform": "HTML",
4 | "version": "2.7",
5 | "wabVersion": "2.7",
6 | "author": "Softwhere Solutions",
7 | "description": "Save current map settings",
8 | "copyright": "",
9 | "license": "http://www.apache.org/licenses/LICENSE-2.0",
10 | "properties": {
11 | "inPanel": true,
12 | "hasLocale": false,
13 | "hasStyle": true,
14 | "hasConfig": true,
15 | "hasUIFile": true,
16 | "hasSettingPage": true,
17 | "hasSettingUIFile": true,
18 | "hasSettingLocale": false,
19 | "hasSettingStyle": true,
20 | "IsController": false
21 | }
22 |
23 | }
--------------------------------------------------------------------------------
/nls/strings.js:
--------------------------------------------------------------------------------
1 | define({
2 | root:({
3 |
4 | })
5 | });
6 |
--------------------------------------------------------------------------------
/release.txt:
--------------------------------------------------------------------------------
1 | v2.7 4/3/2018
2 | * support for saving sublayers
3 | * updated style.css for WAB v2.7
4 |
5 | v1.3.1 2/21/2016
6 | * do not submit the saveToFileForm if url for download is disabled
7 |
8 | v1.3.0 2/6/2016
9 | * initial release
10 |
--------------------------------------------------------------------------------
/setting/Setting.html:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/setting/Setting.js:
--------------------------------------------------------------------------------
1 | ///////////////////////////////////////////////////////////////////////////
2 | // Copyright © 2015 Softwhere Solutions. All Rights Reserved.
3 | //
4 | // Licensed under the Apache License Version 2.0 (the "License");
5 | // you may not use this file except in compliance with the License.
6 | // You may obtain a copy of the License at
7 | //
8 | // http://www.apache.org/licenses/LICENSE-2.0
9 | //
10 | // Unless required by applicable law or agreed to in writing, software
11 | // distributed under the License is distributed on an "AS IS" BASIS,
12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | // See the License for the specific language governing permissions and
14 | // limitations under the License.
15 | ///////////////////////////////////////////////////////////////////////////
16 | /*global console, define, dojo */
17 | define([
18 | 'dojo/_base/declare',
19 | 'jimu/BaseWidgetSetting',
20 | 'dijit/_WidgetsInTemplateMixin',
21 | "dojo/_base/lang",
22 | 'dojo/on',
23 | 'dojo/json',
24 | 'dojo/Deferred',
25 | "dojo/dom-style",
26 | "dojo/dom-attr",
27 | 'jimu/dijit/Message',
28 | 'dijit/form/ValidationTextBox',
29 | 'jimu/dijit/CheckBox'
30 | ],
31 | function (
32 | declare,
33 | BaseWidgetSetting,
34 | _WidgetsInTemplateMixin,
35 | lang,
36 | on,
37 | dojoJSON,
38 | Deferred,
39 | domStyle,
40 | domAttr,
41 | Message,
42 | ValidationTextBox,
43 | CheckBox
44 | ) {
45 | return declare([BaseWidgetSetting, _WidgetsInTemplateMixin], {
46 |
47 | baseClass: 'jimu-widget-savesession-setting',
48 |
49 | startup: function () {
50 | this.inherited(arguments);
51 | this.setConfig(this.config);
52 | },
53 |
54 | setConfig: function (config) {
55 | this.config = config;
56 |
57 | if (config.useServerToDownloadFile) {
58 | this.shouldUseServerToDownloadFile.setValue(true);
59 | }
60 |
61 | if (config.saveToFileUrl) {
62 | this.saveToFileUrl.set('value', config.saveToFileUrl);
63 | }
64 |
65 | if (config.fileNameForAllSessions) {
66 | this.fileNameForAllSessions.set('value', config.fileNameForAllSessions);
67 | }
68 | if (config.fileNameTplForSession) {
69 | this.fileNameTplForSession.set('value', config.fileNameTplForSession);
70 | }
71 | },
72 |
73 | getConfig: function () {
74 | this.config.useServerToDownloadFile = this.shouldUseServerToDownloadFile.getValue();
75 | this.config.saveToFileUrl = this.saveToFileUrl.get('value');
76 | this.config.fileNameForAllSessions = this.fileNameForAllSessions.get('value');
77 | this.config.fileNameTplForSession = this.fileNameTplForSession.get('value');
78 | return this.config;
79 | }
80 | });
81 | });
--------------------------------------------------------------------------------
/setting/css/style.css:
--------------------------------------------------------------------------------
1 | .jimu-widget-savesession-setting {
2 | margin: 0;
3 | padding: 0;
4 | font-size: 15px;
5 | }
6 |
7 | .jimu-widget-savesession-setting .dijitArrowButtonContainer {
8 | width: 17px;
9 | }
10 |
11 | .jimu-widget-savesession-setting .setting-table > thead > tr > th,
12 | .jimu-widget-savesession-setting .setting-table > tbody > tr > td {
13 | height: 40px;
14 | line-height: 40px;
15 | vertical-align: middle;
16 | }
17 |
18 | .jimu-widget-savesession-setting .input-table > tbody > tr > .first {
19 | width: auto;
20 | text-align: right;
21 | padding-right: 15px;
22 | min-width: 200px;
23 | vertical-align: top;
24 | }
25 |
26 | .jimu-widget-savesession-setting .input-table > tbody > tr > .second {
27 | width: 650px;
28 | }
29 |
30 | .jimu-widget-savesession-setting .help-text {
31 | color: silver;
32 | line-height: 20px;
33 | }
--------------------------------------------------------------------------------