<commit_before>﻿angular.module('crm', ['ui.state', 'ui.select2', 'ui.date', 'core.security', 'crm.templates'])
    .config(['$routeProvider', '$locationProvider', '$stateProvider', '$urlRouterProvider', 'securityAuthorizationProvider',
        function($routeProvider, $locationProvider, $stateProvider, $urlRouterProvider, securityAuthorizationProvider) {

            $urlRouterProvider.otherwise('/contracts');

            var contractList = {
                name: 'page2C.contractList',
                url: '/contracts',
                views: {
                    'sidebar': {
                        templateUrl: '/ng-modules/crm/contracts/list/contractListFilter.tpl.html'
                    },
                    'content': {
                        templateUrl: '/ng-modules/crm/contracts/list/contractListGrid.tpl.html'
                    }
                },
                resolve: {
                    //authUser: securityAuthorizationProvider.requireAuthenticatedUser()
                    projectMember: securityAuthorizationProvider.requireGroups(['admins', 'managers', 'executors'])
                }
            },

                contractCommonTab = {
                    name: 'tabPage1C.contractCommonTab',
                    url: '/contracts/:contractid/common',
                    views: {
                        'tabbar': {
                            template: '<div ng-controller="contractTabsCtrl" tabbar="0"></div>'
                        },
                        'content': {
                            templateUrl: '/ng-modules/crm/contracts/commonTab/contractCommonTab.tpl.html'
                        }
                    }
                },

                contractTasksTab = {
                    name: 'tabPage2C.contractTasksTab',
                    url: '/contracts/:contractid/tasks',
                    views: {
                        'tabbar': {
                            template: '<div ng-controller="contractTabsCtrl" tabbar="1"></div>'
                        },
                        'sidebar': {
                            templateUrl: '/ng-modules/crm/contracts/tasksTab/contractTasksTabFilter.tpl.html'
                        },
                        'content': {
                            templateUrl: '/ng-modules/crm/contracts/tasksTab/contractTasksTabGrid.tpl.html'
                        }
                    }
                };

            $stateProvider
                .state(contractList)
                .state(contractCommonTab)
                .state(contractTasksTab);

        }
    ])
    .service("contractService", ['$q','$http',
        function($q, $http) {
            this.getContracts = function(filter) {
                var deferred = $q.defer();
                 $http.post("/api/v1", {
                    action: "get",
                    model: "project.contracts",
                    project: window.app.project,
                    filter: filter
                }).success(function (data, status, headers, config) {
                     deferred.resolve(data);
                }).error(function (data, status, headers, config) {
                    // TODO
                });
                return deferred.promise;
            };
        }
    ])


    .controller('contractListGridCtrl', ['$scope', 'contractService', 'pageConfig',
        function($scope, $contractService, $pageConfig) {
            $pageConfig.setConfig({
                breadcrumbs: [{
                        name: "Projects",
                        url: '/projects'
                    },{
                        name: window.app.project,
                        url: '/projects/'+window.app.project
                    },{
                        name: 'Contracts',
                        url: '#!/contracts'
                    }]
            });

            $scope.contracts=[];

            $contractService.getContracts({}).then(function (res) {
                $scope.contracts =  res.contracts;
            });
        }
    ])
    .controller('contractTabsCtrl', ['$scope', '$stateParams',
        function($scope, $stateParams) {
            $scope.tabs = [{
                name: 'Common',
                url: '#!/contracts/' + $stateParams.contractid + '/common'
            }, {
                name: 'Tasks',
                url: '#!/contracts/' + $stateParams.contractid + '/tasks'
            }];
        }
    ])
    .controller('contractCommonTabCtrl', ['$scope', '$stateParams', 'pageConfig',
        function($scope, $stateParams, $pageConfig) {
            var contractid = $stateParams.contractid;

            $pageConfig.setConfig({
                breadcrumbs: [{
                        name: "Projects",
                        url: '/projects'
                    },{
                        name: window.app.project,
                        url: '/projects/'+window.app.project
                    },{
                        name: 'contracts',
                        url: '#!/contracts'
                    }, {
                        name: contractid,
                        url: '#!/contracts/' + contractid + '/common'
                    }

                ]
            });
            $scope.contractid = contractid;
        }
    ])

