Example #1
0
 error: function(){
     that.isUpdating = false;
     Utils.Notification.Toast('Failed loading more Alerts!');
     that.render_infinity_buttons();
 }
Example #2
0
 function (e) {
     console.error(e);
     Utils.Notification.Toast('Upload failed');
 }, options);
Example #3
0
    PageView.prototype.save_todo = function(ev){
        var that = this;

        if(this.checking === true){
            // return;
        }
        this.checking = true;

        var formData = {};

        // Determine what data, and format, we'll send up to the server to store this Todo
        // formData.images = this.summary.images;

        // // picture (only taking one for now)
        // if(!this.summary.media_id){
        //     Utils.Notification.Toast('Include a picture!');
        //     return;
        // }
        // formData.images = [this.summary.media_id];

        // title
        formData.title = this._inputs['title'].getValue().toString();
        if(!formData.title){
            Utils.Notification.Toast('Include a title!');
            return;
        }

        // detail/description
        formData.details = this._inputs['details'].getValue().toString();

        // timeframe
        // - todo...v2 (trying to limit the number of extra options) (maybe have a + sign to expand advanced options?)

        // // Group_id
        // formData.group_id = this.summary.group.get('_id');

        // // payment
        // if(!this.summary.payment){
        //     Utils.Notification.Toast('Include a payment method!');
        //     return;
        // }
        // formData.payment_source_id = this.summary.payment._id;

        this.submitButton.setContent('..Please Wait..');

        // Get elements to save
        this.model.set(formData);

        this.model.save()
            .fail(function(){
    
                that.checking = false;
                that.submitButton.setContent('Create Job');                

            })
            .then(function(newModel){

                // that.checking = false;
                // that.submitButtonSurface.setContent('Create Todo');


                // Create the new one
                // - causes a "populated" to be created that is valid
                var newTodo = new TodoModel.Todo(newModel);


                // Clear player cache
                // - todo...

                // Clear history
                App.history.eraseUntilTag('StartAdd');

                // Redirect to the new Todo
                App.history.navigate('todo/' + newModel._id);

                

            });

        return false;
    };
Example #4
0
 }, function(message){
     // failed taking a picture
     console.log(message);
     console.log(JSON.stringify(message));
     Utils.Notification.Toast('Failed picture');
 });
Example #5
0
    PageView.prototype.upload_todo_image = function(imageURI){
        var that = this;

        Utils.Notification.Toast('Uploading');

        console.log('uploading...');
        console.log(this.player_id);
        console.log({
            token : App.Data.UserToken,
            extra: {
                "description": "Uploaded from my phone testing 234970897"
            }
        });

        var ft = new FileTransfer(),
            options = new FileUploadOptions();

        options.fileKey = "file";
        options.fileName = 'filename.jpg'; // We will use the name auto-generated by Node at the server side.
        options.mimeType = "image/jpeg";
        options.chunkedMode = false;
        options.params = {
            token : App.Data.UserToken,
            // player_id : this.player_id,
            extra: {
                "description": "Uploaded from my phone testing 293048"
            }
        };

        ft.onprogress = function(progressEvent) {
            
            if (progressEvent.lengthComputable) {
                // loadingStatus.setPercentage(progressEvent.loaded / progressEvent.total);
                // console.log('Percent:');
                // console.log(progressEvent.loaded);
                // console.log(progressEvent.total);
                console.log((progressEvent.loaded / progressEvent.total) * 100);
                Utils.Notification.Toast((Math.floor((progressEvent.loaded / progressEvent.total) * 1000) / 10).toString() + '%');
            } else {
                // Not sure what is going on here...
                // loadingStatus.increment();
                console.log('not computable?, increment');
            }
        };
        ft.upload(imageURI, Credentials.server_root + "media/todophoto",
            function (r) {
                // getFeed();
                // alert('complete');
                // alert('upload succeeded');
                Utils.Notification.Toast('Upload succeeded');
                Utils.Notification.Toast('~30 seconds to process');

                // r.responseCode
                var response = JSON.parse(r.response);

                // Expecting to get back a media_id that we'll use for uploading the Todo/Pickup

                if(response._id){
                    Utils.Notification.Toast(response._id);
                    that.summary.media_id = response._id;
                }



                // // update collection
                // Timer.setTimeout(function(){
                //     that.model.fetch();
                // },5000);

            },
            function (e) {
                console.error(e);
                Utils.Notification.Toast('Upload failed');
            }, options);
    };
