UNPKG

@owstack/ows-wallet-plugin-movies

Version:
1 lines 8.57 kB
"use strict";angular.module("owsWalletPlugin",["gettext","ionic","ngLodash","owsWalletPluginClient","owsWalletPlugin.api","owsWalletPlugin.controllers","owsWalletPlugin.services"]),angular.module("owsWalletPlugin.api",[]),angular.module("owsWalletPlugin.controllers",[]),angular.module("owsWalletPlugin.services",[]),angular.module("owsWalletPlugin").config(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",controller:"SessionLogCtrl",templateUrl:"views/settings/session-log/session-log.html"})}).run(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",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.get("data").then(function(value){cb(null,value)}).catch(function(error){$log.error("Failed to read preferences: "+error.message+" ("+error.statusCode+")"),cb(error)})},root.saveData=function(){session.set("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",function($scope,$log,movieService,BitPay,Session,Transaction,popupService){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){$log.error("Could not create payment request: "+error.message);popupService.showAlert("Oops! Our Fault","We are unable to process your purchase at this time. Please try again later.")})}var bitpay=new BitPay("movieStore");owswallet.Plugin.openForBusiness(BitPay.pluginId,function(){$scope.buyDiabled=!1}),$scope.$on("$ionicView.beforeEnter",function(event,data){$scope.buyDiabled=!0,$scope.movie=movieService.getMovie(data.stateParams.id)}),$scope.buy=function(movieId){Session.getInstance().chooseWallet().then(function(wallet){if(!wallet)return void $log.info("User canceled");doBuy(movieService.getMovie(movieId),wallet)}).catch(function(error){$log.error("Could not choose a wallet: "+JSON.stringify(error))})}}),angular.module("owsWalletPlugin.controllers").controller("HomeCtrl",function($scope,movieService){$scope.$on("$ionicView.beforeEnter",function(event,data){$scope.appletName=movieService.appletName,$scope.movies=movieService.getMovies()})}),angular.module("owsWalletPlugin.controllers").controller("SessionLogCtrl",function($scope,historicLogService,lodash,gettextCatalog,Session){var session=Session.getInstance(),pluginId=session.plugin.header.id+"@"+session.plugin.header.version;$scope.pluginName=session.plugin.header.name+"@"+session.plugin.header.version,$scope.isCordova=owswallet.Plugin.isCordova();var logLevel=session.logLevel;historicLogService.getLevels();$scope.$on("$ionicView.enter",function(event,data){var selectedLevel=historicLogService.getLevel(logLevel);filterLogs(selectedLevel.weight)}),$scope.prepareLogs=function(){var log=pluginId+" session logs\n Be careful, this could contain sensitive private data.\n\n";return log+=historicLogService.get().map(function(v){return"["+v.timestamp+"]["+v.level+"]"+v.msg}).join("\n")},$scope.sendLogs=function(){var body=$scope.prepareLogs();window.plugins.socialsharing.shareViaEmail(body,pluginId+" session logs",null,null,null,null,function(){},function(){})};var filterLogs=function(weight){$scope.filteredLogs=historicLogService.get(weight)}}),angular.module("owsWalletPlugin.controllers").controller("SettingsCtrl",function($scope,Session,externalLinkService,gettextCatalog){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)}});