Sha256: 20e40ff49ec078fb133ff81bc60696f9d8c1e10e0a8cf3423836e3831fd36214
Contents?: true
Size: 1.98 KB
Versions: 3
Compression:
Stored size: 1.98 KB
Contents
(function () { 'use strict'; /** * @ngdoc directive * @name Bastion.components.directive:bstResourceSwitcher * * @description * Allows switching between resources on the same level. */ function bstResourceSwitcher($breadcrumb, $location, $state, TableCache) { function getTableName(url) { var tableName = url.split('/'); if (isFinite(parseInt(tableName[tableName.length - 1], 10))) { tableName.pop(); } return tableName.join('-').slice(1); } return { templateUrl: 'components/views/bst-resource-switcher.html', link: function (scope) { var breadcrumbs = $breadcrumb.getStatesChain(), listUrl; scope.table = {rows: []}; if (breadcrumbs.length > 0) { listUrl = breadcrumbs[breadcrumbs.length - 2].ncyBreadcrumbLink; scope.table = TableCache.getTable(getTableName(listUrl)); } scope.showSwitcher = function () { var tableHasRows, isNewPage; // Must have at least two items to switch between them tableHasRows = scope.table && scope.table.rows.length > 1; // Don't show the switcher when creating a new product isNewPage = /new$/.test($location.path()); return tableHasRows && !isNewPage; }; scope.changeResource = function (id) { var currentUrl, nextUrl; currentUrl = $location.path(); nextUrl = currentUrl.replace(/\d+([^\d+]*)$/, id + '$1'); $location.path(nextUrl); }; } }; } angular.module('Bastion.components').directive('bstResourceSwitcher', bstResourceSwitcher); bstResourceSwitcher.$inject = ['$breadcrumb', '$location', '$state', 'TableCache']; })();
Version data entries
3 entries across 3 versions & 1 rubygems