Skip to content

Commit

Permalink
More Author Tools bits
Browse files Browse the repository at this point in the history
* `@copyright` structure
* Fix UI glitch with a work-around of pre-ordering and dropup class

Applies to OpenUserJS#389
  • Loading branch information
Martii committed Nov 30, 2017
1 parent b1e9f02 commit 9930181
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 3 deletions.
21 changes: 21 additions & 0 deletions controllers/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -1847,6 +1847,7 @@ exports.editScript = function (aReq, aRes, aNext) {
var installNameBase = null;
var isLib = aReq.params.isLib;
var tasks = [];
var nowDate = null;

// Session
options.authedUser = authedUser = modelParser.parseUser(authedUser);
Expand Down Expand Up @@ -1877,6 +1878,9 @@ exports.editScript = function (aReq, aRes, aNext) {
var collaborators = null;
var licenses = null;
var licensePrimary = null;
var copyrights = null;
var copyrightPrimary = null;
var sinceDate = null;

//---
if (aErr || !aScript) {
Expand All @@ -1900,6 +1904,16 @@ exports.editScript = function (aReq, aRes, aNext) {
: undefined)).replace(/\+$/, '');
}

copyrights = scriptStorage.findMeta(aScript.meta, 'UserScript.copyright.value');
if (copyrights) {
copyrightPrimary = copyrights[copyrights.length - 1];
script.copyrightPrimary = copyrightPrimary;
} else {
sinceDate = new Date(script.updatedISOFormat);
options.script.copyrightPrimary = sinceDate.getFullYear() + ', ' + authedUser.name
+ ' (https://openuserjs.org' + authedUser.userPageUrl + ')';
}

options.isOwner = authedUser && (authedUser._id == script._authorId
|| collaborators.indexOf(authedUser.name) > -1);
modelParser.renderScript(script);
Expand Down Expand Up @@ -1951,7 +1965,14 @@ exports.editScript = function (aReq, aRes, aNext) {
options.isScriptViewSourcePage = true;

options.script = {};
options.script.isLib = isLib;

options.script.licensePrimary = 'MIT'; // NOTE: Site default

nowDate = new Date();
options.script.copyrightPrimary = nowDate.getFullYear() + ', ' + authedUser.name
+ ' (https://openuserjs.org' + authedUser.userPageUrl + ')';

options.script.scriptAcceptableOSILicense = [];
SPDXOSI.forEach(function (aElement, aIndex, aArray) {
if (blockSPDX.indexOf(aElement) === -1) {
Expand Down
32 changes: 29 additions & 3 deletions views/includes/scriptAuthorToolsPanel.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@
</ul>
{{/isScriptViewSourcePage}}
{{#isScriptViewSourcePage}}

{{^script.isLib}}
<h4>UserScript Block</h4>
{{/script.isLib}}

{{^script.isLib}}
{{^newScript}}
<div class="form-group">
Expand All @@ -30,12 +35,33 @@
</div>
{{/newScript}}
{{/script.isLib}}

{{#script.isLib}}
<h4>UserScript and OpenUserJS Block</h4>
{{/script.isLib}}

<div class="form-group">
<div class="input-group col-xs-12">
<span class="input-group-btn">
<button class="btn btn-default" id="copyright-raw" data-clipboard-text="// @copyright {{script.copyrightPrimary}}" title="Copy key and raw URL to clipboard"><i class="octicon octicon-clippy"></i> // @copyright</button>
</span>
<input type="text" class="form-control" id="copyright" value="{{script.copyrightPrimary}}" readonly="readonly">
<span class="input-group-btn">
<a class="btn btn-default"
title="How do I use this?"
href="/user/add/{{#script.isLib}}lib{{/script.isLib}}{{^script.isLib}}scripts{{/script.isLib}}#user-block-copyright">
<i class="fa fa-{{#lockdown.updateURLCheck}}exclamation-triangle{{/lockdown.updateURLCheck}}{{^lockdown.updateURLCheck}}question-circle{{/lockdown.updateURLCheck}}"></i>
</a>
</span>
</div>
</div>

<div class="input-group">
<div class="input-group-btn">
<span class="input-group-btn">
<button class="btn btn-info" id="license-raw" data-clipboard-text="// @license MIT" title="Copy key and raw SPDX to clipboard"><i class="octicon octicon-clippy"></i> // @license</button>
</div>
</span>
<input id="spdx-short-id" type="text" class="form-control" aria-label="..." value="MIT" readonly="readonly">
<span class="input-group-btn">
<span class="input-group-btn dropup">
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"><img src="/images/license/osi16.png"> <span class="caret"></span> <span class="sr-only">Toggle Dropdown</span> </button>
<ul class="dropdown-menu scrollable-menu dropdown-menu-right" id="osi-spdx">
{{#script.scriptAcceptableOSILicense}}<li><a href="#">{{shortIdSPDX}}</a></li>{{/script.scriptAcceptableOSILicense}}
Expand Down
1 change: 1 addition & 0 deletions views/includes/scripts/clipboard.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
var rMin = /\.min\.js$/;

var allowedIds = [
'#copyright-raw',
'#groupid-raw',
'#groupid-urn',
'#license-raw',
Expand Down

0 comments on commit 9930181

Please sign in to comment.