Current Path : /var/www/alh/admin/view/journal2/js/directives/ |
Current File : /var/www/alh/admin/view/journal2/js/directives/menu-item.js |
define(['./module', 'underscore.string'], function (module, _S) { module.factory('MenuItemName', function () { var TYPES = { category : 'Category', product : 'Product', manufacturer: 'Brand', information : 'Information', opencart : 'OpenCart Page', custom : 'Custom' }; var PAGES = { 'common/home': 'Home', 'account/wishlist': 'Wishlist', 'product/compare': 'Compare', 'account/account': 'My Account', 'checkout/cart': 'Shopping cart', 'checkout/checkout': 'Checkout', 'information/contact': 'Contact', 'account/return/insert': 'Returns', 'information/sitemap': 'Sitemap', 'product/manufacturer': 'Brands', 'account/voucher': 'Gift Vouchers', 'affiliate/account': 'Affiliates', 'product/special': 'Specials', 'product/search': 'Search', 'account/order': 'Order History', 'account/newsletter': 'Newsletter', 'login': 'Login (Account)', 'register': 'Register (Logout)' }; return function (item) { var type = item.menu.menu_type; var name = item.menu.menu_item ? item.menu.menu_item.name : 'Menu Item'; if (type === 'custom') { name = item.name.value[Journal2Config.languages.default] || 'Menu Item'; } if (type === 'opencart') { name = PAGES[item.menu.menu_item.page]; } if (item.name_overwrite) { name = item.name.value[Journal2Config.languages.default]; } name = name || ''; var pieces = name.split(' > '); return _S.unescapeHTML(pieces.length > 0 ? pieces[pieces.length - 1] : ''); }; }); module.directive('menuItem', [function () { return { require: '?ngModel', scope: { ngModel: '=' }, restrict: 'E', templateUrl: 'view/journal2/tpl/directives/menu-item.html?ver=' + Journal2Config.version, controller: function ($scope) { $scope.languages = Journal2Config.languages.languages; $scope.$watch('ngModel', function (val) { if (Object.prototype.toString.call(val.menu_item) === '[object Array]') { val.menu_item = {}; } if (val.menu_type === 'opencart' && (!val.menu_item || !val.menu_item.page)) { val.menu_item = val.menu_item || {}; val.menu_item.page = 'common/home'; } $scope.ngModel = val; }); }, link: function ($scope, $element, $attrs, $ngModel) { $($element).find('select').change(function () { if ($scope.ngModel.menu_type === 'opencart') { $scope.ngModel.menu_item.page = 'common/home'; } }); $scope.resetItem = function () { if ($scope.ngModel.menu_type === 'opencart') { $scope.ngModel.menu_item = {}; $scope.ngModel.menu_item.page = 'common/home'; } else { $scope.ngModel.menu_item = null; } }; } }; }]); });