pyc-website
main website for pyc inc.
git clone https://9o.is/git/pyc-website.git
commit 030e1ee489a2cf29d40e07c9483a18dc573c9a42 parent 13b36a9b497fb1446bf3d4ce79b86d814e1820cd Author: Jul <jul@9o.is> Date: Fri, 2 May 2014 03:52:39 -0400 modularized snippets, ng ui-router, and App.js Diffstat:
22 files changed, 355 insertions(+), 464 deletions(-)
diff --git a/src/main/scala/inc/pyc/lib/NgUIRouter.scala b/src/main/scala/inc/pyc/lib/NgUIRouter.scala @@ -65,25 +65,55 @@ trait NgUIRouterSnip extends SnippetHelper { app <- S.attr("ngApp") ?~ "ngApp name is missing" } yield "* *" #> { import NgUIRouterFactory._ + type Cmd = String - val otherwise = defaultRoute.vend map { - "$urlRouterProvider.otherwise('"+ - S.contextPath+_.loc.calcDefaultHref+"');" - } openOr "" + // the default route + val otherwise = + defaultRoute.vend map { + "$urlRouterProvider.otherwise('"+S.contextPath+_.loc.calcDefaultHref+"');" + } openOr "" - app+".config(function($stateProvider, $urlRouterProvider,$locationProvider) {"+ - "$locationProvider.html5Mode("+html5mode.vend.toString+");"+ - otherwise+"$stateProvider"+ - routes.vend.map { menu => + // ng ui-router config + val config = + """ + .config(function($stateProvider, $urlRouterProvider,$locationProvider) { + $locationProvider.html5Mode("""+html5mode.vend.toString+"""); + """+otherwise+""" + $stateProvider"""+{ + routes.vend.map { menu => + val templateUrl = S.contextPath+menu.loc.calcDefaultHref + val state: String = menu.loc.name.replaceAll(" ","").toLowerCase + + ".state('"+state+"', {"+ + "url:'"+templateUrl+"',"+ + "views: {'viewA': {"+ + "templateUrl:'"+templateUrl+".html?ajax'"+ + "}}"+ + "})" + }.mkString + }+""" + ;}) + """ - val templateUrl = S.contextPath+menu.loc.calcDefaultHref - val state: String = menu.loc.name.replaceAll(" ","").toLowerCase - - ".state('"+state+"',{url:'"+templateUrl+"',views:"+ - "{'viewA':{templateUrl:'"+templateUrl+".html?ajax'}}"+ - "})" - }.mkString+ - ";});" + // updates lift_toWatch js variable + val updateLiftWatch: Cmd = + """var el = angular.element(document.querySelectorAll(".lift-roundtrip"));"""+ + """for (var i=0;i<el.length;++i) { window.lift_toWatch[el[i].getAttribute("id")] = el[i].getAttribute("when") };""" + + // updates all client side js promises + val updatePromises: Cmd = + """var promises = angular.element(document.querySelectorAll(".lift-promise"));"""+ + """for (var i=0;i<promises.length;++i) { eval(promises[i].innerHTML) };""" + + val log: Cmd = "console.log('$viewContentLoaded is running now ... ');" + + // ng ui-router run when $viewContentLoaded + def runFunc(cmds: Cmd*): Cmd = + """.run(['$rootScope', function($rootScope) {$rootScope.$on('$viewContentLoaded', function() {"""+ + cmds.mkString+"""}); }])""" + + app + config + runFunc(updateLiftWatch, updatePromises) + ";" + // TODO if the first normal page load does not have any roundtrips, cometajax.js is ignored. } diff --git a/src/main/scala/inc/pyc/snippet/AngularSnips.scala b/src/main/scala/inc/pyc/snippet/AngularSnips.scala @@ -11,43 +11,33 @@ import http._ import js._ import JsCmds._ import JE.JsVar +import net.liftmodules.extras.SnippetHelper /** - * Snippet classes with AngularJs server-side code need to extend trait. - * Its js function will be called at the end of Body element if it is added - * to AngularServerSide's 'snips' FactoryMaker. + * Snippet classes with AngularJs server-side code need to extend this. + * Javascript promism */ -trait AngularSnippet { - def roundTrips: RoundTripInfo -} - -/** - * Place this snippet at the end of your end of Body - * - * <script data-lift="AngularServerSide.js"></script> - */ -class AngularServerSide extends Factory { - - /* All AngularJs server-side snippets. */ - private val snips = new FactoryMaker[List[AngularSnippet]](List( - new SearchedPostalSnip, - new AtmApplicationSnip, - new NearAtmNotifySnip, - new UserRegistrationSnip, - new UserLoginSnip, - new ForgotPasswordSnip - )) {} - - def js: CssSel = - "* *" #> (for { - sess <- S.session - } yield { - def roundTrips: List[RoundTripInfo] = snips.vend.map(_.roundTrips) +trait AngularSnippet extends SnippetHelper with Logger { + + def roundTrips: List[RoundTripInfo] + + def render: CssSel = + for (sess <- S.session) yield { + val roundtrips = sess.buildRoundtrip(roundTrips) + + val lastcomet = S.cometAtEnd.last + val whenregex = "<div.*lift:when=\"([0-9]*)\".*/>".r - val script = SetExp(JsVar("window", "backend"), - sess.buildRoundtrip(List[RoundTripInfo](roundTrips: _*))) - script - }) + val when: String = lastcomet.toString match { + case whenregex(when) => when + case _ => "" + } + + val className: String = this.getClass.getName.split("""\.""").last + + "* *+" #> <script class="lift-promise">{SetExp(JsVar("window", className), roundtrips).toJsCmd}</script> & + "* *+" #> <div class="lift-roundtrips">{(lastcomet % ("class" -> "lift-roundtrip") % ("when" -> when))}</div> + } } /** diff --git a/src/main/scala/inc/pyc/snippet/AtmApplicationSnip.scala b/src/main/scala/inc/pyc/snippet/AtmApplicationSnip.scala @@ -1,44 +0,0 @@ -package inc.pyc -package snippet - -import model._ -import field._ -import net.liftweb._ -import common._ -import json.JsonAST._ -import util._ -import Helpers._ -import http._ -import js._ -import JsCmds._ -import SHtml._ -import JE.JsVar - -class AtmApplicationSnip extends AngularSnippet { - - def save(model: JValue): JValue = { - val rec = AtmApplication.createRecord - rec.setFieldsFromJValue(model) - - rec.validate match { - case Nil => - rec.save - NgAlert.success( - <i class="fa-fw fa fa-thumbs-o-up"></i> ++ - <strong>{ s"Your Bitcoin ATM application for ${rec.name.get} has been received." }</strong> ++ - <span>{s" We will contact you when we are ready. Thank you for applying."}</span> - ) - case errors => - NgAlert.danger( - <i class="fa-fw fa fa-thumbs-o-down"></i> ++ - <strong>{ s"Your application could not be processed." }</strong>, - errors - ) - } - } - - def render: CssSel = - "@state" #> select(USStates.options, Empty, USStates.stateSelect, "name" -> "state") - - override def roundTrips = ("saveAtmApplication" -> save _) -} -\ No newline at end of file diff --git a/src/main/scala/inc/pyc/snippet/AtmSnip.scala b/src/main/scala/inc/pyc/snippet/AtmSnip.scala @@ -0,0 +1,97 @@ +package inc.pyc +package snippet + +import model._ +import field._ +import xml._ +import net.liftweb._ +import common._ +import json.JsonAST._ +import util._ +import Helpers._ +import http._ +import js._ +import JsCmds._ +import SHtml._ +import JE.JsVar + +class AtmApplication extends AngularSnippet { + + def roundTrips: List[RoundTripInfo] = List("submit" -> submit _) + + def states: CssSel = + "@state" #> select(USStates.options, Empty, USStates.stateSelect, "name" -> "state") + + def submit(model: JValue): JValue = { + val rec = AtmApplication.createRecord + rec.setFieldsFromJValue(model) + + rec.validate match { + case Nil => + rec.save + NgAlert.success( + <i class="fa-fw fa fa-thumbs-o-up"></i> ++ + <strong>{ s"Your Bitcoin ATM application for ${rec.name.get} has been received." }</strong> ++ + <span>{s" We will contact you when we are ready. Thank you for applying."}</span> + ) + case errors => + NgAlert.danger( + <i class="fa-fw fa fa-thumbs-o-down"></i> ++ + <strong>{ s"Your application could not be processed." }</strong>, + errors + ) + } + } +} + +class FindAtm extends AngularSnippet { + + def roundTrips: List[RoundTripInfo] = List("submit" -> submit _) + + def submit(model: JValue): JValue = { + val rec = SearchedPostal.createRecord + rec.setFieldsFromJValue(model) + + rec.validate match { + case Nil => + rec.save + NgAlert.success + case errors => + NgAlert.danger( + <i class="fa-fw fa fa-thumbs-o-down"></i> ++ + <strong>{"Something went wrong. We apologize for the inconvenience."}</strong>, + errors + ) + } + } +} + +class NearAtmNotify extends AngularSnippet { + + def roundTrips: List[RoundTripInfo] = List("submit" -> submit _) + + def states: CssSel = + "@state" #> select(USStates.options, Empty, USStates.stateSelect, "name" -> "state") + + + def submit(model: JValue): JValue = { + val rec = NearAtmNotify.createRecord + rec.setFieldsFromJValue(model) + + rec.validate match { + case Nil => + rec.save + NgAlert.success( + <i class="fa-fw fa fa-thumbs-o-up"></i> ++ + <strong>{ s"Hi ${rec.fname.get}, your notification has been received." }</strong> ++ + <span>{s" We will notify you when there is an ATM near ${rec.city.get}, ${rec.state.get}."}</span> + ) + case errors => + NgAlert.danger( + <i class="fa-fw fa fa-thumbs-o-down"></i> ++ + <strong>{ s"Hi ${rec.fname.get}, your notification was not submitted successfully." }</strong>, + errors + ) + } + } +} +\ No newline at end of file diff --git a/src/main/scala/inc/pyc/snippet/ForgotPasswordSnip.scala b/src/main/scala/inc/pyc/snippet/ForgotPasswordSnip.scala @@ -1,40 +0,0 @@ -package inc.pyc -package snippet - -import model._ -import net.liftweb._ -import common._ -import http.S -import json._ -import JsonAST.{JValue, JNull} - -class ForgotPasswordSnip extends AngularSnippet { - - def forgotPassword(model: JValue): JValue = { - (for { - JString(e) <- model \ "email" - } yield { - val email = e.toLowerCase.trim - - User.findByEmail(email) match { - case Full(user) => - User.sendLoginToken(user) - User.loginCredentials.remove() - - NgAlert.success( - <i class="fa-fw fa fa-thumbs-o-up"></i> ++ - <strong>An email has been sent to you with instructions for accessing your account.</strong>) - case _ => - NgAlert.danger( - <i class="fa-fw fa fa-thumbs-o-down"></i> ++ - <strong>Your email could not be found.</strong>, Nil) - } - }).headOption.getOrElse { - NgAlert.danger( - <i class="fa-fw fa fa-thumbs-o-down"></i> ++ - <strong>The information submitted could not be processed.</strong>, Nil) - } - } - - override def roundTrips = ("forgotPassword" -> forgotPassword _) -} -\ No newline at end of file diff --git a/src/main/scala/inc/pyc/snippet/NearAtmNotifySnip.scala b/src/main/scala/inc/pyc/snippet/NearAtmNotifySnip.scala @@ -1,48 +0,0 @@ -package inc.pyc -package snippet - -import model._ -import field._ -import net.liftweb._ -import common._ -import json.JsonAST._ -import util._ -import Helpers._ -import http._ -import js._ -import JsCmds._ -import SHtml._ -import JE.JsVar - -class NearAtmNotifySnip extends AngularSnippet { - - def save(model: JValue): JValue = { - val rec = NearAtmNotify.createRecord - rec.setFieldsFromJValue(model) - - rec.validate match { - case Nil => - rec.save - NgAlert.success( - <div> - <i class="fa-fw fa fa-thumbs-o-up"></i> - <strong>{ s"Hi ${rec.fname.get}, your notification has been received." }</strong> - <span>{s" We will notify you when there is an ATM near ${rec.city.get}, ${rec.state.get}."}</span> - </div> - ) - case errors => - NgAlert.danger( - <div> - <i class="fa-fw fa fa-thumbs-o-down"></i> - <strong>{ s"Hi ${rec.fname.get}, your notification was not submitted successfully." }</strong> - </div>, - errors - ) - } - } - - def render: CssSel = - "@state" #> select(USStates.options, Empty, USStates.stateSelect, "name" -> "state") - - override def roundTrips = ("saveNearAtmNotify" -> save _) -} -\ No newline at end of file diff --git a/src/main/scala/inc/pyc/snippet/SearchedPostalSnip.scala b/src/main/scala/inc/pyc/snippet/SearchedPostalSnip.scala @@ -1,40 +0,0 @@ -package inc.pyc -package snippet - -import model._ -import field._ -import xml._ -import net.liftweb._ -import common._ -import json.JsonAST._ -import util._ -import Helpers._ -import http._ -import js._ -import JsCmds._ -import SHtml._ -import JE.JsVar - -class SearchedPostalSnip extends AngularSnippet { - - def search(model: JValue): JValue = { - val rec = SearchedPostal.createRecord - rec.setFieldsFromJValue(model) - - rec.validate match { - case Nil => - rec.save - NgAlert.success - case errors => - NgAlert.danger( - <div> - <i class="fa-fw fa fa-thumbs-o-down"></i> - <strong>{"Something went wrong. We apologize for the inconvenience."}</strong> - </div>, - errors - ) - } - } - - override def roundTrips = ("searchAtmPostalCode" -> search _) -} -\ No newline at end of file diff --git a/src/main/scala/inc/pyc/snippet/UserLoginSnip.scala b/src/main/scala/inc/pyc/snippet/UserLoginSnip.scala @@ -1,49 +0,0 @@ -package inc.pyc -package snippet - -import model._ -import net.liftweb._ -import common._ -import json._ -import JsonAST.{JValue, JString, JBool} -import net.liftmodules.mongoauth.model.ExtSession - -class UserLoginSnip extends AngularSnippet { - - def login(model: JValue): JValue = { - (for { - JString(e) <- model \ "email" - JString(password) <- model \ "password" - JBool(remember) <- model \ "remember" - } yield { - val email = e.toLowerCase.trim - User.loginCredentials(LoginCredentials(email, remember)) - - if(!(email.length > 0) || !(password.length > 0)) { - NgAlert.danger( - <i class="fa-fw fa fa-thumbs-o-down"></i> ++ - <strong>{"Your login information could not be processed."}</strong>, Nil) - } - else { - User.findByEmail(email) match { - case Full(user) if (user.password.isMatch(password)) => - User.logUserIn(user, remember) - if (remember) User.createExtSession(user.id.get) - else ExtSession.deleteExtCookie() - NgAlert.success - case _ => - NgAlert.danger( - <i class="fa-fw fa fa-thumbs-o-down"></i> ++ - <strong>{"Invalid Credentials: "}</strong> - <p>Assure your email and password are correct.</p>, Nil) - } - } - }).headOption.getOrElse { - NgAlert.danger( - <i class="fa-fw fa fa-thumbs-o-down"></i> ++ - <strong>{"Your login information could not be processed."}</strong>, Nil) - } - } - - override def roundTrips = ("loginUser" -> login _) -} -\ No newline at end of file diff --git a/src/main/scala/inc/pyc/snippet/UserRegistrationSnip.scala b/src/main/scala/inc/pyc/snippet/UserRegistrationSnip.scala @@ -1,45 +0,0 @@ -package inc.pyc -package snippet - -import model._ -import field._ -import net.liftweb._ -import common._ -import json.JsonAST._ -import util._ -import Helpers._ -import http._ -import js._ -import JsCmds._ -import SHtml._ -import JE.JsVar - -class UserRegistrationSnip extends AngularSnippet { - - def register(model: JValue): JValue = { - val rec = User.createRecord - rec.setFieldsFromJValue(model) - rec.password(Helpers.randomString(20)) - rec.password.hashIt - - rec.validate match { - case Nil => - rec.save - User.sendLoginToken(rec) - - NgAlert.success( - <i class="fa-fw fa fa-thumbs-o-up"></i> ++ - <strong>{ s"Thank you for registering, ${rec.fname.get}." }</strong> ++ - <span>{" An email has been sent for you to log in."}</span> - ) - case errors => - NgAlert.danger( - <i class="fa-fw fa fa-thumbs-o-down"></i> ++ - <strong>{"Your application could not be processed."}</strong>, - errors - ) - } - } - - override def roundTrips = ("registerUser" -> register _) -} -\ No newline at end of file diff --git a/src/main/scala/inc/pyc/snippet/UserSnip.scala b/src/main/scala/inc/pyc/snippet/UserSnip.scala @@ -0,0 +1,112 @@ +package inc.pyc +package snippet + +import model._ +import net.liftweb._ +import common._ +import http._ +import util._ +import json._ +import JsonAST.{JValue, JString, JBool} +import net.liftmodules.mongoauth.model.ExtSession + +class UserLogin extends AngularSnippet { + + def roundTrips: List[RoundTripInfo] = List("submit" -> submit _) + + def submit(model: JValue): JValue = { + (for { + JString(e) <- model \ "email" + JString(password) <- model \ "password" + JBool(remember) <- model \ "remember" + } yield { + val email = e.toLowerCase.trim + User.loginCredentials(LoginCredentials(email, remember)) + + if(!(email.length > 0) || !(password.length > 0)) { + NgAlert.danger( + <i class="fa-fw fa fa-thumbs-o-down"></i> ++ + <strong>{"Your login information could not be processed."}</strong>, Nil) + } + else { + User.findByEmail(email) match { + case Full(user) if (user.password.isMatch(password)) => + User.logUserIn(user, remember) + if (remember) User.createExtSession(user.id.get) + else ExtSession.deleteExtCookie() + NgAlert.success + case _ => + NgAlert.danger( + <i class="fa-fw fa fa-thumbs-o-down"></i> ++ + <strong>{"Invalid Credentials: "}</strong> + <p>Assure your email and password are correct.</p>, Nil) + } + } + }).headOption.getOrElse { + NgAlert.danger( + <i class="fa-fw fa fa-thumbs-o-down"></i> ++ + <strong>{"Your login information could not be processed."}</strong>, Nil) + } + } +} + +class PasswordRecovery extends AngularSnippet { + + def roundTrips: List[RoundTripInfo] = List("submit" -> submit _) + + def submit(model: JValue): JValue = { + (for { + JString(e) <- model \ "email" + } yield { + val email = e.toLowerCase.trim + + User.findByEmail(email) match { + case Full(user) => + User.sendLoginToken(user) + User.loginCredentials.remove() + + NgAlert.success( + <i class="fa-fw fa fa-thumbs-o-up"></i> ++ + <strong>An email has been sent to you with instructions for accessing your account.</strong>) + case _ => + NgAlert.danger( + <i class="fa-fw fa fa-thumbs-o-down"></i> ++ + <strong>Your email could not be found.</strong>, Nil) + } + }).headOption.getOrElse { + NgAlert.danger( + <i class="fa-fw fa fa-thumbs-o-down"></i> ++ + <strong>The information submitted could not be processed.</strong>, Nil) + } + } +} + +class UserRegistration extends AngularSnippet { + + def roundTrips: List[RoundTripInfo] = List("submit" -> submit _) + + def submit(model: JValue): JValue = { + val rec = User.createRecord + rec.setFieldsFromJValue(model) + rec.password(Helpers.randomString(20)) + rec.password.hashIt + + rec.validate match { + case Nil => + rec.save + User.sendLoginToken(rec) + + NgAlert.success( + <i class="fa-fw fa fa-thumbs-o-up"></i> ++ + <strong>{ s"Thank you for registering, ${rec.fname.get}." }</strong> ++ + <span>{" An email has been sent for you to log in."}</span> + ) + case errors => + NgAlert.danger( + <i class="fa-fw fa fa-thumbs-o-down"></i> ++ + <strong>{"Your application could not be processed."}</strong>, + errors + ) + } + } +} +\ No newline at end of file diff --git a/src/main/scala/inc/pyc/snippet/UserSnips.scala b/src/main/scala/inc/pyc/snippet/UserSnips.scala @@ -77,82 +77,6 @@ object ProfileLocUser extends UserSnippet { } } -object UserLogin extends Loggable { - - def render = { - // form vars - var password = "" - var hasPassword = false - var remember = User.loginCredentials.is.isRememberMe - - val radios = SHtml.radioElem[Boolean]( - Seq(false, true), - Full(hasPassword) - )(it => it.foreach(hasPassword = _)) - - def doSubmit(): JsCmd = { - S.param("email").map(e => { - val email = e.toLowerCase.trim - // save the email and remember entered in the session var - User.loginCredentials(LoginCredentials(email, remember)) - - if (hasPassword && email.length > 0 && password.length > 0) { - User.findByEmail(email) match { - case Full(user) if (user.password.isMatch(password)) => - logger.debug("pwd matched") - User.logUserIn(user, true) - if (remember) User.createExtSession(user.id.get) - else ExtSession.deleteExtCookie() - RedirectTo(LoginRedirect.openOr(Site.home.url)) - case _ => - S.error("Invalid credentials") - Noop - } - } - else if (hasPassword && email.length <= 0 && password.length > 0) { - S.error("id_email_err", "Please enter an email") - Noop - } - else if (hasPassword && password.length <= 0 && email.length > 0) { - S.error("id_password_err", "Please enter a password") - Noop - } - else if (hasPassword) { - S.error("id_email_err", "Please enter an email") - S.error("id_password_err", "Please enter a password") - Noop - } - else if (email.length > 0) { - // see if email exists in the database - User.findByEmail(email) match { - case Full(user) => - User.sendLoginToken(user) - User.loginCredentials.remove() - S.notice("An email has been sent to you with instructions for accessing your account") - Noop - case _ => - RedirectTo(Site.register.url) - } - } - else { - S.error("id_email_err", "Please enter an email address") - Noop - } - }) openOr { - S.error("id_email_err", "Please enter an email address") - Noop - } - } - - "#id_email [value]" #> User.loginCredentials.is.email & - "#id_password" #> SHtml.password(password, password = _) & - "#no_password" #> radios(0) & - "#yes_password" #> radios(1) & - "name=remember" #> SHtml.checkbox(remember, remember = _) & - "#id_submit" #> SHtml.hidden(doSubmit) - } -} - object UserTopbar { def render = { User.currentUser match { diff --git a/src/main/webapp/app/Alert.js b/src/main/webapp/app/Alert.js @@ -0,0 +1,18 @@ +var alert = angular.module("alert", ['ui.bootstrap']); + +alert.controller('AlertCtrl', ['$scope', function($scope) { + $scope.alerts = []; + + $scope.$on('alertDialog', function(event, alert) { + $scope.addAlert(alert); + }); + + $scope.addAlert = function(alert) { + $scope.alerts = []; + $scope.alerts.push({type: alert.msg_type, msg: alert.msg}); + }; + + $scope.closeAlert = function(index) { + $scope.alerts.splice(index, 1); + }; +}]); +\ No newline at end of file diff --git a/src/main/webapp/app/App.js b/src/main/webapp/app/App.js @@ -1,9 +1,9 @@ -var app = angular.module("app", ['ui.bootstrap', 'ui.router', 'google-maps', 'ui.mask']); +var app = angular.module("app", ['google-maps', 'ui.bootstrap', 'ui.router', 'ui.mask', 'disabler', 'alert', 'form']); var ZIP_CODE_REGEXP = /^(\d{5}(-\d{4})?|[A-Z]\d[A-Z] *\d[A-Z]\d)$/; var UNSAFE_URL_REGEXP = /[-a-zA-Z0-9@:%_\+.~#?&//=]{2,256}\.[a-z]{2,4}\b(\/[-a-zA-Z0-9@:%_\+.~#?&//=]*)?/; -app.run(["$rootScope", "$window", function ($rootScope, $window) { +app.run(["$rootScope", "$window", "$state", "$stateParams", function ($rootScope, $window, $state, $stateParams) { $rootScope.$on('$locationChangeStart', function(event, newUrl){ if(newUrl.match(/(http(s)?:\/\/.*\/blog)/)) { event.preventDefault(); @@ -15,55 +15,9 @@ app.run(["$rootScope", "$window", function ($rootScope, $window) { $window.location.href = '/logout'; } }); -}]); - -app.directive('disabler', ['$compile', function($compile) { - return { - link: function(scope, elm, attrs) { - var btnContents = $compile(elm.contents())(scope); - scope.$watch(attrs.ngModel, function(value) { - if (value) { - elm.html("<i class='fa fa-spinner fa-spin'></i> Loading"); - elm.attr('disabled',true); - } else { - elm.html('').append(btnContents); - elm.attr('disabled',false); - } - }); - } - }; -}]); - -app.controller('AlertCtrl', ['$scope', function($scope) { - $scope.alerts = []; - - $scope.$on('alertDialog', function(event, alert) { - $scope.addAlert(alert); - }); - $scope.addAlert = function(alert) { - $scope.alerts = []; - $scope.alerts.push({type: alert.msg_type, msg: alert.msg}); - }; - - $scope.closeAlert = function(index) { - $scope.alerts.splice(index, 1); - }; -}]); - -app.controller('FormCtrl', ['$scope', function($scope) { - $scope.stateSuccess = function(el) { - return "{'state-success':form."+el+".$valid && !form."+el+".$pristine}"; - }; - - $scope.stateSuccessError = function(el) { - return "{'state-error':form."+el+".$invalid && !form."+el+".$pristine,'state-success':form."+el+".$valid && !form."+el+".$pristine}"; - }; - - $scope.reset = function() { - $scope.model = {}; - $scope.form.$setPristine(); - }; + $rootScope.$state = $state; + $rootScope.$stateParams = $stateParams; }]); app.controller('NearAtmNotifyCtrl', ['$scope', '$controller', '$rootScope', function($scope, $controller, $rootScope) { @@ -72,7 +26,7 @@ app.controller('NearAtmNotifyCtrl', ['$scope', '$controller', '$rootScope', func $scope.save = function() { $scope.loading = true; - window.backend.saveNearAtmNotify($scope.model).then(function(alert) { + window.NearAtmNotify.submit($scope.model).then(function(alert) { $scope.$apply(function() { $scope.loading = false; if(alert.msg_type === "success") { @@ -92,7 +46,7 @@ app.controller('AtmApplicationCtrl', ['$scope', '$controller', '$rootScope', fun $scope.save = function() { $scope.loading = true; - window.backend.saveAtmApplication($scope.model).then(function(alert) { + window.AtmApplication.submit($scope.model).then(function(alert) { $scope.$apply(function() { $scope.loading = false; if(alert.msg_type === "success") { @@ -111,7 +65,7 @@ app.controller('UserRegistrationCtrl', ['$scope', '$controller', '$rootScope', f $scope.save = function() { $scope.loading = true; - window.backend.registerUser($scope.model).then(function(alert) { + window.UserRegistration.submit($scope.model).then(function(alert) { $scope.$apply(function() { $scope.loading = false; if(alert.msg_type === "success") { @@ -125,12 +79,12 @@ app.controller('UserRegistrationCtrl', ['$scope', '$controller', '$rootScope', f }; }]); -app.controller('ForgotPasswordCtrl', ['$scope', '$controller', '$rootScope', function($scope, $controller, $rootScope) { +app.controller('PasswordRecoveryCtrl', ['$scope', '$controller', '$rootScope', function($scope, $controller, $rootScope) { $controller('FormCtrl', {$scope: $scope}); $scope.save = function() { $scope.loading = true; - window.backend.forgotPassword($scope.model).then(function(alert) { + window.PasswordRecovery.submit($scope.model).then(function(alert) { $scope.$apply(function() { $scope.loading = false; if(alert.msg_type === "success") { @@ -151,7 +105,7 @@ app.controller('UserLoginCtrl', ['$scope', '$controller', '$rootScope', function $scope.save = function() { $scope.loading = true; - window.backend.loginUser($scope.model).then(function(alert) { + window.UserLogin.submit($scope.model).then(function(alert) { $scope.$apply(function() { $scope.loading = false; if(alert.msg_type === "success") { @@ -170,11 +124,11 @@ app.controller('FindAtmCtrl', ['$scope', '$state', '$rootScope', function($scope $scope.search = function() { $scope.loading = true; - window.backend.searchAtmPostalCode($scope.model).then(function(alert) { + window.FindAtm.submit($scope.model).then(function(alert) { $scope.$apply(function() { $scope.loading = false; if(alert.msg_type === "success") { - $state.go('locations'); + $state.go('atmlocations'); $scope.reset(); } else { $rootScope.$broadcast('alertDialog', alert); diff --git a/src/main/webapp/app/Disabler.js b/src/main/webapp/app/Disabler.js @@ -0,0 +1,18 @@ +var disabler = angular.module("disabler", []); + +disabler.directive('disabler', ['$compile', function($compile) { + return { + link: function(scope, elm, attrs) { + var btnContents = $compile(elm.contents())(scope); + scope.$watch(attrs.ngModel, function(value) { + if (value) { + elm.html("<i class='fa fa-spinner fa-spin'></i> Loading"); + elm.attr('disabled',true); + } else { + elm.html('').append(btnContents); + elm.attr('disabled',false); + } + }); + } + }; +}]); +\ No newline at end of file diff --git a/src/main/webapp/app/Form.js b/src/main/webapp/app/Form.js @@ -0,0 +1,16 @@ +var form = angular.module("form", []); + +form.controller('FormCtrl', ['$scope', function($scope) { + $scope.stateSuccess = function(el) { + return "{'state-success':form."+el+".$valid && !form."+el+".$pristine}"; + }; + + $scope.stateSuccessError = function(el) { + return "{'state-error':form."+el+".$invalid && !form."+el+".$pristine,'state-success':form."+el+".$valid && !form."+el+".$pristine}"; + }; + + $scope.reset = function() { + $scope.model = {}; + $scope.form.$setPristine(); + }; +}]); +\ No newline at end of file diff --git a/src/main/webapp/templates-hidden/base-wrap.html b/src/main/webapp/templates-hidden/base-wrap.html @@ -68,6 +68,5 @@ <script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?key=AIzaSyAehyKUHOOWL_plRJCW8R1EdCIKCfR9jkg&sensor=true"></script> <script data-lift="Assets.js" type="text/javascript"></script> <script data-lift="NgUIRouter.js?ngApp=app" type="text/javascript"></script> -<script data-lift="AngularServerSide.js" type="text/javascript"></script> </body> </html> diff --git a/src/main/webapp/templates-hidden/parts/apply-atm-form.html b/src/main/webapp/templates-hidden/parts/apply-atm-form.html @@ -1,4 +1,4 @@ -<div data-lift="AtmApplicationSnip" ng-controller="AtmApplicationCtrl" ng-cloak> +<div data-lift="AtmApplication" ng-controller="AtmApplicationCtrl"> <form name="form" class="smart-form client-form" ng-submit="save()" novalidate> <fieldset> <section> @@ -35,7 +35,7 @@ </label> </section> <section class="col col-6" ng-class="{{ stateSuccessError('state') }}"> - <label class="select"> + <label data-lift="AtmApplication.states" class="select"> <select name="state" ng-model="model.state" required></select> <i></i> </label> diff --git a/src/main/webapp/templates-hidden/parts/find-atm-form.html b/src/main/webapp/templates-hidden/parts/find-atm-form.html @@ -1,4 +1,4 @@ -<div ng-controller="FindAtmCtrl" ng-cloak> +<div data-lift="FindAtm" ng-controller="FindAtmCtrl" ng-cloak> <form name="form" class="smart-form client-form" ng-submit="search()" novalidate> <div class="row" style="margin:0"> <div class="col-xs-5"> diff --git a/src/main/webapp/templates-hidden/parts/forgot-password-form.html b/src/main/webapp/templates-hidden/parts/forgot-password-form.html @@ -1,4 +1,4 @@ -<div ng-controller="ForgotPasswordCtrl" ng-cloak> +<div data-lift="PasswordRecovery" ng-controller="PasswordRecoveryCtrl" ng-cloak> <form name="form" class="smart-form client-form" ng-submit="save()" novalidate> <fieldset> <section> diff --git a/src/main/webapp/templates-hidden/parts/notify-atm-form.html b/src/main/webapp/templates-hidden/parts/notify-atm-form.html @@ -1,4 +1,4 @@ -<div data-lift="NearAtmNotifySnip" ng-controller="NearAtmNotifyCtrl"> +<div data-lift="NearAtmNotify" ng-controller="NearAtmNotifyCtrl"> <form name="form" class="smart-form client-form" ng-submit="save()" novalidate> <header>Notify me when there is a nearby ATM</header> <fieldset> @@ -39,7 +39,7 @@ </label> </section> <section class="col col-6"> - <label class="select" ng-class="{{ stateSuccessError('state') }}"> + <label data-lift="NearAtmNotify.states" class="select" ng-class="{{ stateSuccessError('state') }}"> <select name="state" ng-model="model.state"></select> <i></i> </label> diff --git a/src/main/webapp/templates-hidden/parts/user-login-form.html b/src/main/webapp/templates-hidden/parts/user-login-form.html @@ -1,4 +1,4 @@ -<div ng-controller="UserLoginCtrl" ng-cloak> +<div data-lift="UserLogin" ng-controller="UserLoginCtrl" ng-cloak> <form name="form" class="smart-form client-form" ng-submit="save()" novalidate> <fieldset> <section> diff --git a/src/main/webapp/templates-hidden/parts/user-registration-form.html b/src/main/webapp/templates-hidden/parts/user-registration-form.html @@ -1,4 +1,4 @@ -<div ng-controller="UserRegistrationCtrl" ng-cloak> +<div data-lift="UserRegistration" ng-controller="UserRegistrationCtrl" ng-cloak> <form name="form" class="smart-form client-form" ng-submit="save()" novalidate> <fieldset> <div class="row">