From 525581bada6e4ffbff65c26b076b4ebb22990cc0 Mon Sep 17 00:00:00 2001 From: James Allen Date: Tue, 17 Jun 2014 16:36:08 +0100 Subject: [PATCH] Add in test loading spinner --- services/web/app/views/layout.jade | 14 +++-- .../coffee/app/directives/asyncForm.coffee | 57 +++++++++++++++++++ services/web/public/coffee/app/main.coffee | 4 +- services/web/public/stylesheets/app/base.less | 6 ++ services/web/public/stylesheets/style.less | 1 + 5 files changed, 75 insertions(+), 7 deletions(-) create mode 100644 services/web/public/coffee/app/directives/asyncForm.coffee create mode 100644 services/web/public/stylesheets/app/base.less diff --git a/services/web/app/views/layout.jade b/services/web/app/views/layout.jade index 21564b4fcb..de44b7058f 100644 --- a/services/web/app/views/layout.jade +++ b/services/web/app/views/layout.jade @@ -37,11 +37,14 @@ html(itemscope, itemtype='http://schema.org/Product') script(src=jsPath+'libs/underscore-1.3.3.js') block scripts - - if (typeof(bodyClasses) == "undefined") - - var bodyClasses = [] - body(class=bodyClasses) - include layout/navbar - block content + body + #ng-app(style="display: none;") + include layout/navbar + block content + include layout/footer + #ng-app-loading + i.fa.fa-spin.fa-refresh + - if (typeof(lookingForScribtex) != "undefined" && lookingForScribtex) .modal.hide#scribtexModal .modal-header @@ -53,7 +56,6 @@ html(itemscope, itemtype='http://schema.org/Product') a(href="https://scribtex.sharelatex.com#{scribtexPath}", style="font-size: 16px") https://scribtex.sharelatex.com#{scribtexPath} .modal-footer button(data-dismiss="modal").btn OK - include layout/footer script(type='text/javascript'). window.requirejs = { diff --git a/services/web/public/coffee/app/directives/asyncForm.coffee b/services/web/public/coffee/app/directives/asyncForm.coffee new file mode 100644 index 0000000000..4a168525f7 --- /dev/null +++ b/services/web/public/coffee/app/directives/asyncForm.coffee @@ -0,0 +1,57 @@ +define [ + "base" +], (App) -> + App.directive "asyncForm", ($http) -> + return { + link: (scope, element, attrs) -> + formName = attrs.asyncForm + + element.on "submit", (e) -> + e.preventDefault() + + formData = {} + for data in element.serializeArray() + formData[data.name] = data.value + + $http + .post(element.attr('action'), formData) + .success (data, status, headers, config) -> + scope.success = true + scope.error = false + + if data.redir? + ga('send', 'event', formName, 'success') + window.location = data.redir + else if data.message? + scope.message = data.message + + if data.message.type == "error" + scope.success = false + scope.error = true + ga('send', 'event', formName, 'failure', data.message) + else + ga('send', 'event', formName, 'success') + + .error (data, status, headers, config) -> + scope.success = false + scope.error = true + ga('send', 'event', formName, 'failure', data.message) + scope.message = + text: data.message or "Something went wrong talking to the server :(. Please try again." + type: 'error' + } + + App.directive "formMessages", () -> + return { + restrict: "E" + template: """ +
+ {{message.text}} +
+
+ """ + transclude: true + } \ No newline at end of file diff --git a/services/web/public/coffee/app/main.coffee b/services/web/public/coffee/app/main.coffee index b4c8c03271..06c44cba61 100644 --- a/services/web/public/coffee/app/main.coffee +++ b/services/web/public/coffee/app/main.coffee @@ -3,4 +3,6 @@ define [ "user-details" "directives/asyncForm" ], () -> - angular.bootstrap(document.body, ["SharelatexApp"]) \ No newline at end of file + angular.bootstrap(document.getElementById("ng-app"), ["SharelatexApp"]) + $("#ng-app").show() + $("#ng-app-loading").hide() \ No newline at end of file diff --git a/services/web/public/stylesheets/app/base.less b/services/web/public/stylesheets/app/base.less new file mode 100644 index 0000000000..e96126f7e1 --- /dev/null +++ b/services/web/public/stylesheets/app/base.less @@ -0,0 +1,6 @@ +#ng-app-loading { + position: absolute; + top: 45%; + width: 100%; + text-align: center; +} \ No newline at end of file diff --git a/services/web/public/stylesheets/style.less b/services/web/public/stylesheets/style.less index 81bcdf9730..7ad9eb0f2e 100755 --- a/services/web/public/stylesheets/style.less +++ b/services/web/public/stylesheets/style.less @@ -52,5 +52,6 @@ @import "core/responsive-utilities.less"; // ShareLaTeX app classes +@import "app/base.less"; @import "app/project-list.less"; @import "app/editor.less";