@owstack/ows-wallet-applet-movies
Version:
An OWS Wallet sample plugin.
1 lines • 7.71 kB
JavaScript
"use strict";angular.module("owsWalletPlugin",["gettext","ionic","ngLodash","owsWalletPluginClient","owsWalletPlugin.api.bitpay","owsWalletPlugin.controllers","owsWalletPlugin.services"]),angular.module("owsWalletPlugin.controllers",[]),angular.module("owsWalletPlugin.services",[]),angular.module("owsWalletPlugin").config(["$stateProvider",function($stateProvider){$stateProvider.state("home",{url:"/home",controller:"HomeCtrl",templateUrl:"views/home/home.html"}).state("detail",{url:"/detail/:id",controller:"DetailCtrl",templateUrl:"views/detail/detail.html"}).state("settings",{url:"/settings",controller:"SettingsCtrl",templateUrl:"views/settings/settings.html"}).state("sessionLog",{url:"/session-log",templateUrl:"views/settings/session-log/session-log.html"})}]).run(["$rootScope","$state","$log","movieService",function($rootScope,$state,$log,movieService){owswallet.Plugin.ready(function(){movieService.init(function(){$state.go("home")})}),$rootScope.$on("$stateChangeStart",function(event,toState,toParams,fromState,fromParams){$log.debug("Applet route change start from:",fromState.name||"-"," to:",toState.name)})}]),angular.module("owsWalletPlugin").run(["gettextCatalog",function(gettextCatalog){}]),angular.module("owsWalletPlugin.services").service("movieService",["$rootScope","lodash","owsWalletPluginClient.api.Session",function($rootScope,lodash,Session){var session,root={},movies=[{id:"the-avengers",title:"The Avengers",year:"2012",plot:"The Asgardian Loki encounters the Other, the leader of an extraterrestrial race known as the Chitauri. In exchange for retrieving the Tesseract,2 a powerful energy source of unknown potential, the Other promises Loki an army with which he can subjugate Earth...",episode:"The Avengers",likeCount:267,commentCount:186,price:{amount:5,currency:"USD"}},{id:"star-wars",title:"Star Wars",episode:"Episode IV - A New Hope",year:"1977",plot:"Near the orbit of the desert planet Tatooine, a Rebel spaceship is intercepted by the Empire. Aboard, the deadliest Imperial agent Darth Vader and his stormtroopers capture Princess Leia Organa, a secret member of the rebellion. Before her capture, Leia makes sure the astromech R2-D2, along with the protocol droid C-3PO, escapes with stolen Imperial blueprints stored inside and a holographic message for the retired Jedi Knight Obi-Wan Kenobi, who has been living in exile on Tatooine...",likeCount:582,commentCount:267,price:{amount:4,currency:"USD"}},{id:"2001-space-odyssey",title:"2001: A Space Odyssey",episode:"2001: A Space Odyssey",year:"1968",plot:"In an African desert millions of years ago, a tribe of hominids is driven away from its water hole by a rival tribe. They awaken to find a featureless black monolith has appeared before them. Seemingly influenced by the monolith, they discover how to use a bone as a weapon and drive their rivals away from the water hole...",likeCount:9343,commentCount:2067,price:{amount:3,currency:"USD"}}];return $rootScope.$on("$pre.beforeLeave",function(event,applet){root.saveData()}),root.data={},root.init=function(cb){session=Session.getInstance(),root.appletName=session.plugin.header.name,cb()},root.getData=function(cb){cb=cb||function(){},session.getValue("data").then(function(value){cb(null,value)}).catch(function(error){cb(error)})},root.saveData=function(){session.setValue("data",data),session.flush()},root.getMovies=function(){return movies},root.getMovie=function(id){return lodash.find(movies,function(movie){return id==movie.id})},root}]),angular.module("owsWalletPlugin.controllers").controller("DetailCtrl",["$scope","$log","$timeout","movieService","popupService","owsWalletPlugin.api.bitpay.BitPay","owsWalletPlugin.api.bitpay.BitPayServlet","owsWalletPluginClient.api.Session",function($scope,$log,$timeout,movieService,popupService,BitPay,BitPayServlet,Session){function doBuy(movie,wallet){function confirmHandler(){return new Promise(function(resolve,reject){var message="You are buying "+movie.title+" for "+movie.price+" "+movie.currency+".";popupService.showConfirm("Confirm Your Purchase",message,"Buy","Cancel",function(ok){ok&&resolve(),reject()})})}var payment={price:movie.price.amount,currency:movie.price.currency};bitpay.sendPayment(wallet,payment,confirmHandler).then(function(){$log.debug("Payment sent")}).catch(function(error){popupService.showAlert("Oops! Our Fault","We are unable to process your purchase at this time. Please try again later.")})}var bitpay=new BitPay;$scope.$on("$ionicView.beforeEnter",function(event,data){$scope.buyDisabled=!0,$scope.movie=movieService.getMovie(data.stateParams.id),owswallet.Plugin.openForBusiness(BitPayServlet.id,function(){$scope.buyDisabled=!1})}),$scope.buy=function(movieId){var filter={currencies:bitpay.getInvoiceCurrencies()};Session.getInstance().chooseWallet(filter).then(function(wallet){if(!wallet)return void $log.info("User canceled");doBuy(movieService.getMovie(movieId),wallet)}).catch(function(error){})}}]),angular.module("owsWalletPlugin.controllers").controller("HomeCtrl",["$scope","movieService",function($scope,movieService){$scope.$on("$ionicView.beforeEnter",function(event,data){$scope.appletName=movieService.appletName,$scope.movies=movieService.getMovies()})}]),angular.module("owsWalletPlugin.controllers").controller("SettingsCtrl",["$scope","externalLinkService","gettextCatalog","owsWalletPluginClient.api.Session",function($scope,externalLinkService,gettextCatalog,Session){var session=Session.getInstance();$scope.version=session.plugin.header.version,$scope.commitHash=session.plugin.header.commitHash,$scope.externalLinks={marketing:{itemName:gettextCatalog.getString("Learn More"),title:gettextCatalog.getString("Learn More"),message:gettextCatalog.getString("Visit the plugin authors website to learn more about this and other plugins."),okText:gettextCatalog.getString("Visit Website"),cancelText:gettextCatalog.getString("Go Back"),url:session.plugin.header.url.marketing,icon:"ion-ios-information-outline"},support:{itemName:gettextCatalog.getString("Get Support"),title:gettextCatalog.getString("Get Support"),message:gettextCatalog.getString("You can get support for this plugin from ")+session.plugin.header.author,okText:gettextCatalog.getString("Visit Website"),cancelText:gettextCatalog.getString("Go Back"),url:session.plugin.header.url.support,icon:"ion-ios-help-outline"},privacy:{itemName:gettextCatalog.getString("Privacy Policy"),title:gettextCatalog.getString("View Privacy Policy"),message:gettextCatalog.getString("Read the privacy policy for this plugin."),okText:gettextCatalog.getString("Visit Website"),cancelText:gettextCatalog.getString("Go Back"),url:session.plugin.header.url.privacy,icon:null},terms:{itemName:gettextCatalog.getString("Terms of Use"),title:gettextCatalog.getString("View Terms of Use"),message:gettextCatalog.getString("Read the terms of use for this plugin."),okText:gettextCatalog.getString("Visit Website"),cancelText:gettextCatalog.getString("Go Back"),url:session.plugin.header.url.terms,icon:null}},$scope.git={itemName:gettextCatalog.getString("Commit Hash"),title:gettextCatalog.getString("View GitHub Project"),message:gettextCatalog.getString("You can see the latest developments and contribute to this open source app by visiting our project on GitHub."),okText:gettextCatalog.getString("Open GitHub"),cancelText:gettextCatalog.getString("Go Back"),url:session.plugin.header.url.git+"tree/"+$scope.commitHash,icon:"ion-social-github-outline"},$scope.links=Object.keys($scope.externalLinks),$scope.get=function(link){return $scope.externalLinks[link]},$scope.openExternalLink=function(link){externalLinkService.open(link.url,!0,link.title,link.message,link.okText,link.cancelText)}}]);