Wiki zdrojový kód pre VelocityMacros
Naposledy upravil Admin-metais MetaIS 2025/05/28 21:41
Show last authors
author | version | line-number | content |
---|---|---|---|
1 | {{velocity output="false"}} | ||
2 | #set ($LONG_MAX_VALUE = $mathtool.pow(2,63)) | ||
3 | #set ($licensorId = 'com.xwiki.licensing:application-licensing-licensor-api') | ||
4 | #set ($licensingConfigDoc = $xwiki.getDocument('Licenses.Code.LicensingConfig')) | ||
5 | #set ($storeBuyURL = $licensingConfigDoc.storeBuyURL) | ||
6 | #set ($storeAccessURL = $licensingConfigDoc.storeAccessURL) | ||
7 | #set ($ownerObj = $licensingConfigDoc.getObject('Licenses.Code.LicensingOwnerClass')) | ||
8 | #set ($userCount = $services.licensing.licensor.userCount) | ||
9 | |||
10 | #macro (getPaidExtensions) | ||
11 | #set ($paidExtensionsByNamespace = $services.extension.installed.getBackwardDependencies($licensorId)) | ||
12 | #set ($paidExtensions = $collectiontool.set) | ||
13 | #foreach ($paidExtensionsOnNamespace in $paidExtensionsByNamespace.values()) | ||
14 | #set ($discard = $paidExtensions.addAll($paidExtensionsOnNamespace)) | ||
15 | #end | ||
16 | #end | ||
17 | |||
18 | #macro (getVisiblePaidExtensions) | ||
19 | #getPaidExtensions | ||
20 | #set ($mandatoryExtensions = $services.licensing.licensor.getLicensedExtensionManager().getMandatoryLicensedExtensions()) | ||
21 | #set ($visiblePaidExtensions = $collectiontool.set) | ||
22 | #foreach ($paidExtension in $paidExtensions) | ||
23 | #if ($mandatoryExtensions.contains($paidExtension.getId())) | ||
24 | #set ($discard = $visiblePaidExtensions.add($paidExtension)) | ||
25 | #end | ||
26 | #end | ||
27 | #end | ||
28 | |||
29 | #macro (getLicensesAdminSectionURL) | ||
30 | ## We target the main wiki explicitly because licenses are managed globally. | ||
31 | #if ($xwiki.exists($services.model.createDocumentReference($xcontext.mainWikiName, 'XWiki', 'ConfigurableClass'))) | ||
32 | $xwiki.getURL($services.model.createDocumentReference($xcontext.mainWikiName, 'XWiki', 'XWikiPreferences'), | ||
33 | 'admin', 'editor=globaladmin§ion=Licenses')## | ||
34 | #else | ||
35 | ## Fall-back in case the Administration Application is not installed. | ||
36 | $xwiki.getURL($services.model.createDocumentReference($xcontext.mainWikiName, 'Licenses', 'WebHome'))## | ||
37 | #end | ||
38 | #end | ||
39 | |||
40 | #macro (getInstanceIdFormField) | ||
41 | <dt> | ||
42 | <label for="instanceId">$services.localization.render('licensor.ownerDetails.instanceId.label')</label> | ||
43 | <span class="xHint">$services.localization.render('licensor.ownerDetails.instanceId.hint')</span> | ||
44 | </dt> | ||
45 | <dd> | ||
46 | #getInstanceIdInput(false) | ||
47 | </dd> | ||
48 | #end | ||
49 | |||
50 | #macro (getInstanceIdInput $hidden) | ||
51 | #set ($type = 'text') | ||
52 | #if ($hidden) | ||
53 | #set ($type = 'hidden') | ||
54 | #end | ||
55 | <input type="$type" name="instanceId" id="instanceId" value="${services.instance.getInstanceId()}" readonly /> | ||
56 | #end | ||
57 | |||
58 | #macro (getOwnerFormFields) | ||
59 | #foreach ($prop in $ownerObj.properties) | ||
60 | <dt> | ||
61 | <label for="${prop.name}">$services.localization.render("licensor.ownerDetails.${prop.name}.label")</label> | ||
62 | #set ($hintTranslationKey = "licensor.ownerDetails.${prop.name}.hint") | ||
63 | #set ($hint = $services.localization.render($hintTranslationKey)) | ||
64 | #if ($hint != $hintTranslationKey) | ||
65 | <span class="xHint">$!escapetool.xml($hint)</span> | ||
66 | #end | ||
67 | </dt> | ||
68 | #set ($inputType = 'text') | ||
69 | #if ($prop.name == 'email') | ||
70 | #set ($inputType = 'email') | ||
71 | #end | ||
72 | <dd><input type="$inputType" name="${prop.name}" id="${prop.name}" value="$!{prop.value}" /></dd> | ||
73 | #end | ||
74 | #end | ||
75 | |||
76 | #macro (displayOwnerDetailsForm) | ||
77 | {{html clean=false}} | ||
78 | <form id="ownerDetails" target="_blank" class="xform half" action="${storeBuyURL}" method="post"> | ||
79 | <fieldset class="header"> | ||
80 | <legend>$services.localization.render('licensor.ownerDetails.heading')</legend> | ||
81 | <p>$services.localization.render('licensor.ownerDetails.hint')</p> | ||
82 | <input type="hidden" name="form_token" value="$!escapetool.xml($services.csrf.token)" /> | ||
83 | <dl> | ||
84 | #getOwnerFormFields | ||
85 | #getInstanceIdFormField | ||
86 | </dl> | ||
87 | </fieldset> | ||
88 | </form> | ||
89 | {{/html}} | ||
90 | #end | ||
91 | |||
92 | #macro (licenseButton $licenseType $cssClass $iconName $key $jsonData) | ||
93 | #set ($jsonData.licenseType = $licenseType) | ||
94 | #set ($label = $escapetool.xml($services.localization.render("licensor.${key}License.label"))) | ||
95 | <a href="#$escapetool.xml($key)" class="action licenseButton licenseButton-$escapetool.xml($key)" | ||
96 | data-button="$escapetool.xml($jsontool.serialize($jsonData))" title="$label"> | ||
97 | <span class="action-icon"><span class="fa fa-$iconName"></span></span>## | ||
98 | <span class="action-label">$label</span> | ||
99 | </a> | ||
100 | #end | ||
101 | |||
102 | #macro (autoUpgradeButton $extensionId) | ||
103 | #set ($licensingConfigDoc = $xwiki.getDocument('Licenses.Code.LicensingConfig')) | ||
104 | #set ($autoUpgradesObj = $licensingConfigDoc.getObject('Licenses.Code.AutomaticUpgradesClass')) | ||
105 | #set ($isAutoUpgrade = $autoUpgradesObj.getValue('allowlist').contains($extensionId)) | ||
106 | #set ($upgradeL10nKey = "#if ($isAutoUpgrade)prevent#{else}allow#end") | ||
107 | <div class="btn-group"> | ||
108 | <form target="_blank" class="xform half"> | ||
109 | <input type="hidden" name="form_token" value="$!escapetool.xml($services.csrf.token)" /> | ||
110 | <input type="hidden" name="extensionId" value="$!escapetool.xml($extensionId)" /> | ||
111 | <input type="hidden" name="autoUpgrade" value="$!escapetool.xml($isAutoUpgrade)" /> | ||
112 | <a href="#autoUpgrade" class="action licenseButton-autoUpgrade" title="$escapetool.xml( | ||
113 | $services.localization.render("licensor.moreActions.autoUpgrade.${upgradeL10nKey}"))" > | ||
114 | <span class="action-icon #if ($isAutoUpgrade)isAutoUpgrade#end"> | ||
115 | <span class="fa fa-cloud-download"></span>## | ||
116 | </span><span class="action-label">$escapetool.xml( | ||
117 | $services.localization.render('licensor.moreActions.autoUpgrade.label')) | ||
118 | </span> | ||
119 | </a> | ||
120 | </form> | ||
121 | </div> | ||
122 | #end | ||
123 | |||
124 | #macro(feedbackButton $extension) | ||
125 | #set ($licensingConfigDoc = $xwiki.getDocument('Licenses.Code.LicensingConfig')) | ||
126 | #set ($jsonData = { | ||
127 | 'featureId': $extension.id.id, | ||
128 | 'extensionVersion': $extension.id.version.toString(), | ||
129 | 'storeFeedbackURL': $licensingConfigDoc.storeFeedbackURL | ||
130 | }) | ||
131 | #licenseButton('' 'primary' 'comment' 'feedback' $jsonData) | ||
132 | #end | ||
133 | |||
134 | #macro (getLicenseActions $license $extension $actions) | ||
135 | ## Use the JSON format in order to be parsable in JavaScript. | ||
136 | #set ($jsonData = { | ||
137 | 'featureId': $extension.id.id, | ||
138 | 'extensionVersion': $extension.id.version.toString(), | ||
139 | 'userCount': $userCount | ||
140 | }) | ||
141 | #if (!$license || $license.expirationDate == 0) | ||
142 | ## No license available. | ||
143 | #set ($discard = $actions.add("#licenseButton('PAID' 'success' 'shopping-cart' 'paid' $jsonData)")) | ||
144 | #set ($discard = $actions.add("#licenseButton('TRIAL' 'primary' 'hourglass-start' 'trial' $jsonData)")) | ||
145 | #elseif ($license.type == 'FREE') | ||
146 | #set ($discard = $actions.add("#licenseButton('PAID' 'success' 'shopping-cart' 'paid' $jsonData)")) | ||
147 | #elseif ($license.type == 'TRIAL') | ||
148 | #set ($discard = $actions.add("#licenseButton('PAID' 'success' 'shopping-cart' 'paid' $jsonData)")) | ||
149 | #set ($discard = $actions.add("#licenseButton('TRIAL' 'primary' 'hourglass-end' 'extendTrial' $jsonData)")) | ||
150 | #elseif ($license.type == 'PAID') | ||
151 | #set ($discard = $actions.add("#licenseButton('PAID' 'success' 'shopping-cart' 'extendPaid' $jsonData)")) | ||
152 | #end | ||
153 | #end | ||
154 | |||
155 | #macro (licenseActions $license $extension) | ||
156 | #set ($actions = []) | ||
157 | ## Pull the resources needed by license actions. | ||
158 | #set ($discard = $services.icon.use('Font Awesome')) | ||
159 | #getLicenseActions($license $extension $actions) | ||
160 | <div class="licenseActions container-fluid"> | ||
161 | <div class="row"> | ||
162 | $stringtool.join($actions, '') | ||
163 | </div> | ||
164 | <div class="row"> | ||
165 | #autoUpgradeButton($extension.id.id) | ||
166 | #feedbackButton($extension) | ||
167 | </div> | ||
168 | </div> | ||
169 | #end | ||
170 | |||
171 | #macro(webmecanikForm $webmecanikID) | ||
172 | <div class="webmecanikForm"> | ||
173 | <input type="hidden" name="webmecanikID" value="${webmecanikID}"> | ||
174 | ## This is the recommended way for automatically inserting a form from Webmecanik using Mautic. | ||
175 | <script type="text/javascript" src="\/\/news.xwiki.com/form/generate.js?id=${webmecanikID}"></script> | ||
176 | </div> | ||
177 | #end | ||
178 | |||
179 | #macro(feedbackForm) | ||
180 | {{html clean="false" wiki="true"}} | ||
181 | <div class="modal fade" id="feedbackFormModal" tabindex="-1" role="dialog" aria-labelledby="feedbackFormModal-label"> | ||
182 | <div class="modal-dialog" role="document"> | ||
183 | <div class="modal-content"> | ||
184 | <div class="modal-header"> | ||
185 | <button type="button" class="close" data-dismiss="modal" aria-label="Close"> | ||
186 | <span aria-hidden="true">×</span> | ||
187 | </button> | ||
188 | <div class="modal-title" id="feedbackFormModal-label"> | ||
189 | $escapetool.xml($services.localization.render('licensor.feedbackLicense.title')) | ||
190 | </div> | ||
191 | </div> | ||
192 | <div class="modal-body"> | ||
193 | ## This is the Pro Apps feedback form ID from Webmecanik. | ||
194 | #set ($webmecanikID = '89') | ||
195 | #webmecanikForm($webmecanikID) | ||
196 | </div> | ||
197 | </div> | ||
198 | </div> | ||
199 | </div> | ||
200 | {{/html}} | ||
201 | #end | ||
202 | |||
203 | #macro(installedAsDependency) | ||
204 | {{html clean="false" wiki="true"}} | ||
205 | <div class="modal fade" id="installed-as-dependency" tabindex="-1" role="dialog" aria-labelledby="installed-as-dependency-label"> | ||
206 | <div class="modal-dialog" role="document"> | ||
207 | <div class="modal-content"> | ||
208 | <div class="modal-header"> | ||
209 | <button type="button" class="close" data-dismiss="modal" aria-label="Close"> | ||
210 | <span aria-hidden="true">×</span> | ||
211 | </button> | ||
212 | <div class="modal-title" id="installed-as-dependency-label"> | ||
213 | $escapetool.xml($services.localization.render('licensor.installedAsDependency.modal.title')) | ||
214 | </div> | ||
215 | </div> | ||
216 | <div class="modal-body"> | ||
217 | $escapetool.xml($services.localization.render('licensor.installedAsDependency.modal.description')) | ||
218 | <ul class="parent-extensions"></ul> | ||
219 | $escapetool.xml($services.localization.render('licensor.installedAsDependency.modal.question')) | ||
220 | </div> | ||
221 | <div class="modal-footer"> | ||
222 | <button type="button" class="btn btn-default" data-dismiss="modal"> | ||
223 | $escapetool.xml($services.localization.render('cancel')) | ||
224 | </button> | ||
225 | <button type="button" class="btn btn-primary"> | ||
226 | $escapetool.xml($services.localization.render('licensor.installedAsDependency.modal.confirm')) | ||
227 | </button> | ||
228 | </div> | ||
229 | </div> | ||
230 | </div> | ||
231 | </div> | ||
232 | {{/html}} | ||
233 | #end | ||
234 | {{/velocity}} |