transaction manager demo

by marco pretelli

HTML

<script src="https://rawgit.com/marco64bit/Angular-Transaction-manager/master/src/transactionManager.js"></script>
   <div ng-controller="MainCtrl" class="hero-unit">
            <h3>Transaction Manager</h3>

            <button class="btn" ng-click="myHistory.snapshot(foo)">Make a snapshot</button>
            <button class="btn" ng-show="myHistory.hasSnapshot(foo)" ng-click="myHistory.clear(foo)">Clear all snapshots</button>
            <br>
            {{foo.name}} : {{foo.age}}
            <br>
            <input ng-model="foo.name" placeholder="Name">
            <input type="number" ng-model="foo.age" placeholder="Age">
            <br>
            <button class="btn" ng-show="myHistory.canRollback(foo)" ng-click="myHistory.rollback(foo)">Rollback</button>
            <button class="btn" ng-show="myHistory.canRestorePrevious(foo)" ng-click="myHistory.restorePrevious(foo)">Restore previous state</button>
            <!-- all snapshots -->
            <div ng-show="myHistory.hasSnapshot(foo)">
                <b>Snapshots:</b>
                <div ng-repeat="snapshot in foo.snapshot">
                    <div>{{ snapshot }}</div>
                </div>
            </div>
        </div>

JavaScript

var myApp = angular.module('myApp', ['transactionManager']);

function MainCtrl($scope, TransactionManager) {
    $scope.foo = {name: "marco", age: 20};
    $scope.myHistory = TransactionManager;
};