explore-services/portal-2/src/app/claimPages/linking/selected/selectedPublications.compon...

124 lines
4.8 KiB
TypeScript

import {Component, Input,Output, EventEmitter, ViewChild} from '@angular/core';
import {AlertModal} from '../../../utils/modal/alert';
@Component({
selector: 'claim-selected-publications',
template: `
<li *ngFor="let pub of publications" class="list-group-item">
<div class="row">
<div [ngClass]="showAccessRights?'col-md-8':'col-md-12'" >
<span *ngIf="showAccessRights" (click)="removePublication(pub)" aria-hidden="true" class="btn glyphicon glyphicon-remove"></span>
<a *ngIf="pub.url" target="_blank" href="{{pub.url}}" >{{pub.title}}</a>
<span *ngIf="!pub.url" >{{pub.title}}</span><span *ngIf="pub.date" >({{pub.date.substring(0,4)}})</span>
<span *ngIf="!showAccessRights" (click)="removePublication(pub)" aria-hidden="true" class="btn glyphicon glyphicon-remove"></span>
</div>
<div *ngIf="showAccessRights && pub.source != 'openaire' " class = "col-md-4">
<span *ngIf="showAccessRights && pub.source != 'openaire' " class="dropdown">
<button class="btn btn-default dropdown-toggle" type="button" id="{{'dropdown'+pub.id}}" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
{{pub.accessRights}}
</button>
<ul class="dropdown-menu" [attr.aria-labelledby]="'dropdown'+pub.id">
<li *ngFor="let type of accessTypes" ><a (click)="accessRightsTypeChanged(type,pub) " >{{type}} </a></li>
</ul>
<input *ngIf="pub.accessRights== 'EMBARGO'" type="date" id="{{'date'+pub.id}}" name="" [min]="todayDate" (keyup)="dateChanged($event, pub)" [value]="pub.embargoEndDate">
</span>
</div>
<div *ngIf="showAccessRights && pub.source == 'openaire' " class = "col-md-4">
<span >
<button class="btn btn-default disabled " type="button" >
{{pub.accessRights}}
</button>
</span>
</div>
</div>
</li>
<modal-alert (alertOutput)="confirmClose($event)">
</modal-alert>
`
})
export class ClaimSelectedPublicationsComponent {
ngOnInit() {
var myDate = new Date();
this.todayDate=( myDate.getFullYear()+ "-" +myDate.getMonth() + 1) + "-" + myDate.getDate() ;
this.nextDate= ( (myDate.getFullYear()+100)+ "-" +myDate.getMonth() + 1) + "-" + myDate.getDate() ;
//2015-05-01
}
@Input() publications;
@Input() showAccessRights:boolean = false;
@Input() inline:boolean = false;
@Input() hideType;
@Input() bulkMode:boolean = false;
@Input() linkToResults:boolean = true;
@Output()publicationsChange = new EventEmitter();
@Output() showChange = new EventEmitter();
todayDate = '';
nextDate = '';
@ViewChild(AlertModal) alertApplyAll;
private commonAccessRights = "OPEN"; // for access rights- changes when user apply a change to every result
private commonEmbargoEndDate; // for access rights: embargoEndDate - changes when user apply a change to every result
removePublication(item:any){
var index:number =this.publications.indexOf(item);
if (index > -1) {
this.publications.splice(index, 1);
}
this.publicationsChange.emit({
value: this.publications
});
}
accessTypes = ["OPEN","CLOSED","EMBARGO","RESTRICTED"];
dateChanged (event:any, item:any) {
item.embargoEndDate = event.target.value ;
}
publicationsChanged($event) {
this.publications=$event.value;
this.publicationsChange.emit({
value: this.publications
});
}
/* The following methods:
*typeChanged
*confirmOpen
*confirmClose
implement the functionality: change accessRights of a publication - apply to all if asked */
accessRightsTypeChanged (type:any, item:any) {
item.accessRights = type;
if(this.publications.length > 1 ){
this.commonAccessRights = type;
if(this.commonAccessRights == "EMBARGO"){
this.commonEmbargoEndDate = item.embargoEndDate;
}
this.confirmOpen();
}
}
confirmOpen(){
this.alertApplyAll.cancelButton = true;
this.alertApplyAll.okButton = true;
this.alertApplyAll.alertTitle = "Change access rights";
this.alertApplyAll.message = "Do you wish to apply the change to every publication?";
this.alertApplyAll.okButtonText = "Yes";
this.alertApplyAll.cancelButtonText = "No";
this.alertApplyAll.open();
}
confirmClose(data){
for (var i = 0; i < this.publications.length; i++) {
this.publications[i].accessRights = this.commonAccessRights;
if(this.commonAccessRights == "EMBARGO"){
this.publications[i].embargoEndDate = this.commonEmbargoEndDate;
}
}
}
}