Código fuente wiki de #if($doc.fullName=='AppWithinMinutes.LiveTableEditSheet')LiveTable Edit Sheet#{else}#evaluate($doc.title)#end
Versión 2.1 por Administrator el 2024/06/05 19:09
Ocultar los últimos autores
author | version | line-number | content |
---|---|---|---|
![]() |
2.1 | 1 | {{velocity output="false"}} |
2 | #macro(listAvailableColumns) | ||
3 | {{html}} | ||
4 | <select id="availableColumns"> | ||
5 | #set($className = "$!liveTableObj.getProperty('class').value") | ||
6 | #set($classFields = $xwiki.getDocument($className).getxWikiClass().properties) | ||
7 | #set($discard = $services.localization.use('document', "$stringtool.removeEnd($className, 'Class')Translations")) | ||
8 | #if($classFields.size() > 0) | ||
9 | <optgroup label="$escapetool.xml($services.localization.render('platform.appwithinminutes.liveTableEditorClassFieldColumnGroupLabel'))" id="classFields"> | ||
10 | #foreach($field in $classFields) | ||
11 | <option value="$field.name">$escapetool.xml($field.translatedPrettyName)</option> | ||
12 | #end | ||
13 | </optgroup> | ||
14 | #end | ||
15 | <optgroup label="$escapetool.xml($services.localization.render('platform.appwithinminutes.liveTableEditorGenericColumnGroupLabel'))"> | ||
16 | #foreach($entry in $genericColumns.entrySet()) | ||
17 | <option value="$entry.key" title="$escapetool.xml($entry.value.get(1))">$escapetool.xml($entry.value.get(0))</option> | ||
18 | #end | ||
19 | </optgroup> | ||
20 | </select> | ||
21 | {{/html}} | ||
22 | #end | ||
23 | |||
24 | #macro(displayHelpPanel) | ||
25 | #set($genericColumns = { | ||
26 | 'doc.title': [$services.localization.render('platform.appwithinminutes.liveTableEditorDocTitleColumnName'), $services.localization.render('platform.appwithinminutes.liveTableEditorDocTitleColumnDescription')], | ||
27 | 'doc.name': [$services.localization.render('platform.appwithinminutes.liveTableEditorDocNameColumnName'), $services.localization.render('platform.appwithinminutes.liveTableEditorDocNameColumnDescription')], | ||
28 | 'doc.author': [$services.localization.render('platform.appwithinminutes.liveTableEditorDocAuthorColumnName'), $services.localization.render('platform.appwithinminutes.liveTableEditorDocAuthorColumnDescription')], | ||
29 | 'doc.creator': [$services.localization.render('platform.appwithinminutes.liveTableEditorDocCreatorColumnName'), $services.localization.render('platform.appwithinminutes.liveTableEditorDocCreatorColumnDescription')], | ||
30 | 'doc.date': [$services.localization.render('platform.appwithinminutes.liveTableEditorDocDateColumnName'), $services.localization.render('platform.appwithinminutes.liveTableEditorDocDateColumnDescription')], | ||
31 | 'doc.creationDate': [$services.localization.render('platform.appwithinminutes.liveTableEditorDocCreationDateColumnName'), $services.localization.render('platform.appwithinminutes.liveTableEditorDocCreationDateColumnDescription')], | ||
32 | '_actions': [$services.localization.render('platform.appwithinminutes.liveTableEditorActionsColumnName'), $services.localization.render('platform.appwithinminutes.liveTableEditorActionsColumnDescription')], | ||
33 | '_attachments': [$services.localization.render('platform.appwithinminutes.liveTableEditorAttachmentsColumnName'), $services.localization.render('platform.appwithinminutes.liveTableEditorAttachmentsColumnDescription')], | ||
34 | '_images': [$services.localization.render('platform.appwithinminutes.liveTableEditorImagesColumnName'), $services.localization.render('platform.appwithinminutes.liveTableEditorImagesColumnDescription')] | ||
35 | }) | ||
36 | (% class="wizard-help" %) | ||
37 | ((( | ||
38 | **$services.localization.render('platform.appwithinminutes.liveTableEditorHelpTitle')** $services.localization.render('platform.appwithinminutes.liveTableEditorHelpDescription') | ||
39 | |||
40 | #foreach($columnId in ['doc.name', 'doc.date', 'doc.author', '_actions']) | ||
41 | ; {{{$genericColumns.get($columnId).get(0)}}} | ||
42 | : {{{$genericColumns.get($columnId).get(1)}}} | ||
43 | #end | ||
44 | ))) | ||
45 | #end | ||
46 | |||
47 | #macro(displayFormFields) | ||
48 | {{html wiki="true"}} | ||
49 | (% class="hidden" %) | ||
50 | ((( | ||
51 | ## Make sure that only the sheet content is rendered when the class is saved using AJAX. | ||
52 | <input type="hidden" name="xpage" value="plain" /> | ||
53 | ## We prevent the class name from being edited directly. The class name can be specified in the URL. | ||
54 | $doc.display('class', 'hidden') | ||
55 | ## We have to pass the list of available columns to the JavaScript code. | ||
56 | #listAvailableColumns() | ||
57 | ))) | ||
58 | ; <label for="AppWithinMinutes.LiveTableClass_0_description">$doc.displayPrettyName('description', false, false)</label>## | ||
59 | (% class="xHint" %)$services.localization.render('platform.appwithinminutes.liveTableEditorDescriptionHint') | ||
60 | : $doc.display('description') | ||
61 | ; <label for="AppWithinMinutes.LiveTableClass_0_columns">$doc.displayPrettyName('columns', false, false)</label>## | ||
62 | (% class="xHint" %)$services.localization.render('platform.appwithinminutes.liveTableEditorColumnsHint') | ||
63 | : $doc.display('columns') | ||
64 | {{/html}} | ||
65 | #end | ||
66 | |||
67 | #macro(displayIcon) | ||
68 | #if($services.uix) | ||
69 | #set($icon = 'icon:application') | ||
70 | #foreach($uix in $services.uix.getExtensions('org.xwiki.platform.panels.Applications')) | ||
71 | #if($uix.getId() == "platform.panels.${doc.space}Application" && "$!uix.getParameters().get('icon')" != '') | ||
72 | #set($icon = $uix.getParameters().get('icon')) | ||
73 | #end | ||
74 | #end | ||
75 | {{html wiki="true"}} | ||
76 | ; <label for="applicationIcon">$services.localization.render('platform.appwithinminutes.liveTableEditorIcon')</label> | ||
77 | (% class="xHint" %)$services.localization.render('platform.appwithinminutes.liveTableEditorIconHint', | ||
78 | [$xwiki.getSkinFile('icons/silk/index_abc.png')]) | ||
79 | : <input id="applicationIcon" name="applicationIcon" type="text" size="10" value="$!escapetool.xml($icon)" /> | ||
80 | {{/html}} | ||
81 | #end | ||
82 | #end | ||
83 | |||
84 | #macro(doEdit) | ||
85 | #set($liveTableObj = $doc.getObject('AppWithinMinutes.LiveTableClass', true)) | ||
86 | #set($discard = $doc.use($liveTableObj)) | ||
87 | #set($discard = $xwiki.jsfx.use('js/scriptaculous/dragdrop.js')) | ||
88 | #set($discard = $xwiki.ssx.use('AppWithinMinutes.LiveTableEditSheet')) | ||
89 | #set($discard = $xwiki.jsx.use('AppWithinMinutes.LiveTableEditSheet')) | ||
90 | #if("$!request.wizard" == 'true') | ||
91 | #appWizardHeader(3) | ||
92 | |||
93 | #end | ||
94 | #displayHelpPanel() | ||
95 | (% class="form-body" %) | ||
96 | ((( | ||
97 | #displayFormFields() | ||
98 | |||
99 | #displayIcon() | ||
100 | |||
101 | #if("$!request.wizard" == 'true') | ||
102 | |||
103 | #appWizardFooter(3) | ||
104 | #end | ||
105 | ))) | ||
106 | {{html}}<div class="clearfloats"></div>{{/html}} | ||
107 | #end | ||
108 | |||
109 | #macro(maybeGrantSpaceAdminRight $spaceHomeRef) | ||
110 | ## Grant space administration rights only if the space is new. | ||
111 | #if(!$xwiki.exists($spaceHomeRef)) | ||
112 | #set($spacePrefsRef = $services.model.createDocumentReference($spaceHomeRef.wikiReference.name, $spaceHomeRef.lastSpaceReference.name, 'WebPreferences')) | ||
113 | #set($spacePrefsDoc = $xwiki.getDocument($spacePrefsRef)) | ||
114 | ## Don't overwrite existing space preferences. | ||
115 | #if($spacePrefsDoc.isNew()) | ||
116 | #set($discard = $spacePrefsDoc.use($spacePrefsDoc.getObject('XWiki.XWikiGlobalRights', true))) | ||
117 | #set($discard = $spacePrefsDoc.set('allow', 1)) | ||
118 | #set($discard = $spacePrefsDoc.set('levels', 'admin')) | ||
119 | #set($discard = $spacePrefsDoc.set('users', $services.model.serialize($xcontext.userReference, 'default'))) | ||
120 | #set($discard = $spacePrefsDoc.setParent($services.model.serialize($spaceHomeRef, 'default'))) | ||
121 | #set($discard = $spacePrefsDoc.setHidden(true)) | ||
122 | #set($discard = $spacePrefsDoc.saveWithProgrammingRights($services.localization.render('platform.appwithinminutes.grantSpaceAdminRightsSaveComment'))) | ||
123 | #end | ||
124 | #end | ||
125 | #end | ||
126 | |||
127 | #macro(maybeGrantSpaceAdminRights) | ||
128 | ## Data space | ||
129 | #set($dataSpaceHomeRef = $services.model.createDocumentReference($doc.wiki, $doc.space, 'WebHome')) | ||
130 | #maybeGrantSpaceAdminRight($dataSpaceHomeRef) | ||
131 | ## Code space | ||
132 | #set($className = $request.get('AppWithinMinutes.LiveTableClass_0_class')) | ||
133 | #set($classRef = $services.model.resolveDocument($className)) | ||
134 | #set($codeSpaceHomeRef = $services.model.createDocumentReference($classRef.wikiReference.name, $classRef.lastSpaceReference.name, 'WebHome')) | ||
135 | #maybeGrantSpaceAdminRight($codeSpaceHomeRef) | ||
136 | #end | ||
137 | |||
138 | #macro(updateAndSaveLiveTable) | ||
139 | #set($discard = $doc.updateObjectFromRequest('AppWithinMinutes.LiveTableClass')) | ||
140 | #set($liveTableGeneratorDoc = $xwiki.getDocument('AppWithinMinutes.LiveTableGenerator')) | ||
141 | #set($discard = $doc.setContent($doc.getRenderedContent($liveTableGeneratorDoc.content, $liveTableGeneratorDoc.syntax.toIdString(), 'plain/1.0'))) | ||
142 | #set($minorEdit = "$!request.minorEdit" != '') | ||
143 | #set($comment = $request.comment) | ||
144 | #if("$!comment" == '') | ||
145 | #set($comment = $services.localization.render('platform.appwithinminutes.liveTableEditorSaveComment')) | ||
146 | #end | ||
147 | #set($discard = $doc.save($comment, $minorEdit)) | ||
148 | #end | ||
149 | |||
150 | #macro(maybeCreateLiveTableResultsPage) | ||
151 | #set ($className = "$!doc.getObject('AppWithinMinutes.LiveTableClass').getProperty('class').value") | ||
152 | #set ($liveTableResultsDoc = $xwiki.getDocument("$!stringtool.removeEnd($className, 'Class')LiveTableResults")) | ||
153 | #set ($liveTableResultsGeneratorDoc = $xwiki.getDocument('AppWithinMinutes.LiveTableResultsGenerator')) | ||
154 | #if ($liveTableResultsDoc.isNew()) | ||
155 | #set ($discard = $liveTableResultsDoc.setParent($doc.name)) | ||
156 | #set ($discard = $liveTableResultsDoc.setHidden(true)) | ||
157 | #set ($discard = $liveTableResultsDoc.setContent($doc.getRenderedContent($liveTableResultsGeneratorDoc.content, $liveTableResultsGeneratorDoc.syntax.toIdString(), 'plain/1.0'))) | ||
158 | #set ($discard = $liveTableResultsDoc.save($services.localization.render('platform.appwithinminutes.liveTableEditorCreateLiveTableResultsComment'))) | ||
159 | #end | ||
160 | #end | ||
161 | |||
162 | #macro(updateAndSaveIcon) | ||
163 | #set($uix = $doc.getObject('XWiki.UIExtensionClass', true)) | ||
164 | #set($discard = $uix.set('name', "platform.panels.${doc.space}Application")) | ||
165 | #set($discard = $uix.set('extensionPointId', "org.xwiki.platform.panels.Applications")) | ||
166 | #set($discard = $uix.set('parameters', "label=${doc.space}${util.newline}target=${doc.fullName}${util.newline}icon=${request.applicationIcon}")) | ||
167 | #set($discard = $doc.save('Updated application icon', true)) | ||
168 | #end | ||
169 | |||
170 | #macro(doSave) | ||
171 | #maybeGrantSpaceAdminRights() | ||
172 | #updateAndSaveLiveTable() | ||
173 | #maybeCreateLiveTableResultsPage() | ||
174 | #updateAndSaveIcon() | ||
175 | #if($action == 'save') | ||
176 | #if($errorMessage) | ||
177 | {{error}}{{html}}$errorMessage{{/html}}{{/error}} | ||
178 | #else | ||
179 | ## Redirect to view mode. | ||
180 | $response.sendRedirect($doc.getURL()) | ||
181 | #end | ||
182 | #else | ||
183 | #if($errorMessage) | ||
184 | $response.sendError(400, $errorMessage) | ||
185 | #else | ||
186 | $response.setStatus(204) | ||
187 | #end | ||
188 | #end | ||
189 | #end | ||
190 | {{/velocity}} | ||
191 | |||
192 | {{velocity}} | ||
193 | #if("$!request.wizard" == 'true') | ||
194 | {{include reference="AppWithinMinutes.WizardStep" /}} | ||
195 | #end | ||
196 | {{/velocity}} | ||
197 | |||
198 | {{velocity}} | ||
199 | ## Determine the action button that triggered the request | ||
200 | #set($action = $xcontext.action) | ||
201 | #foreach($paramName in $request.getParameterMap().keySet()) | ||
202 | #if($paramName.startsWith('xaction_')) | ||
203 | #set($action = $paramName.substring(8)) | ||
204 | #break | ||
205 | #end | ||
206 | #end | ||
207 | #if($action == 'edit') | ||
208 | #doEdit() | ||
209 | #elseif($action == 'save' || $action == 'saveandcontinue') | ||
210 | #if($services.csrf.isTokenValid($request.form_token)) | ||
211 | #doSave() | ||
212 | #else | ||
213 | $response.sendRedirect($services.csrf.getResubmissionURL()); | ||
214 | #end | ||
215 | #end | ||
216 | {{/velocity}} |