Example #6
0
        onReady: function(){
            
            if(this.isReady === true){
                return;
            }
            this.isReady = true;

            // Overwrite console.log and console.info

            // console.log('overwrite log');
            // console.log = (function(){
            //     var originalLog = console.log;
            //     var newLog = function(){
            //         if(1==1){
            //             return;
            //         }
            //         originalLog.apply(this, arguments);
            //     }
            //     return newLog;
            // })();

            // console.info('overwrite info');
            // console.info = (function(){
            //     var originalLog = console.info;
            //     var newLog = function(){
            //         if(1==1){
            //             return;
            //         }
            //         originalLog.apply(this, arguments);
            //     }
            //     return newLog;
            // })();


            // // FastClick attachment to document.body
            // console.log(document.body);
            // attachFastClick.attach(document.body);

            // Android or iOS stylesheet?
            App.Config.devicePlatform = 'android';
            try {
                App.Config.devicePlatform = device.platform.toLowerCase();
            }catch(err){}
            $('head').append('<link rel="stylesheet" href="css/'+ App.Config.devicePlatform +'.css" type="text/css" />');

            // Status bar colors
            try {

                if(App.Config.devicePlatform == 'ios'){

                    // App.MainView has NOT been created yet
                    App.StatusBar = true;

                    StatusBar.overlaysWebView(true);
                    StatusBar.backgroundColorByHexString(App.ConfigImportant.StatusBarBackgroundColor);
                    // Utils.Notification.Toast('OK status bar');
                }
            }catch(err){
                console.log(err);
                Utils.Notification.Toast('Failed status bar');
            }

            // Resolve deferred
            this.readyDeferred.resolve();

            // Stripe
            Stripe.setPublishableKey(Credentials['stripe_publishable_key_' + Credentials.stripe_mode]);

            // Track.js
            // - only using in production
            if(App.Data.usePg && App.Prod){

                // lazy-load track.js
                var script = document.createElement( 'script' );
                script.type = 'text/javascript';
                script.src = 'src/lib2/track.js';
                // $(script).attr('data-token', Credentials.trackjs_token);

                // trackjs options
                window._trackJs = Credentials.trackjs_opts;
                window._trackJs.version = App.ConfigImportant.Version;
                $("body").append( script );

                // // Need to init it first
                // console.error();

                // //override the error function (the immediate call function pattern is used for data hiding)
                // console.error = (function () {
                //   //save a reference to the original error function.
                //   var originalConsole = console.error;
                //   //this is the function that will be used instead of the error function
                //   function myError (stackTrace) {
                //     // alert( 'Error is called. ' );
                //     try {
                //         trackJs.track(stackTrace);
                //     }catch(err){
                //         console.log('trackJs.track non-existant for now');
                //     }

                //     //the arguments array contains the arguments that was used when console.error() was called
                //     originalConsole.apply( this, arguments );
                //   }
                //   //return the function which will be assigned to console.error
                //   return myError;
                // })();

                // // Overwrite window.onerror
                // window.onerror = function (errorMsg, url, lineNumber) {
                //     // lineNumber doesn't mean anything, it is relative to the function that was called! (not the page)
                //     console.error(errorMsg, url, lineNumber);
                // }

                
                // // Testing in production
                // window.setTimeout(function(){
                //     // Throw a failure
                //     throw WeAreInProduction
                // },3000);

            }


            // try {
            //  window.plugin.notification.local.add({ id: 1, title: "Waiting Title", message: 'Great app!' });
            // }catch(err){
            //  alert('noti error');
            //  console.log(err);
            // }

            // Push notifications
            if(App.Credentials.push_notifications === true){
                this.initPush();
            }


            // Keyboard
            // - requires ionic keyboard plugin
            try {
                // disable keyboard scrolling
                cordova.plugins.Keyboard.disableScroll(true);
            }catch(err){
                console.error(err, 'no Keyboard');
            }
            // add listeners for keyboard show/hide
            window.addEventListener('native.keyboardshow', function(e){
                // Utils.Notification.Toast('Keyboard Show');

                var keyboardHeight = e.keyboardHeight;

                // Has the body changed in height?
                // if yes, set that as the keyboardHeight
                if(App.defaultSize[1] != window.innerHeight){
                    keyboardHeight = App.defaultSize[1] - window.innerHeight;
                } else {
                    // if no, use the supplied keyboardHeight
                    switch(App.Config.devicePlatform){
                        case 'android':
                            keyboardHeight -= 40;
                            break;
                        case 'ios':
                            break;
                        default:
                            break;
                    }
                }

                App.mainSize = [App.defaultSize[0],App.defaultSize[1] - keyboardHeight];
                App.MainContext.emit('resize');

                App.KeyboardShowing = true;
                App.Events.emit('KeyboardShowHide', true);

                App.Events.emit('resize');

                // App.mainSize = App.MainContext.getSize();
                // if (App.MainController)
                //     App.MainController.setOptions({size: [App.mainSize[0], App.mainSize[1]]});

            });
            window.addEventListener('native.keyboardhide', function(e){
                // Utils.Notification.Toast('Keyboard HIDE');
                
                App.mainSize = [App.defaultSize[0],App.defaultSize[1]];
                App.MainContext.emit('resize');

                // Update the page (tell 'em)
                App.KeyboardShowing = false;
                App.Events.emit('KeyboardShowHide', false);

                App.Events.emit('resize');
                
                // App.mainSize = App.MainContext.getSize();
                // if (App.MainController)
                //     App.MainController.setOptions({size: [App.mainSize[0], App.mainSize[1]]});

            });

            // Pausing (exiting)
            document.addEventListener("pause", function(){
                // Mark as Paused
                // - this prevents Push Notifications from activating all at once when Resuming

                App.Data.paused = true;
                App.Data.was_paused = true;
                
                App.Events.trigger('pause');

            }, false);

            // Back button capturing in Browser
            if(!App.Data.usePg){
                $(document).keydown(function (e) {
                    var preventKeyPress;
                    if (e.keyCode == 8) {
                        var d = e.srcElement || e.target;
                        switch (d.tagName.toUpperCase()) {
                            case 'TEXTAREA':
                                preventKeyPress = d.readOnly || d.disabled;
                                break;
                            case 'INPUT':
                                preventKeyPress = d.readOnly || d.disabled ||
                                    (d.attributes["type"] && $.inArray(d.attributes["type"].value.toLowerCase(), ["radio", "checkbox", "submit", "button"]) >= 0);
                                break;
                            case 'DIV':
                                preventKeyPress = d.readOnly || d.disabled || !(d.attributes["contentEditable"] && d.attributes["contentEditable"].value == "true");
                                break;
                            default:
                                preventKeyPress = true;
                                break;
                        }
                    }
                    else
                        preventKeyPress = false;

                    if (preventKeyPress){
                        e.preventDefault();
                        App.Events.emit('backbutton');
                    }
                });
            }

            // Resume
            // - coming back to application
            document.addEventListener("resume", function(resume_data){
                // Gather existing Push Notifications and see if we should summarize them, or show individually (confirm, etc.)
                    
                App.Events.trigger('resume');
                console.log('resuming');
                console.log(resume_data);

                console.log(JSON.stringify(resume_data));

                App.Data.paused = false;
                App.Data.was_paused = true;

                // Run 1 second after returning
                // - collecting all the Push Notifications into a queue
                // - enough time for all Push events to be realized
                setTimeout(function(){

                    App.Data.paused = false;
                    App.Data.was_paused = false;

                    // // Get queue
                    // // - more than 1 item in queue?
                    // // - different types of items?
                    // switch (App.Data.notifications_queue.length){
                    //     case 0:
                    //         // No messages
                    //         break;
                    //     case 1:
                    //         // Only a single message, use normal
                    //         Utils.process_push_notification_message(App.Data.notifications_queue.pop());
                    //         break;
                    //     default:
                    //         // Multiple notifications
                    //         // - get last added
                    //         // alert(App.Data.notifications_queue.length + ' Push Notifications Received. Latest Processed');
                    //         Utils.process_push_notification_message(App.Data.notifications_queue.pop());
                    //         App.Data.notifications_queue = [];
                    //         break;
                    // }
                    // var queue = App.Data.notifications_queue.concat([]);

                    // - assuming 1 type of Push Notification only at this time

                },1000);

            }, false);


            // Init MENU button on Android (not always there?)
            document.addEventListener("menubutton", function(){
                // - only launches the settings if we're on the main view
                App.history.navigate('settings');
            }, false);

            // Init BACK button on Android
            // - disable default first
            document.addEventListener("backbutton", function(killa){
                App.Events.emit('backbutton');
                killa.stopPropagation();
                killa.preventDefault();
                return false;
            }, true);

            // // Online/Offline state

            // //Create the View
            // // - render too
            // App.Data.GlobalViews.OnlineStatus = new App.Views.OnlineStatus();
            // App.Data.GlobalViews.OnlineStatus.render();

            // // Online
            // // - remove "not online"
            // document.addEventListener("online", function(){
            //  // Am now online
            //  // - emit an event?
            //  App.Data.GlobalViews.OnlineStatus.trigger('online');

            // }, false);
            // document.addEventListener("offline", function(){
            //  // Am now online
            //  // - emit an event?
            //  App.Data.GlobalViews.OnlineStatus.trigger('offline');

            // }, false);
            



            
        },