// Edit
.controller('contractItemCtrl', ['$scope', '$q', '$timeout',
    function($scope, $q, $timeout) {

        var categories = [{
            id: 1,
            text: 'cat'
        }, {
            id: 2,
            text: 'dog'
        }, {
            id: 3,
            text: 'pet'
        }, {
            id: 4,
            text: 'rat'
        }, {
            id: 5,
            text: 'fat'
        }, {
            id: 6,
            text: 'zet'
        }];
        var contract = {
            name: 'contract-123',
            signedAt: new Date(2010, 01, 01),
            category: [{
                id: 1,
                text: 'cat'
            }]
        };

        $scope.categoryOptions = {
            multiple: true,
            query: function(query) {
                $timeout(function() {
                    var data = {
                        results: categories
                    };
                    query.callback(data);
                }, 400);
            }
        };
        $scope.contract = angular.copy(contract);

        $scope.cancel = function() {<commit_msg>No new versions of angular (> 1.1.1) available via bower, $setPristine method not available on 1.0.7 version<commit_after>﻿angular.module('crm', ['ui.state', 'ui.select2', 'ui.date', 'core.security', 'crm.templates'])
    .config(['$routeProvider', '$locationProvider', '$stateProvider', '$urlRouterProvider', 'securityAuthorizationProvider',
        function($routeProvider, $locationProvider, $stateProvider, $urlRouterProvider, securityAuthorizationProvider) {

            $urlRouterProvider.otherwise('/contracts');

            var contractList = {
                name: 'page2C.contractList',
                url: '/contracts',
                views: {
                    'sidebar': {
                        templateUrl: '/ng-modules/crm/contracts/list/contractListFilter.tpl.html'
                    },
                    'content': {
                        templateUrl: '/ng-modules/crm/contracts/list/contractListGrid.tpl.html'
                    }
                },
                resolve: {
                    //authUser: securityAuthorizationProvider.requireAuthenticatedUser()
                    projectMember: securityAuthorizationProvider.requireGroups(['admins', 'managers', 'executors'])
                }
            },

                contractCommonTab = {
                    name: 'tabPage1C.contractCommonTab',
                    url: '/contracts/:contractid/common',
                    views: {
                        'tabbar': {
                            template: '<div ng-controller="contractTabsCtrl" tabbar="0"></div>'
                        },
                        'content': {
                            templateUrl: '/ng-modules/crm/contracts/commonTab/contractCommonTab.tpl.html'
                        }
                    }
                },

                contractTasksTab = {
                    name: 'tabPage2C.contractTasksTab',
                    url: '/contracts/:contractid/tasks',
                    views: {
                        'tabbar': {
                            template: '<div ng-controller="contractTabsCtrl" tabbar="1"></div>'
                        },
                        'sidebar': {
                            templateUrl: '/ng-modules/crm/contracts/tasksTab/contractTasksTabFilter.tpl.html'
                        },
                        'content': {
                            templateUrl: '/ng-modules/crm/contracts/tasksTab/contractTasksTabGrid.tpl.html'
                        }
                    }
                };

            $stateProvider
                .state(contractList)
                .state(contractCommonTab)
                .state(contractTasksTab);

        }
    ])
    .service("contractService", ['$q','$http',
        function($q, $http) {
            this.getContracts = function(filter) {
                var deferred = $q.defer();
                 $http.post("/api/v1", {
                    action: "get",
                    model: "project.contracts",
                    project: window.app.project,
                    filter: filter
                }).success(function (data, status, headers, config) {
                     deferred.resolve(data);
                }).error(function (data, status, headers, config) {
                    // TODO
                });
                return deferred.promise;
            };
        }
    ])


    .controller('contractListGridCtrl', ['$scope', 'contractService', 'pageConfig',
        function($scope, $contractService, $pageConfig) {
            $pageConfig.setConfig({
                breadcrumbs: [{
                        name: "Projects",
                        url: '/projects'
                    },{
                        name: window.app.project,
                        url: '/projects/'+window.app.project
                    },{
                        name: 'Contracts',
                        url: '#!/contracts'
                    }]
            });

            $scope.contracts=[];

            $contractService.getContracts({}).then(function (res) {
                $scope.contracts =  res.contracts;
            });
        }
    ])
    .controller('contractTabsCtrl', ['$scope', '$stateParams',
        function($scope, $stateParams) {
            $scope.tabs = [{
                name: 'Common',
                url: '#!/contracts/' + $stateParams.contractid + '/common'
            }, {
                name: 'Tasks',
                url: '#!/contracts/' + $stateParams.contractid + '/tasks'
            }];
        }
    ])
    .controller('contractCommonTabCtrl', ['$scope', '$stateParams', 'pageConfig',
        function($scope, $stateParams, $pageConfig) {
            var contractid = $stateParams.contractid;

            $pageConfig.setConfig({
                breadcrumbs: [{
                        name: "Projects",
                        url: '/projects'
                    },{
                        name: window.app.project,
                        url: '/projects/'+window.app.project
                    },{
                        name: 'contracts',
                        url: '#!/contracts'
                    }, {
                        name: contractid,
                        url: '#!/contracts/' + contractid + '/common'
                    }

                ]
            });
            $scope.contractid = contractid;
        }
    ])

// Edit
.controller('contractItemCtrl', ['$scope', '$q', '$timeout',
    function($scope, $q, $timeout) {

        var categories = [{
            id: 1,
            text: 'cat'
        }, {
            id: 2,
            text: 'dog'
        }, {
            id: 3,
            text: 'pet'
        }, {
            id: 4,
            text: 'rat'
        }, {
            id: 5,
            text: 'fat'
        }, {
            id: 6,
            text: 'zet'
        }];
        var contract = {
            name: 'contract-123',
            signedAt: new Date(2010, 01, 01),
            category: [{
                id: 1,
                text: 'cat'
            }]
        };

        $scope.categoryOptions = {
            multiple: true,
            query: function(query) {
                $timeout(function() {
                    var data = {
                        results: categories
                    };
                    query.callback(data);
                }, 400);
            }
        };
        $scope.contract = angular.copy(contract);

        $scope.cancel = function() {
            //WTF?? where this method?? contractForm.$setPristine();
            //$scope.contractForm.$pristine = true;
{'fraction_non_alphanumeric': 0.12542372881355932, 'fraction_numerical': 0.004776579352850539, 'mean_word_length': 1.0943852855759924, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1650166', 'n_tokens_mistral': 3272, 'n_tokens_neox': 3023, 'n_words': 510}