[ExercisePlanner] updated ExercisePlanner sources
authorPiotr Dabrowski <p.dabrowski2@samsung.com>
Fri, 26 Jul 2013 13:11:29 +0000 (15:11 +0200)
committerPiotr Dabrowski <p.dabrowski2@samsung.com>
Fri, 26 Jul 2013 13:11:29 +0000 (15:11 +0200)
Change-Id: I523d2fe3aa0ee1d5de512ebc154acc54df0c3c54

index.html
js/UI.js

index f7004c0..20b3416 100644 (file)
 
        </div>
 
+       <div data-role="popup" id="popup">
+               <div class="ui-popup-text">
+                       <p class="text"></p>
+               </div>
+               <div class="ui-popup-button-bg"></div>
+       </div>
+
        <div id="progress">
                <div id="progresscenter">
                        <div id="progresstitle"></div>
index e19fcbc..a623909 100644 (file)
--- a/js/UI.js
+++ b/js/UI.js
@@ -1,5 +1,5 @@
 /*jslint nomen: true*/
-/*global $, GraphSchedule, confirm, range, history, setTimeout */
+/*global $, GraphSchedule, range, history, setTimeout */
 function UI() {
        "use strict";
 }
@@ -47,6 +47,35 @@ function UI() {
                });
        };
 
+       UI.prototype.popup = function (text, callback) {
+               var i, popup = $("#popup"),
+                       buttons = {'Close': function () { $("#popup").popup('close') }};
+               // to hide default button give {'Close': false} in callback
+
+               for (i in callback) {
+                       if (callback.hasOwnProperty(i)) {
+                               buttons[i] = callback[i];
+                       }
+               }
+
+               $(".ui-popup-button-bg", popup).empty();
+               for (i in buttons) {
+                       if (buttons.hasOwnProperty(i)) {
+                               if (buttons[i]) {
+                                       $('<a/>')
+                                               .text(i)
+                                               .attr({'data-role': 'button', 'data-inline': 'true'})
+                                               .bind('tap', buttons[i])
+                                               .appendTo($(".ui-popup-button-bg", popup));
+                               }
+                       }
+               }
+               $(".text", popup).text(text);
+
+               popup.trigger("create");
+               popup.popup('open', {positionTo: 'window'});
+       };
+
        UI.prototype.clearTabbars = function () {
                $('[data-role = "tabbar"] li > a').removeClass('ui-focus, ui-btn-active');
        };
@@ -65,7 +94,7 @@ function UI() {
                $('#availableTime').listview().listview('refresh');
                $('#availableTime :jqmData(name=edit)').on('tap', function (e) {
                        if (self.app.config.trainingEnabled) {
-                               alert('You should stop the training first');
+                               self.popup('You should stop the training first');
                        } else {
                                e.preventDefault();
                                e.stopPropagation();
@@ -74,7 +103,7 @@ function UI() {
                });
                $('#availableTime :jqmData(name=disable)').on('tap', function (e) {
                        if (self.app.config.trainingEnabled) {
-                               alert('You should stop the training first');
+                               self.popup('You should stop the training first');
                        } else {
                                e.stopPropagation();
                                self.app.disableTimeRange($(this).data('val'));
@@ -84,14 +113,15 @@ function UI() {
                        var value = $(this).data('val');
                        e.stopPropagation();
                        if (self.app.config.trainingEnabled) {
-                               alert('You should stop the training first');
+                               self.popup('You should stop the training first');
                                return;
                        }
-                       setTimeout(function () {
-                               if (confirm('Are you sure?')) {
+                       self.popup('Are you sure?', {
+                               'Delete': function () {
                                        self.app.deleteTimeRange(value);
+                                       $("#popup").popup('close');
                                }
-                       }, 20);
+                       });
                });
        };
 
@@ -298,6 +328,8 @@ function UI() {
                var self = this;
 
                // bind events;
+               $("#popup").popup();
+
                $('#one .ui-btn-back').on('tap', this.app.exit.bind(this.app));
 
                $('#ok').on('tap', self.app.ok.bind(self.app));
@@ -406,7 +438,7 @@ function UI() {
 
                        $('#addTimeRange').on('tap', function (e) {
                                if (self.app.config.trainingEnabled) {
-                                       alert('You should stop the training first');
+                                       self.popup('You should stop the training first');
                                } else {
                                        self.editTimeRange(-1, e);
                                }
@@ -426,7 +458,7 @@ function UI() {
                });
 
                $('#customExercises').on('pageinit', function (page, options) {
-                       $('#btnNewExercise').on('tap', function (e) {
+                       $('#btnNewExercise').on('vmousedown', function (e) {
                                e.preventDefault();
                                e.stopPropagation();
                                if ($(this).data('disabled') !== true) {