Merge pull request '2428-anchor_directive' (#419) from 2428-anchor_directive into dev
gitea/salix/pipeline/head This commit looks good Details

Reviewed-on: #419
Reviewed-by: Carlos Jimenez <carlosjr@verdnatura.es>
This commit is contained in:
Joan Sanchez 2020-10-21 08:38:55 +00:00
commit 3208dce7fa
7 changed files with 76 additions and 10 deletions

View File

@ -0,0 +1,70 @@
import ngModule from '../module';
export function stringifyParams(data) {
const params = Object.assign({}, data.params);
for (let param in params)
params[param] = JSON.stringify(params[param]);
return params;
}
export function changeState($state, event, data) {
const params = stringifyParams(data);
$state.go(data.state, params);
event.preventDefault();
event.stopPropagation();
}
export function openNewTab($state, $window, event, data) {
const params = stringifyParams(data);
const href = $state.href(data.state, params);
$window.open(href);
event.preventDefault();
event.stopPropagation();
}
/**
* Allows changing state for nested anchor
*
* @param {Object} $state
* @param {Object} $window
* @return {Object} The directive
*/
export function directive($state, $window) {
let ctrlPressed = false;
$window.addEventListener('keydown', event => {
if (event.key == 'Control')
ctrlPressed = true;
});
$window.addEventListener('keyup', event => {
if (event.key == 'Control')
ctrlPressed = false;
});
return {
restrict: 'A',
link: function($scope, $element, $attrs) {
const data = $scope.$eval($attrs.vnAnchor);
$element.on('click', event => {
if (ctrlPressed)
openNewTab($state, $window, event, data);
else
changeState($state, event, data);
});
$element.on('mousedown', event => {
const mouseWheel = 1;
if (event.button == mouseWheel)
openNewTab($state, $window, event, data);
});
}
};
}
directive.$inject = ['$state', '$window'];
ngModule.directive('vnAnchor', directive);

View File

@ -15,3 +15,4 @@ import './smart-table';
import './droppable'; import './droppable';
import './http-click'; import './http-click';
import './http-submit'; import './http-submit';
import './anchor';

View File

@ -2,3 +2,4 @@ Simple ticket: Ticket simple
View consumer report: Ver informe de consumo View consumer report: Ver informe de consumo
From date: Fecha desde From date: Fecha desde
To date: Fecha hasta To date: Fecha hasta
Go to user: Ir al usuario

View File

@ -40,8 +40,7 @@
vn-tooltip="Client frozen" vn-tooltip="Client frozen"
icon="icon-frozen"> icon="icon-frozen">
</vn-icon-button> </vn-icon-button>
<vn-icon-button <vn-icon-button vn-anchor="{state: 'ticket.index', params: {q: {clientFk: client.id}}}"
ng-click="$ctrl.filterTickets(client, $event)"
vn-tooltip="Client tickets" vn-tooltip="Client tickets"
icon="icon-ticket"> icon="icon-ticket">
</vn-icon-button> </vn-icon-button>

View File

@ -119,7 +119,7 @@
</vn-td> </vn-td>
<vn-td actions> <vn-td actions>
<vn-icon-button <vn-icon-button
vn-click-stop="$ctrl.goToLines(ticket.id)" vn-anchor="{state: 'ticket.card.sale', params: {id: ticket.id}}"
vn-tooltip="Go to lines" vn-tooltip="Go to lines"
icon="icon-lines"> icon="icon-lines">
</vn-icon-button> </vn-icon-button>

View File

@ -114,11 +114,6 @@ export default class Controller extends Section {
return 'warning'; return 'warning';
} }
goToLines(ticketFk) {
let url = this.$state.href('ticket.card.sale', {id: ticketFk}, {absolute: true});
window.open(url, '_blank');
}
preview(ticket) { preview(ticket) {
this.selectedTicket = ticket; this.selectedTicket = ticket;
this.$.summary.show(); this.$.summary.show();

View File

@ -29,7 +29,7 @@
<vn-item-section side> <vn-item-section side>
<vn-icon-button <vn-icon-button
ng-click="$ctrl.goToTimeControl($event, worker.id)" ng-click="$ctrl.goToTimeControl($event, worker.id)"
vn-tooltip="Preview" vn-tooltip="Time control"
icon="access_time"> icon="access_time">
</vn-icon-button> </vn-icon-button>
<vn-icon-button <vn-icon-button