Wiki source code of OpenProject
Hide last authors
| author | version | line-number | content |
|---|---|---|---|
| |
1.1 | 1 | {{velocity}} |
| 2 | #set ($currentUser = $xcontext.user) | ||
| 3 | #if ($currentUser == 'XWiki.XWikiGuest') | ||
| 4 | {{html}} | ||
| 5 | <div class="box warningmessage"> | ||
| 6 | <p>$escapetool.xml($services.localization.render('openproject.dashboard.guest'))</p> | ||
| 7 | </div> | ||
| 8 | {{/html}} | ||
| 9 | #else | ||
| 10 | #set ($configClass = 'OpenProject.Code.DashboardConnectionConfigClass') | ||
| 11 | #set ($configObj = $doc.getObject($configClass)) | ||
| 12 | #if ($hasEdit && $request.method == 'POST' && $request.action == 'saveProject' && $services.csrf.isTokenValid($request.csrf_token)) | ||
| 13 | #set ($discard = $configObj.set('selectedConnection', $request.connection)) | ||
| 14 | #set ($discard = $configObj.set('selectedProject', $request.project)) | ||
| 15 | #set ($discard = $configObj.set('selectedProjectLabel', $request.projectLabel)) | ||
| 16 | #set ($discard = $doc.save('Updated project', true)) | ||
| 17 | $response.sendRedirect($doc.getURL()) | ||
| 18 | #stop | ||
| 19 | #end | ||
| 20 | #set ($connectionOptions = $services.openproject.getConnectionOptions()) | ||
| 21 | #set ($discard = $connectionOptions.remove(0)) | ||
| 22 | #set ($selectedConnection = '') | ||
| 23 | #set ($selectedProject = '') | ||
| 24 | #set ($selectedProjectLabel = '') | ||
| 25 | #if ($configObj) | ||
| 26 | #set ($selectedConnection = $configObj.getValue('selectedConnection')) | ||
| 27 | #set ($selectedProject = $configObj.getValue('selectedProject')) | ||
| 28 | #set ($selectedProjectLabel = $configObj.getValue('selectedProjectLabel')) | ||
| 29 | #end | ||
| 30 | #set ($effectiveConnection = $selectedConnection) | ||
| 31 | #if ("$!effectiveConnection" == '' && $connectionOptions.size() > 0) | ||
| 32 | #set ($effectiveConnection = $connectionOptions.get(0).value) | ||
| 33 | #end | ||
| 34 | #set ($tokenValid = false) | ||
| 35 | #if ("$!effectiveConnection" != '' && $services.openproject.isUserAuthorized($effectiveConnection)) | ||
| 36 | #set ($tokenValid = true) | ||
| 37 | #end | ||
| 38 | {{html clean="false"}} | ||
| 39 | #if ($connectionOptions.size() == 0) | ||
| 40 | <div class="box warningmessage"> | ||
| 41 | <p>$escapetool.xml($services.localization.render('openproject.dashboard.selectConnection.noConnections'))</p> | ||
| 42 | </div> | ||
| 43 | #else | ||
| 44 | #if ($hasEdit) | ||
| 45 | <form id="openproject-dashboard-project-form" method="post" class="withLock xform" action=""> | ||
| 46 | <div class="form-group"> | ||
| 47 | <label for="openproject-dashboard-connection-select">$escapetool.xml($services.localization.render('openproject.dashboard.selectConnection.label'))</label> | ||
| 48 | <select id="openproject-dashboard-connection-select" name="connection" class="form-control" | ||
| 49 | #if($connectionOptions.size() == 1) disabled #end> | ||
| 50 | #foreach ($option in $connectionOptions) | ||
| 51 | <option value="$option.value" #if($effectiveConnection == $option.value) selected #end>$escapetool.xml($option.name)</option> | ||
| 52 | #end | ||
| 53 | </select> | ||
| 54 | #if ($connectionOptions.size() == 1) | ||
| 55 | <input type="hidden" name="connection" value="$!escapetool.xml($effectiveConnection)"/> | ||
| 56 | #end | ||
| 57 | </div> | ||
| 58 | ## The project picker is only useful once the connection is authorized. | ||
| 59 | #if ($tokenValid) | ||
| 60 | <div class="form-group"> | ||
| 61 | <label for="openproject-dashboard-project-select">$escapetool.xml($services.localization.render('openproject.dashboard.selectProject.label'))</label> | ||
| 62 | <select id="openproject-dashboard-project-select" name="project" class="form-control" | ||
| 63 | data-connection="$!escapetool.xml($effectiveConnection)" | ||
| 64 | data-placeholder="$escapetool.xml($services.localization.render('openproject.dashboard.selectProject.placeholder'))"> | ||
| 65 | #if ("$!selectedProject" != '') | ||
| 66 | <option value="$!escapetool.xml($selectedProject)" selected="selected">$!escapetool.xml($selectedProjectLabel)</option> | ||
| 67 | #end | ||
| 68 | </select> | ||
| 69 | <input type="hidden" name="projectLabel" id="openproject-dashboard-project-label-input"/> | ||
| 70 | </div> | ||
| 71 | #end | ||
| 72 | <input type="hidden" name="csrf_token" value="${escapetool.xml($services.csrf.token)}"/> | ||
| 73 | <input type="hidden" name="action" value="saveProject"/> | ||
| 74 | </form> | ||
| 75 | #end | ||
| 76 | ## Carries the effective connection to the JS for users without pickers (no connection select). | ||
| 77 | <span id="openproject-dashboard-data" class="hidden" data-connection="$!escapetool.xml($effectiveConnection)"></span> | ||
| 78 | ## The current user has no token for this connection: show the (per-user) authorize warning. | ||
| 79 | #if (!$tokenValid) | ||
| 80 | #set ($notAuthorized = $services.openproject.getNotAuthorizedMessage($effectiveConnection, 'html/5.0')) | ||
| 81 | #if ("$!notAuthorized" != '') | ||
| 82 | $notAuthorized | ||
| 83 | #end | ||
| 84 | #end | ||
| 85 | ## Warnings revealed by the JS (invalid/expired connection, or connection without any projects). | ||
| 86 | <div id="openproject-dashboard-invalid-connection" class="box warningmessage hidden"> | ||
| 87 | <p>$escapetool.xml($services.localization.render('openproject.dashboard.selectProject.invalidConnection', [$effectiveConnection]))</p> | ||
| 88 | </div> | ||
| 89 | <div id="openproject-dashboard-no-project" class="box warningmessage hidden"> | ||
| 90 | <p>$escapetool.xml($services.localization.render('openproject.dashboard.noProject'))</p> | ||
| 91 | </div> | ||
| 92 | #end | ||
| 93 | {{/html}} | ||
| 94 | ## Render the macros (hidden) only when the current user is authorized for the connection; the project | ||
| 95 | ## is defaulted transiently by the listener. The JS reveals them once it confirms the connection works. | ||
| 96 | #if ("$!effectiveConnection" != '' && $tokenValid) | ||
| 97 | (% id="openproject-dashboard-gadgets" class="hidden" %)((( | ||
| 98 | {{dashboard/}} | ||
| 99 | ))) | ||
| 100 | #end | ||
| 101 | #end | ||
| 102 | {{/velocity}} |