Skip to content

Instantly share code, notes, and snippets.

@SergeiGolos
Created December 10, 2012 04:50
Show Gist options
  • Save SergeiGolos/4248435 to your computer and use it in GitHub Desktop.
Save SergeiGolos/4248435 to your computer and use it in GitHub Desktop.
ScratchPad
/// Define the routes of the application.
var app = angular.module('Main', ['keyboardProvider', 'tasksProvider'], function($routeProvider, $locationProvider) {
$routeProvider.when('/details/:taskId', { controller: 'ctrl_Details', templateUrl: "view/details.html" });
$routeProvider.when('/new', { controller: 'ctrl_New', templateUrl: "view/new.html" });
$routeProvider.when('/', { controller: 'ctrl_List', templateUrl: 'view/home.html' });
$routeProvider.otherwise({redirectTo:'/'});
});
/// Displays the the full detail view of a task, also applys the filter to show only the history for the results list.
app.controller('ctrl_Details', function ($scope: DetailScope, $routeParams: any) {
$scope.task = window["_"].find(window["model"].tasks, function (item: Task) { return item.refID == $routeParams.taskId });
$scope.$emit('setSearch', $scope.task.account);
});
//clears any filters and brings up a current
app.controller('ctrl_New', function ($scope: NewScope) {
$scope.$emit('setSearch', '');
});
app.controller('ctrl_List', function ($scope: ListScope) {
$scope.$emit('setSearch', '');
});
app.controller('ctrl_Page', function ($scope: PageScope, $element: JQuery, $filter: any, tasks) {
$scope.$on('setSearch', function (evt, data : string) {
$scope.filterString = data;
});
$scope.tasks = tasks.getAllTasks();
$scope.filterString = "";
});
app.filter('QuickTaskFilter', function () {
var searchFields: string[] = ['account', 'owner', 'summary'];
return (function (data, search) {
var matchPatt = new RegExp(search, 'i');
angular.forEach(data, function (item, index) {
var result = (search == null ||
search == '' ||
matchPatt.test($.map(searchFields, function (val: string) { return item[val]; }).join(" ")));
item.hidden = result ? "" : "hidden";
});
return data;
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment