Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Selecting value in a directive
Message
 
 
À
Tous
Information générale
Forum:
Javascript
Catégorie:
Autre
Titre:
Selecting value in a directive
Divers
Thread ID:
01629739
Message ID:
01629739
Vues:
33
Hi everybody,

This should be simple but I can not get it working so far. I'm trying to create an account picker directive. Here is the whole code
(function () {
    'use strict';

    var app = angular.module('sysMgrApp');
    app.directive("accountPicker", ['searchScreenService', 'accountsService', 'resourceFactory',
        function (searchScreenService, accountsService, resourceFactory) {
            return {
                restict: 'A',
                transclude: true,
                scope: {

                    account: '=',
                    buttonToolTip: '@?',
                    pickerTitle: '@?',
                    selectAccount: '&'
                },
                link: function (scope, element, attrs, ctrl) {
                    scope.buttonToolTip = scope.buttonToolTip || resourceFactory.getResource('Labels', 'selectX').format(resourceFactory.getResource('Labels', 'account'));;
                    scope.pickerTitle = scope.pickerTitle || resourceFactory.getResource('Labels', 'accounts');
                    // window.console && console.log(scope.buttonToolTip);
                },
                replace: true,
                templateUrl: 'app/templates/contactpickerbutton',
                controller: ['$scope', '$log', '$modal', 'searchScreenService',
                    'accountsService', 'resourceFactory', function ($scope, $log, $modal, searchScreenService,
                        accountsService, resourceFactory) {

                        $scope.displayList = function () {
                            var modal = $modal.open({
                                scope: $scope,

                                windowClass: 'contacts-modal-window', // use bootstrap                         
                                templateUrl: 'app/templates/accountpicker',
                                controller: ['$scope', '$log', function ($scope, $log) {
                                    $scope.simpleSearch = '';
                                    
                                    var createTable = function () {
                                        $scope.table = searchScreenService.getTable('AcctName', [
                                            {
                                                name: 'AcctName',
                                                displayName: resourceFactory.getResource('Labels', 'nickname'),
                                                width: 26
                                            },
                                            {
                                                name: 'FullName',
                                                displayName: resourceFactory.getResource('Labels', 'fullName'),
                                                width: 37
                                            },
                                            {
                                                name: 'PhoneNumber',
                                                displayName: resourceFactory.getResource('Labels', 'phoneNumber'),
                                                width: 37
                                            }
                                        ]);
                                    };

                                    createTable();
                                    var queryRequest = searchScreenService.getQueryRequest();
                                    queryRequest.pageSize = 15;
                                    queryRequest.orderBy = 'AcctName';
                                    queryRequest['IsSimpleSearch'] = true;

                                    var getData = function (queryRequest) {
                                        // queryRequest = searchScreenService.getQueryRequest();
                                        searchScreenService.setTable($scope.table);
                                        var data = accountsService.getAccounts(queryRequest).then(function (data) {
                                            if (data.totalCount < 1) {
                                                $scope.alertType = 'info';
                                                $scope.alertMessage = resourceFactory.getResource('Messages', 'noSearchResults');
                                            };

                                            if (data.totalCount > 0) {
                                                $scope.accountsList = data.list;
                                                $scope.table.pageCount = data.pageCount;
                                                $scope.table.pageSize = data.pageSize;
                                                $scope.table.pageNumber = data.pageNumber;
                                                $scope.table.totalCount = data.totalCount;
                                                
                                            }
                                        });
                                    }

                                    $scope.searchAccounts = function (table) {
                                     
                                        queryRequest.orderBy = table.sort;
                                        queryRequest.dir = table.dir;
                                        getData(queryRequest);
                                    }

                                    $scope.doSimpleSearch = function (searchValue) {
                                        queryRequest['SimpleSearch.SimpleSearchField'] = searchValue;
                                        getData(queryRequest);
                                    }

                                    $scope.selectPage = function () {
                                        queryRequest.page = $scope.table.pageNumber;
                                        getData(queryRequest);
                                    }

                                    $scope.sort = function (column) {
                                    }
                                    getData(queryRequest);
                                }]
                            });

                            var getAccount = function (id) {
                                var data = accountsService.getAccount(id, false).then(function (data) {

                                    $scope.account = data;
                                });
                            } 

                            modal.result.then(function (result) {
                                $log.info('Selected account: ' + result.acctName);
                                $scope.account = result; // just return the base info
                                // call another service to populate account.
                                $scope.selectAccount(); 
                                //  getAccount(result.acctNameHash);
                                return result;
                            });
                        }
                    }]
            };
        }]);
})();
So, this all works quite nicely, I can select an account.

My problem is getting that selected account in my page.

Here is my controller's code:
$scope.selectAccount = function()
            {
                // window.console && console.log('Selected account is ' + selectedAccount.acctName);
                if ($scope.currentTemplate.accountForInvoice)
                    $scope.currentTemplate.dwacc = $scope.currentTemplate.accountForInvoice.acctName;
            }
and this is how I put it in the chtml page:
<div name="accountForInvoice"
                             account-picker
                             button-tool-tip="@String.Format(Labels.selectX, Labels.account)"
                             picker-title="@Labels.accounts"
                             account = "currentTemplate.accountForInvoice"
                             select-account ="selectAccount()"></div>
                    </div>
and this is not working - my currentTemplate.accountForInvoice is not becoming the selected account. I also tried passing it as a parameter but also can not make it to work (in that case it was becoming a selected account after the second time).

Do you see what am I missing here?

Thanks in advance.
If it's not broken, fix it until it is.


My Blog
Répondre
Fil
Voir

Click here to load this message in the networking platform