Skip to content

Commit

Permalink
feat(transactions): remove cellNav after txn edit
Browse files Browse the repository at this point in the history
This commit changes the Posting Journal's Transaction Service behavior to
only allow cell-level navigation in edit mode.  The cellNav service is
canceled upon a call to `save()`.
  • Loading branch information
Jonathan Niles committed Sep 7, 2016
1 parent 39013ea commit 451b1d6
Showing 1 changed file with 53 additions and 2 deletions.
55 changes: 53 additions & 2 deletions client/src/js/services/grid/TransactionService.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,17 @@ function TransactionService(util, uiGridConstants, bhConstants) {
return $scope.row[ROW_EDIT_FLAG];
}

// sets the allowCellFocus parameter on grid's column definitions
function setColumnCellNav(column) {
column.allowCellFocus = this._cellNavEnabled;
}

// called after the cellNavigationEnabled trigger is fired
function registerCellNavChange() {
angular.forEach(this.gridOptions.columnDefs, setColumnCellNav.bind(this));
this.gridApi.core.notifyDataChange(uiGridConstants.dataChange.COLUMN);
}

/**
* @constructor
*/
Expand All @@ -80,6 +91,9 @@ function TransactionService(util, uiGridConstants, bhConstants) {
// this array stores the transactions ids currently being edited.
this._edits = [];

// cellNav is not enabled by default
this._cellNavEnabled = false;

gridOptions.cellEditableCondition = cellEditableCondition;
gridOptions.enableCellEditOnFocus = true;

Expand All @@ -91,6 +105,39 @@ function TransactionService(util, uiGridConstants, bhConstants) {
}.bind(this));
}


/**
* @function enableCellNavigation
*
* @description
* Enables cell navigation on the underlying grid.
*
* @public
*
*/
Transactions.prototype.enableCellNavigation = function enableCellNavigation() {
this._cellNavEnabled = true;
registerCellNavChange.call(this);
};

/**
* @function disableCellNavigation
*
* @description
* Disables and clears the focused cell navigation for a better UX while working
* with complex grids.
*
* @public
*
*/
Transactions.prototype.disableCellNavigation = function disableCellNavigation() {
this._cellNavEnabled = false;
registerCellNavChange.call(this);

// clear the focused element for a better UX
this.gridApi.grid.cellNav.clearFocus();
};

/**
* @function createTransactionIndexMap
*
Expand Down Expand Up @@ -234,6 +281,10 @@ function TransactionService(util, uiGridConstants, bhConstants) {
uuid = getChildRecordUuid(uuid);
}

if (!this._cellNavEnabled) {
this.enableCellNavigation();
}

setPropertyOnTransaction.call(this, uuid, ROW_EDIT_FLAG, true);
this.scrollIntoView(uuid);
this._edits.push(uuid);
Expand All @@ -256,8 +307,8 @@ function TransactionService(util, uiGridConstants, bhConstants) {
// set the edits length to 0
this._edits.length = 0;

// clear the focused element for a better UX
this.gridApi.grid.cellNav.clearFocus();
// disable cell navigation
this.disableCellNavigation();
};

/**
Expand Down

0 comments on commit 451b1d6

Please sign in to comment.