Example #7
0
        historyObj.navigate = function(path, opts, back, reloadCurrent){

            console.log('historyObj.navigate: path:', path, arguments);
            // console.trace();

            opts = opts || {};

            opts = _.defaults(opts, {
                history: true, // add to history
                group: null,
                tag: null
            });

            if(back === true){
                // Get the last entry, see if we can go back to it
                // - todo, compare saved opts, etc.

                // Remove the "current entry"
                // - reload the last one (after pop'ing it out too)
                var currentArgs = historyObj.data.pop();
                console.log(currentArgs);

                var lastArgs = historyObj.data.pop();
                console.log('lastArgs', lastArgs);

                if(lastArgs === undefined || !lastArgs || lastArgs.length < 1 || lastArgs[0] == ''){
                    // No last arguments exist
                    // alert('Exiting app');
                    Utils.Notification.Toast('Exiting App');
                    console.error('exiting app');
                    historyObj.navigate('dash');
                    return;
                }

                // debugger;

                historyObj.isGoingBack = true;
                console.log('isGoingBack==true');
                historyObj.navigate.apply(HistoryContext, lastArgs);

                return;
            }

            if(reloadCurrent === true){
                // Reload the currently-in-place history event
                // - should be used when you want to go "back" from a history:false page

                // pop it out from the array, it'll get popped back in
                var lastArgs = historyObj.data.pop();
                console.log('lastArgs', lastArgs);

                if(lastArgs === undefined || !lastArgs || lastArgs.length < 1 || lastArgs[0] == ''){
                    // No last arguments exist
                    Utils.Notification.Toast('Exiting App');
                    console.error('Exiting app, reloadCurrent failed');
                    historyObj.navigate('dash');
                    return;
                }

                historyObj.isGoingBack = true; // yes, keep as "is going back" from whatever is currently displayed
                historyObj.navigate.apply(HistoryContext, lastArgs);

                return;
            }

            // be able to "tag" a history event, and then "erase" all the ones since that one
            // keep "groups" together: viewing a bunch of users in a row, then going "back" to the Dash

            // options
            console.log('Running backbone.history', path);

            // Replace the URL
            // console.log(DefaultRouter);
            // console.log(DefaultRouter.handlers);
            // console.log(App.StartRouter);
            // console.log(App.StartRouter.handlers);
            // console.log(App.StartRouter.routes);
            // console.log(Object.keys(App.StartRouter.routes));
            // _.find(Object.keys(App.StartRouter.routes), function(theRoute){
            //     console.log(theRoute);
            //     console.log(App.StartRouter._routeToRegExp(theRoute));
            //     if(App.StartRouter._routeToRegExp(theRoute).test(path)){

            //     // }
            //     // if(theRoute.toString().test(path)) {
            //       // handler.callback();
            //       // debugger;
            //       // App.StartRouter.routes[theRoute](); // call the function
            //       return true;
            //     }
            // });

            // pass arguments
            // - update with default options? (no, pass exactly as before)
            if(opts.history == true){
                historyObj.data.push([
                    path, opts, back
                ]);
            }

            Backbone.history.navigate(path, {trigger: true, replace: true});


        };
