pleasewait.ts 1.34 KB
Newer Older
Tomas Pettersson's avatar
Tomas Pettersson committed
1 2 3
/// <reference path="../def/uikit.d.ts" />


Tomas Pettersson's avatar
Tomas Pettersson committed
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
module STWkit {
    export class PleaseWait {
        public StartMilliseconds: number;
        public ElapsedMilliseconds: number;
        private wait: boolean;
        private modal: any;

        constructor() {
            this.StartMilliseconds = 0;
            this.ElapsedMilliseconds = 0;
        }
        public start() {
            var self = this;
            self.StartMilliseconds = new Date().getTime();
            self.wait = true;
            setTimeout(function () {
                if (self.wait) self.modal = self.pleaseWaitModal();
            }, 500);
        }
        public stop() {
            var self = this;
            this.ElapsedMilliseconds = new Date().getTime() - this.StartMilliseconds;
            self.wait = false;
            if (self.modal) {
                var timeLeft = 2000 - self.ElapsedMilliseconds; // wait minimum 2 sec
                if (timeLeft > 0) {
                    setTimeout(function () {
                        self.modal.hide();
                    }, timeLeft);
                } else {
Tomas Pettersson's avatar
Tomas Pettersson committed
34
                    self.modal.hide();
Tomas Pettersson's avatar
Tomas Pettersson committed
35
                }
Tomas Pettersson's avatar
Tomas Pettersson committed
36
            }
Tomas Pettersson's avatar
Tomas Pettersson committed
37
        } 
Tomas Pettersson's avatar
Tomas Pettersson committed
38

Tomas Pettersson's avatar
Tomas Pettersson committed
39 40 41
        private pleaseWaitModal() {
            return UIkit.modal.blockUI('<div class="uk-modal-spinner"></div><div class="uk-margin-botttom"><b>Please wait...</b></div>');
        }
Tomas Pettersson's avatar
Tomas Pettersson committed
42
    }
Tomas Pettersson's avatar
Tomas Pettersson committed
43
}