20 var magicNumberNoLicenseFoundInt = 507;
21 var magicNumberNoLicenseFound =
"507";
22 var noLicenseString =
"No_license_found";
25 function jsArrayFromHtmlOptions(pListBox) {
26 var options =
new Array(pListBox.options.length);
27 for (var i = 0; i < options.length; i++) {
28 if (pListBox.options[i].value === magicNumberNoLicenseFound) {
31 options[i] = pListBox.options[i];
36 function htmlOptionsFromJsArray(pListBox, options) {
37 pListBox.options.length = 0;
38 if(options===undefined) {
return;
40 for (var i = 0; i < options.length; i++) {
41 if(options[i]===undefined) {
continue;
43 pListBox.options[i] = options[i];
47 function sortLicenseList(pListBox) {
48 var options = jsArrayFromHtmlOptions(pListBox);
49 options.sort(compareText);
50 if (options.length == 0) {
51 options[0] = (
new Option(noLicenseString, magicNumberNoLicenseFound));
53 htmlOptionsFromJsArray(pListBox, options);
56 function compareText(opt1, opt2) {
57 return opt1.text < opt2.text ? -1 : opt1.text > opt2.text ? 1 : 0;
60 function moveLicense(theSelFrom, theSelTo) {
61 var selLength = theSelFrom.length;
62 for (var i = selLength - 1; i >= 0; i--) {
63 if (theSelFrom.options[i].selected) {
64 theSelTo.appendChild(theSelFrom.options[i].cloneNode(
true));
69 sortLicenseList(theSelFrom);
70 sortLicenseList(theSelTo);
74 function selectNoLicenseFound(left, right) {
75 var selLength = right.length;
77 for (i = selLength - 1; i >= 0; i--) {
78 left.options[left.options.length] = (
new Option(right.options[i].text, right.options[i].value));
81 selLength = left.length;
82 for (i = selLength - 1; i >= 0; i--) {
83 if (left.options[i].value == magicNumberNoLicenseFound) {
87 right.options[right.options.length] = (
new Option(noLicenseString, magicNumberNoLicenseFound));
92 function scheduledDeciderSuccess (data, resultEntity, callbackSuccess, callbackCloseModal) {
95 resultEntity.html(
"scan scheduled as " + linkToJob(jqPk));
96 if (callbackSuccess) {
97 queueUpdateCheck(jqPk, callbackSuccess);
101 resultEntity.html(
"bad response from server");
106 function scheduledDeciderError (responseobject, resultEntity) {
107 var error = responseobject.responseJSON.error;
109 resultEntity.text(
"error: " + error);
111 resultEntity.text(
"error");
116 function isUserError(bulkActions, refText) {
118 if(bulkActions.length < 1) {
119 errorText +=
"No licenses to bulk scan selected\n";
122 if(refText.trim().split(
" ").length < 2) {
123 errorText +=
"Reference text needs to be at least 2 words long" 127 if(errorText.length > 0) {
128 alert(
"Bulk scan not scheduled: \n\n"+errorText);
134 function scheduleBulkScanCommon(resultEntity, callbackSuccess) {
135 var bulkActions = getBulkFormTableContent();
136 var refText = $(
'#bulkRefText').val();
138 for (i = 0; i < bulkActions.length; i++) {
139 bulkActions[i][
"reportinfo"] = $(
"#"+bulkActions[i].licenseId+
"reportinfoBulk").attr(
'title');
140 bulkActions[i][
"acknowledgement"] = $(
"#"+bulkActions[i].licenseId+
"acknowledgementBulk").attr(
'title');
141 bulkActions[i][
"comment"] = $(
"#"+bulkActions[i].licenseId+
"commentBulk").attr(
'title');
145 if(isUserError(bulkActions, refText)) {
150 "bulkAction": bulkActions,
152 "bulkScope": $(
'#bulkScope').val(),
153 "uploadTreeId": $(
'#uploadTreeId').val(),
154 "forceDecision": $(
'#forceDecision').is(
':checked')?1:0
161 url:
"?mod=change-license-bulk",
163 success:
function(data) { scheduledDeciderSuccess(data, resultEntity, callbackSuccess, closeBulkModal); },
164 error:
function(responseobject) { scheduledDeciderError(responseobject, resultEntity); }
169 function performPostRequestCommon(resultEntity, callbackSuccess) {
171 $(
'#licenseRight option').each(
function () {
172 txt.push(this.value);
176 "licenseNumbersToBeSubmitted": txt,
177 "uploadTreeId": $(
'#uploadTreeId').val(),
183 url:
"?mod=change-license-processPost",
185 success:
function (data) { scheduledDeciderSuccess(data,resultEntity, callbackSuccess, closeUserModal); },
186 error:
function(responseobject) { scheduledDeciderError(responseobject, resultEntity); }
191 function popUpLicenseText(popUpUri, title) {
192 sel = $(
"#bulkLicense :selected").val();
193 window.open(popUpUri + sel, title,
'width=600,height=400,toolbar=no,scrollbars=yes,resizable=yes');
196 function modifyLicense(doWhat ,uploadId, uploadTreeId, licenseId) {
197 $.getJSON(
"?mod=conclude-license&do=" + doWhat +
"&upload=" + uploadId +
"&item=" + uploadTreeId +
"&licenseId=" + licenseId)
198 .done(
function (data) {
200 $(
'#decTypeSet').addClass(
'decTypeWip');
202 var table = createClearingTable();
208 function addLicense(uploadId, uploadTreeId, licenseId) {
209 modifyLicense(
'addLicense', uploadId, uploadTreeId, licenseId);
212 function removeLicense(uploadId, uploadTreeId, licenseId) {
213 modifyLicense(
'removeLicense', uploadId, uploadTreeId, licenseId);
217 function makeMainLicense(uploadId, licenseId) {
218 $.getJSON(
"?mod=conclude-license&do=makeMainLicense&upload=" + uploadId +
"&licenseId=" + licenseId)
219 .done(
function (data) {
220 var table = createClearingTable();
226 function removeMainLicense(uploadId,licenseId) {
227 if(confirm(
"Remove this license from the main license list?"))
229 $.getJSON(
"?mod=conclude-license&do=removeMainLicense&upload=" + uploadId +
"&licenseId=" + licenseId)
230 .done(
function (data) {
231 var table = createClearingTable();
237 function openTextModel(uploadTreeId, licenseId, what, type) {
238 if(type === undefined) {
242 let clearingsForSingleFile = $(
"#clearingsForSingleFile"+licenseId+what).attr(
"title");
243 idLicUploadTree = uploadTreeId+
','+licenseId;
245 $(
"#referenceText").val(clearingsForSingleFile);
246 if (what == 4 || what ==
"comment") {
247 createDropDown($(
"#textModal > form > div"), $(
"#referenceText"));
249 $(
"#licenseStdCommentDropDown-text").hide();
250 $(
"#licenseStdCommentDropDown").next(
".select2-container").hide();
252 textModal.plainModal(
'open');
254 $(
"#referenceText").val($(
"#"+licenseId+what+type).attr(
'title'));
256 whatLicId = licenseId;
257 if (what == 4 || what ==
"comment") {
258 createDropDown($(
"#textModal > form > div"), $(
"#referenceText"));
260 $(
"#licenseStdCommentDropDown-text").hide();
261 $(
"#licenseStdCommentDropDown").next(
".select2-container").hide();
263 textModal.plainModal(
'open');
268 function closeTextModal() {
269 textModal.plainModal(
'close');
272 function submitTextModal(){
275 "id": idLicUploadTree,
277 "value": $(
"#referenceText").val()
281 url:
"?mod=conclude-license&do=updateClearings",
286 textModal.plainModal(
'close');
287 $(
"#"+ whatLicId + whatCol +
"Bulk").attr(
'title', $(
"#referenceText").val());
288 referenceText = $(
"#referenceText").val().trim();
289 if(referenceText !== null && referenceText !==
'') {
290 $(
"#"+ whatLicId + whatCol + whatType).html($(
"#"+ whatLicId + whatCol + whatType).attr(
'title').slice(0, 10) +
"...");
292 $(
"#"+ whatLicId + whatCol +
"Bulk").attr(
'title',
'');
297 function checkIfEligibleForGlobalDecision()
299 var checkBox = document.getElementById(
"globalDecision");
300 if (checkBox.checked ==
true) {
303 url:
"?mod=conclude-license&do=checkCandidateLicense",
304 data: {
"item": $(
'#uploadTreeId').val()},
305 success:
function(data) {
306 if (data !=
'success') {
308 checkBox.checked =
false;
311 error:
function(data) {
317 function doOnSuccess() {
318 textModal.plainModal(
'close');
319 $(
'#decTypeSet').addClass(
'decTypeWip');
320 oTable = $(
'#licenseDecisionsTable').dataTable(selectedLicensesTableConfig).makeEditable(editableConfiguration);
321 oTable.fnDraw(
false);
324 $(document).ready(
function () {
325 textModal = $(
'#textModal').plainModal();
326 $(
'#textModal').draggable({
328 $(
this).css({
'width':
'',
'height':
''});
333 function createDropDown(element, textBox) {
335 if ($(
"#licenseStdCommentDropDown").length) {
337 $(
"#licenseStdCommentDropDown-text").show();
338 dropDown = $(
"#licenseStdCommentDropDown");
339 dropDown.val(null).trigger(
'change');
340 dropDown.next(
".select2-container").show();
343 dropDown = $(
"<select />", {
344 "id":
"licenseStdCommentDropDown",
345 "class":
"ui-render-select2" 346 }).on(
"select2:select",
function(e) {
347 let
id = e.params.data.id;
348 getStdLicenseComments(
id,
function (comment) {
349 if (comment.hasOwnProperty(
"error")) {
350 console.log(
"Error while fetching standard comments: " + comment.error);
352 textBox.val(textBox.val() +
"\n" + comment.comment);
356 dropDown.insertBefore(element);
358 "id":
"licenseStdCommentDropDown-text" 359 }).html(
"Select standard license comments:").insertBefore(dropDown);
360 getStdLicenseComments(
"visible",
function (data) {
367 dropdownParent: textModal,
370 text:
"Select a comment" 372 data: $.map(data,
function(obj) {
382 function getStdLicenseComments(scope, callback) {
385 url:
"?mod=ajax_license_std_comments",
386 data: {
"scope": scope},
387 success:
function(data) {
390 error:
function(data) {
391 callback(data.error);
stop($application)
stop the application Assumes application is restartable via /etc/init.d/<script>. The application pas...