123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- 'use strict';
- /**
- * Licensed Materials - Property of IBM
- * IBM Watson Analytics (C) Copyright IBM Corp. 2018
- * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
- *
- */
- define(['../../lib/@waca/core-client/js/core-client/ui/core/Class', '../../lib/@waca/core-client/js/core-client/utils/UniqueId'], function (Class, UniqueId) {
- /**
- * Handles undo/redo and rollback drill through model if users cancel editing in the manage dialog
- */
- var DrillThroughUndoRedoTransaction = Class.extend({
- init: function init(options) {
- options = options || {};
- this._drillThroughModelApi = options.drillThroughModelApi;
- },
- /**
- * silently apply the undo/redo payload to the model to restore a previous state
- * @param undoRedoValue - the value passed to onModelChange when an undo or redo occurs.
- */
- applyUndoRedo: function applyUndoRedo(payload, prevValue, sender, name, context) {
- if (sender === 'UndoRedoController' && name === 'reset') {
- var value = context.undoRedoTransactionType === 'undo' ? payload.prevValue : payload.value;
- this._drillThroughModelApi.applyModelChange(value, { silent: true });
- }
- },
- rollback: function rollback(transactionInfo) {
- if (transactionInfo.transactionId === this._mainTransaction) {
- transactionInfo.options.silent = true;
- this._drillThroughModelApi.applyModelChange(this.callbackPayload.prevValue, transactionInfo.options);
- }
- },
- startTransaction: function startTransaction(prefix, options, transactionArgs, transactionType) {
- var startStart = Date.now();
- this._transactionType = transactionType || this.TRANSACTION_TYPE_DEFAULT;
- this._transactionArgs = transactionArgs || {};
- // If a transaction id provided in the transactionArgs, then use it.
- var transactionId = transactionArgs && transactionArgs.transactionId || UniqueId.get(prefix);
- if (!this._mainTransaction && !this._transactionInProgress(options)) {
- options = options || {};
- options.payloadData = options.payloadData || {};
- this._mainTransaction = transactionId;
- options.payloadData.undoRedoTransactionId = this._mainTransaction;
- options.silent = true;
- this.callbackPayload = {
- //Make a clone
- prevValue: JSON.parse(JSON.stringify(this._drillThroughModelApi.toJSON()))
- };
- } else {
- options.silent = true;
- }
- return {
- startStart: startStart,
- startEnd: Date.now(),
- options: options,
- transactionId: transactionId
- };
- },
- _transactionInProgress: function _transactionInProgress(options) {
- return options && options.payloadData && options.payloadData.undoRedoTransactionId;
- },
- endTransaction: function endTransaction(transactionInfo) {
- if (transactionInfo.transactionId === this._mainTransaction) {
- //var endStart=Date.now();
- transactionInfo.options.silent = false;
- var newValue = this._drillThroughModelApi.toJSON();
- this.callbackPayload.value = newValue;
- transactionInfo.options = transactionInfo.options || {};
- transactionInfo.options.sender = 'DrillThroughTransaction';
- transactionInfo.options.senderContext = {
- applyFn: this.applyUndoRedo.bind(this, this.callbackPayload)
- };
- this._drillThroughModelApi.applyModelChange(newValue, transactionInfo.options);
- }
- }
- });
- return DrillThroughUndoRedoTransaction;
- });
- //# sourceMappingURL=DrillThroughManageUndoRedo.js.map
|