Sunteți pe pagina 1din 9

angular.

module('ed944fa1-04a3-44ba-8c70-e9d9020fea3e', [
'core.services.WidgetAPI'
]).directive('customCards', widgetComponent);

function widgetComponent(WidgetAPI, $timeout) {

function widgetContainer(scope, element, params) {


// Create a new instance of the Widget API
var api = new WidgetAPI(params);

scope.updatedMenuItems = [{
title: 'My Team',
subMenuItems: [{
title: 'John Maloney',
action: function (data) {
api.sendNotification('info', data.title + ' pressed');
}
},{
title: 'Cathal Jackson',
action: function (data) {
api.sendNotification('info', data.title + ' pressed');
}
}],
},
{
title: 'Disposition Codes',
subMenuItems: [{
title: 'Discount Offered',
tooltip: '766',
action: function (data) {
api.sendNotification('info', data.title + ' pressed');
}
}],
}
];

var cardObject = {
id: 0,
title: 'Custom card Title',
titleTooltip: 'Custom card title tooltip',
icon: 'aoc-custom01',
iconTooltip: 'Custom card icon tooltip',
color: '',
summary: 'Custom card summary message',
establishedTime: new Date(),
updatableTimer: true,
countdownTimer: false,
countdownDuration: 30,
menuTimeout: 10000,
legTitle: 'Custom card leg title',
legTitleIcon: 'aoc-warning-filled',
legTitleTooltip: 'Custom card leg title tooltip',
customShortcuts:[{
combo: 'Ctrl + Shift + h',
buttonIdentifier: 'A',
action: function (data) {
api.sendNotification('info', data.title + ' passed to callback');
}
}],
buttons: [{
title: 'Custom Button',
positionIndex: '1',
uniqueIdentifier: 'A',
icon: 'aoc-defer-in',
action: function (data) {
api.sendNotification('info', data.title + ' pressed');
}
}, {
title: 'Custom Context Button',
positionIndex: '2',
icon: 'aoc-worklog',
color: 'green',
isContextMenu: true,
inputWithButton: {
isEnabled: true,
placeholder: 'Input field',
buttonIcon: 'aoc-voice-active',
buttonTooltip: 'My purpose here is to submit the input field value',
action: function (value) {
api.sendNotification('info', value + ' submitted');
}
},
action: function (id) {
$timeout(function(){api.updateMenuItems(scope.updatedMenuItems, id)},
scope.timeoutValue);
},
menuItems: [{
title: 'My Team',
subMenuItems: [{
title: 'John Maloney',
action: function (data) {
api.sendNotification('info', data.title + ' pressed');
}
},{
title: 'Pat Burke',
action: function (data) {
api.sendNotification('info', data.title + ' pressed');
}
},{
title: 'James May',
action: function (data) {
api.sendNotification('info', data.title + ' pressed');
}
},{
title: 'Charlie Beckett',
action: function (data) {
api.sendNotification('info', data.title + ' pressed');
}
},{
title: 'Adam Brennan',
action: function (data) {
api.sendNotification('info', data.title + ' pressed');
}
},{
title: 'Sarah Walsh',
action: function (data) {
api.sendNotification('info', data.title + ' pressed');
}
},{
title: 'Peter Ebdon',
action: function (data) {
api.sendNotification('info', data.title + ' pressed');
}
},{
title: 'Sean O Toole',
action: function (data) {
api.sendNotification('info', data.title + ' pressed');
}
},{
title: 'Peter Walsh',
action: function (data) {
api.sendNotification('info', data.title + ' pressed');
}
},{
title: 'Steve Lynch',
action: function (data) {
api.sendNotification('info', data.title + ' pressed');
}
},{
title: 'Jane Doe',
action: function (data) {
api.sendNotification('info', data.title + ' pressed');
}
},{
title: 'Conor Murray',
action: function (data) {
api.sendNotification('info', data.title + ' pressed');
}
},{
title: 'Paul Ruane',
action: function (data) {
api.sendNotification('info', data.title + ' pressed');
}
},{
title: 'Cathal Burke',
action: function (data) {
api.sendNotification('info', data.title + ' pressed');
}
},{
title: 'Ian Flaherty',
action: function (data) {
api.sendNotification('info', data.title + ' pressed');
}
},{
title: 'James Richards',
action: function (data) {
api.sendNotification('info', data.title + ' pressed');
}
},{
title: 'Niall Burke',
action: function (data) {
api.sendNotification('info', data.title + ' pressed');
}
},{
title: 'Eoin Maher',
action: function (data) {
api.sendNotification('info', data.title + ' pressed');
}
},{
title: 'Ian Power',
action: function (data) {
api.sendNotification('info', data.title + ' pressed');
}
},{
title: 'Stephen Dunphy',
action: function (data) {
api.sendNotification('info', data.title + ' pressed');
}
},{
title: 'Cathal Jackson',
action: function (data) {
api.sendNotification('info', data.title + ' pressed');
}
}],
},
{
title: 'Disposition Codes',
tooltip: 'Disposition Codes',
subMenuItems: [{
title: 'Callback Customer',
tooltip: '999',
action: function (data) {
api.sendNotification('info', data.title + ' pressed');
}
},{
title: 'Report to Supervisor',
tooltip: '888',
action: function (data) {
api.sendNotification('info', data.title + ' pressed');
}
},{
title: 'Discount Offered',
tooltip: '766',
action: function (data) {
api.sendNotification('info', data.title + ' pressed');
}
}],
}
]
},
{
title: 'Custom Button Colored',
positionIndex: '3',
icon: 'aoc-agents',
color: 'green',
isContextMenu: true,
menuItems: [{
title: 'Cathal Jackson',
action: function (data) {
api.sendNotification('info', data.title + ' pressed');
}
},{
title: 'Stephen Dunphy',
action: function (data) {
api.sendNotification('info', data.title + ' pressed');
}
},{
title: 'Ian Power',
action: function (data) {
api.sendNotification('info', data.title + ' pressed');
}
},{
title: 'Eoin Maher',
action: function (data) {
api.sendNotification('info', data.title + ' pressed');
}
},{
title: 'Niall Burke',
action: function (data) {
api.sendNotification('info', data.title + ' pressed');
}
},{
title: 'James Richards',
action: function (data) {
api.sendNotification('info', data.title + ' pressed');
}
},{
title: 'Ian Flaherty',
action: function (data) {
api.sendNotification('info', data.title + ' pressed');
}
},{
title: 'Cathal Burke',
action: function (data) {
api.sendNotification('info', data.title + ' pressed');
}
},{
title: 'Paul Ruane',
action: function (data) {
api.sendNotification('info', data.title + ' pressed');
}
},{
title: 'Conor Murray',
action: function (data) {
api.sendNotification('info', data.title + ' pressed');
}
},{
title: 'Conor Murray',
action: function (data) {
api.sendNotification('info', data.title + ' pressed');
}
},{
title: 'Jane Doe',
action: function (data) {
api.sendNotification('info', data.title + ' pressed');
}
},{
title: 'Steve Lynch',
action: function (data) {
api.sendNotification('info', data.title + ' pressed');
}
},{
title: 'Sean O Toole',
action: function (data) {
api.sendNotification('info', data.title + ' pressed');
}
},{
title: 'Peter Walsh',
action: function (data) {
api.sendNotification('info', data.title + ' pressed');
}
},{
title: 'Peter Ebdon',
action: function (data) {
api.sendNotification('info', data.title + ' pressed');
}
},{
title: 'Sarah Walsh',
action: function (data) {
api.sendNotification('info', data.title + ' pressed');
}
},{
title: 'Adam Brennan',
action: function (data) {
api.sendNotification('info', data.title + ' pressed');
}
},{
title: 'James May',
action: function (data) {
api.sendNotification('info', data.title + ' pressed');
}
},{
title: 'Charlie Beckett',
action: function (data) {
api.sendNotification('info', data.title + ' pressed');
}
},{
title: 'Pat Burke',
action: function (data) {
api.sendNotification('info', data.title + ' pressed');
}
}]
}
],
interactionData: {
workRequestId: '12345'
},
focusOnCreated: true
};
var buttonObject = {
title: 'Custom Button title',
icon: 'aoc-defer-in',
color: '',
action: function (data) {
api.sendNotification('info', data.title + ' pressed');
}
};
var menuItemObject = {
title: 'Custom Menu item title',
action: function (data) {
api.sendNotification('info', data.title + ' pressed');
}
};
var subMenuItemObject = {
title: 'Custom Submenu item title',
action: function (data) {
api.sendNotification('info', data.title + ' pressed');
}
};

scope.updateMenuItems = function(menuItems, delay) {


scope.updatedMenuItems = eval(menuItems);
scope.timeoutValue = delay;
}

scope.timeoutValues = [
{value: 0, friendlyDisplay: 'No Delay'},
{value: 3000, friendlyDisplay: '3 seconds'},
{value: 5000, friendlyDisplay: '5 seconds'},
{value: 10000, friendlyDisplay: '10 seconds'},
];
scope.timeoutValue = {value:1000, friendlyDisplay: '1 second'};

scope.cards = {
list: [],
predefined: angular.copy(cardObject)
};
scope.cards.selected = scope.cards.predefined;
scope.colors = ['green', 'yellow', 'red', 'blue'];
scope.buttons = {
selected: {},
subButtonSelected: {}
};

scope.createCustomCard = function() {
scope.cards.list.push(scope.cards.selected);
scope.cards.selected.id = generateUUID();
var cardForSend = angular.copy(scope.cards.selected);
cardForSend.countdownDuration = cardForSend.countdownDuration * 1000;
api.createCustomCard(cardForSend);
scope.cards.predefined = angular.copy(cardObject);
};

scope.updateCustomCard = function () {
var cardForSend = angular.copy(scope.cards.selected);
cardForSend.countdownDuration = cardForSend.countdownDuration * 1000;
api.updateCustomCard(cardForSend);
var index = _.findIndex(scope.cards.list, {id: scope.cards.selected.id});
scope.cards.list.splice(index, 1, scope.cards.selected);
};

scope.deleteCustomCard = function () {
api.deleteCustomCard({ id: scope.cards.selected.id });
_.remove(scope.cards.list, {
id: scope.cards.selected.id
});
scope.cards.selected = scope.cards.predefined;
};

scope.addButton = function() {
scope.cards.selected.buttons.push(angular.copy(buttonObject));
};
scope.addMenuItem = function() {
if (!scope.buttons.selected.menuItems) scope.buttons.selected.menuItems = [];
scope.buttons.selected.menuItems.push(angular.copy(menuItemObject));
};

scope.addSubMenuItem = function() {
if (!scope.buttons.selectedMenuItem.subMenuItems)
scope.buttons.selectedMenuItem.subMenuItems = [];

scope.buttons.selectedMenuItem.subMenuItems.push(angular.copy(subMenuItemObject));
};

scope.deleteButton = function(index) {
scope.cards.selected.buttons.splice(index, 1);
};

scope.deleteMenuItem = function(index) {
scope.buttons.selected.menuItems.splice(index, 1);
};

scope.deleteSubMenuItem = function(index) {
scope.buttons.selected.menuItems.subMenuItems.splice(index, 1);
};

scope.selectButton = function(button) {
scope.buttons.selected = button;
};

scope.selectMenuItem = function(menuItem) {
scope.buttons.selectedMenuItem = menuItem;
};

scope.selectSubMenuItem = function(subMenuItem) {
scope.buttons.selectedSubMenuItem = subMenuItem;
};

function generateUUID() {
var d = new Date().getTime();
var uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function
(c) {
var r = (d + Math.random() * 16) % 16 | 0;
d = Math.floor(d / 16);
return (c === 'x' ? r : (r & 0x3 | 0x8)).toString(16);
});
return uuid;
}

// Called automatically when the widget is destroyed


element.on('$destroy', function() {
api.unregister();
});
}

return {
scope: {},
replace: true,
template: template,
link: widgetContainer
};
}

S-ar putea să vă placă și