Example #8
0
 Timer.setTimeout(function(){
     Utils.Notification.Toast('Refreshing');
     that.model.fetch();
 },5000);
Example #9
0
 Utils.takePicture('gallery', {}, that.uploadProfileImage.bind(that), function(message){
     // failed taking a picture
     console.log(message);
     console.log(JSON.stringify(message));
     Utils.Notification.Toast('Failed picture');
 });
Example #10
0
 }, function(err){
     Utils.Notification.Toast('Failed loading contacts');
     def.reject(err);
 }, options);
Example #11
0
                success: function(){
                    
                    Utils.Notification.Toast('Not implemented yet');

                }
    PageView.prototype.uploadMedia = function(imageURI){
        var that = this;

        Utils.Notification.Toast('Uploading');

        console.log('uploading...');
        console.log(this.player_id);
        console.log({
            token : App.Data.UserToken,
            // player_id : this.player_id,
            extra: {
                "description": "Uploaded from my phone testing 234970897"
            }
        });

        var ft = new FileTransfer(),
            options = new FileUploadOptions();

        options.fileKey = "file";
        options.fileName = 'filename.jpg'; // We will use the name auto-generated by Node at the server side.
        options.mimeType = "image/jpeg";
        options.chunkedMode = false;
        options.params = {
            token : App.Data.UserToken,
            contest_id: that.contest_id,
            extra: {
                "description": "Uploaded from my phone testing 193246"
            }
        };

        ft.onprogress = function(progressEvent) {
            
            if (progressEvent.lengthComputable) {
                // loadingStatus.setPercentage(progressEvent.loaded / progressEvent.total);
                // console.log('Percent:');
                // console.log(progressEvent.loaded);
                // console.log(progressEvent.total);
                console.log((progressEvent.loaded / progressEvent.total) * 100);
                Utils.Notification.Toast((Math.floor((progressEvent.loaded / progressEvent.total) * 1000) / 10).toString() + '%');
            } else {
                // Not sure what is going on here...
                // loadingStatus.increment();
                console.log('not computable?, increment');
            }
        };
        ft.upload(imageURI, App.Credentials.server_root + "contestcontent/media",
            function (e) {
                // getFeed();
                // alert('complete');
                // alert('upload succeeded');
                Utils.Notification.Toast('Upload succeeded');
                Utils.Notification.Toast('~10 seconds to process');

                // update collection
                Timer.setTimeout(function(){
                    that.contestContent.collection.fetch();
                },5000);

            },
            function (e) {
                console.error(e);
                Utils.Notification.Toast('Upload failed');
            }, options);
    };
Example #13
0
    PageView.prototype.submit_forgot = function(ev){
        var that = this;

        if(this.checking === true){
            return;
        }
        this.checking = true;

        // Get email and password
        var email = $.trim(this.inputEmail.getValue().toString());
        if(email.length === 0){
            this.checking = false;
            Utils.Notification.Toast('Email Missing');
            return;
        }

        // Disable submit button
        this.submitButton.setContent('Please wait...');

        // data to POST
        // - just the email
        var dataBody = {
            email: email
            // code: code,
        };

        // Try sending a reset email
        $.ajax({
            url: Credentials.server_root + 'forgot',
            method: 'POST',
            data: dataBody,
            error: function(err){
                // failed somehow
                // - if it was a "valid" (structured correctly) email, we'll ALWAYS return "if an account exists for this email, we've sent a reset password"

                console.log(err);

                Utils.Notification.Toast('Failed sending email');
                that.submitButton.setContent('Send Reset Email');
                that.checking = false;

            },
            success: function(response){
                // Success logging in
                // - awesome!
                
                if(response.complete == true){
                    // Awesome, sent a reset email

                    // Surfaces for success (after submitting)
                    var successSurface = new Surface({
                        content: "Sent Reset Email",
                        size: [undefined, 80],
                        classes: ['sent-reset-email-surface']
                    });

                    that.form._formScrollView.Views = [successSurface];
                    that.form._formScrollView.sequenceFrom(that.form._formScrollView.Views);

                    Utils.Notification.Toast('Sent Reset Email');

                    return;

                }

                // See what the error was
                switch(response.msg){
                    case 'bademail':
                        alert('Sorry, that does not look like an email address to us.');
                        break;
                    case 'duplicate':
                        alert('Sorry, that email is already in use.');
                        break;
                    case 'unknown':
                    default:
                        alert('Sorry, we could not send a reset email at the moment, please try again!');
                        break;

                }

                // Re-enable submit button
                that.submitButton.setContent('Send Reset Email');
                that.checking = false;

                return false;

            }

        });

    };
Example #14
0
 function (e) {
     // getFeed();
     // alert('complete');
     // alert('upload succeeded');
     Utils.Notification.Toast('Upload succeeded');
 },
Example #15
0
    PageView.prototype.create_account = function(ev){
        var that = this;

        if(this.checking === true){
            return;
        }
        this.checking = true;

        // Get email and password
        var email = $.trim(this.inputEmail.getValue().toString());
        if(email.length === 0){
            this.checking = false;
            Utils.Notification.Toast('Email Missing');
            return;
        }
        // todo: validate email

        var password = this.inputPassword.getValue().toString();

        // var profile_name = this.inputNameSurface.getValue().toString();
        // if(profile_name.length < 1){
        //     Utils.Notification.Toast('Enter your Name!');
        //     return;
        // }

        // Disable submit button
        this.submitButton.setContent('Please wait...');

        // return;

        // data to POST
        var dataBody = {
            email: email,
            password: password,
            platform: App.Config.devicePlatform
            // profile_name: profile_name
            // code: code,
        };
        console.log(dataBody);
        
        // Try signup
        // - and then login
        that.model.signup(dataBody)
        .then(function(result){
            
            that.submitButton.setContent('Logging In');

            // Login
            // - same as Login.js
            that.model.login(dataBody)
            .fail(function(){

                that.checking = false;
                that.submitButton.setContent('Sign Up');

                // invalid login
                console.error('Fail, invalid login');

                // Toast
                Utils.Notification.Toast('Failed login after signup');

                // Go to login
                App.history.navigate('login');

            })
            .then(function(response){
                // Success logging in

                that.checking = false;
                that.submitButton.setContent('Sign Up');

                // Go to signup/home (will get redirected)
                App.history.eraseUntilTag('all-of-em');
                App.history.navigate(App.Credentials.home_route);

            });


        })
        .fail(function(){

            Utils.Notification.Toast('Failed creating Waiting account');
            that.submitButton.setContent('Sign Up');
            that.checking = false;
        });

    };
Example #16
0
 function (e) {
     alert("Upload failed");
     Utils.Notification.Toast('Upload failed');
     // Utils.Notification.Toast(e);
 }, options);
Example #17
0
        .fail(function(){

            Utils.Notification.Toast('Failed creating Waiting account');
            that.submitButton.setContent('Sign Up');
            that.checking = false;
        });
Example #18
0
 window.setTimeout(function(){
     Utils.Notification.Alert('failed Push Notifications');
 },2000);