summaryrefslogtreecommitdiff
path: root/www/js/MonitorModalCtrl.js
diff options
context:
space:
mode:
Diffstat (limited to 'www/js/MonitorModalCtrl.js')
-rw-r--r--www/js/MonitorModalCtrl.js78
1 files changed, 61 insertions, 17 deletions
diff --git a/www/js/MonitorModalCtrl.js b/www/js/MonitorModalCtrl.js
index 3d765aed..55e15f3a 100644
--- a/www/js/MonitorModalCtrl.js
+++ b/www/js/MonitorModalCtrl.js
@@ -3,7 +3,7 @@
/* jslint browser: true*/
/* global saveAs, cordova,StatusBar,angular,console,ionic, moment, imagesLoaded, chrome */
-angular.module('zmApp.controllers').controller('MonitorModalCtrl', ['$scope', '$rootScope', 'zm', 'NVRDataModel', '$ionicSideMenuDelegate', '$timeout', '$interval', '$ionicModal', '$ionicLoading', '$http', '$state', '$stateParams', '$ionicHistory', '$ionicScrollDelegate', '$q', '$sce', 'carouselUtils', '$ionicPopup', 'SecuredPopups', '$translate', function ($scope, $rootScope, zm, NVRDataModel, $ionicSideMenuDelegate, $timeout, $interval, $ionicModal, $ionicLoading, $http, $state, $stateParams, $ionicHistory, $ionicScrollDelegate, $q, $sce, carouselUtils, $ionicPopup, SecuredPopups, $translate) {
+angular.module('zmApp.controllers').controller('MonitorModalCtrl', ['$scope', '$rootScope', 'zm', 'NVRDataModel', '$ionicSideMenuDelegate', '$timeout', '$interval', '$ionicModal', '$ionicLoading', '$http', '$state', '$stateParams', '$ionicHistory', '$ionicScrollDelegate', '$q', '$sce', 'carouselUtils', '$ionicPopup', 'SecuredPopups', '$translate', '$cordovaFile', function ($scope, $rootScope, zm, NVRDataModel, $ionicSideMenuDelegate, $timeout, $interval, $ionicModal, $ionicLoading, $http, $state, $stateParams, $ionicHistory, $ionicScrollDelegate, $q, $sce, carouselUtils, $ionicPopup, SecuredPopups, $translate, $cordovaFile) {
$scope.animationInProgress = false;
$scope.imageFit = true;
@@ -1183,6 +1183,64 @@ angular.module('zmApp.controllers').controller('MonitorModalCtrl', ['$scope', '$
NVRDataModel.log("SavetoPhone:Trying to save image from " + url);
+ if ($rootScope.platformOS != 'desktop') {
+ var album = 'zmNinja';
+ NVRDataModel.debug ("Trying to save image to album: "+album);
+ cordova.plugins.photoLibrary.requestAuthorization(
+ function () {
+ //url = "https://picsum.photos/200/300/?random";
+
+ var fileTransfer = new FileTransfer();
+ var urle = encodeURI(url);
+ var fname = "zmninja.jpg";
+
+ fileTransfer.download(urle, cordova.file.dataDirectory + fname,
+ function(entry){
+ NVRDataModel.debug("local download complete: " + entry.toURL());
+ NVRDataModel.debug("Now trying to move it to album");
+ cordova.plugins.photoLibrary.saveImage(entry.toURL(), album,
+ function (cameraRollAssetId) {
+ SaveSuccess();
+ $cordovaFile.removeFile(cordova.file.dataDirectory, fname)
+ .then (
+ function () {
+ NVRDataModel.debug ("file removed from data directory");
+ },
+ function (e) {
+ NVRDataModel.debug ("could not delete temp file: "+JSON.stringify(e));
+ }
+ );
+
+
+ }, function (err) {
+ NVRDataModel.debug ("Saving error:" + JSON.stringify(err));
+ SaveError();
+
+ });
+
+ },
+ function(err) { console.log ("error downloading:"+JSON.stringify(err));}, false, {});
+
+
+
+
+ // User gave us permission to his library, retry reading it!
+ },
+ function (err) {
+ // User denied the access
+ NVRDataModel.debug ("Permission not granted");
+ SaveError();
+ }, // if options not provided, defaults to {read: true}.
+
+ {
+ read: true,
+ write: true
+ }
+ );
+ }
+
+ else {
+
var img = new Image();
img.onload = function () {
// console.log("********* ONLOAD");
@@ -1195,21 +1253,6 @@ angular.module('zmApp.controllers').controller('MonitorModalCtrl', ['$scope', '$
imageDataUrl = canvas.toDataURL('image/jpeg', 1.0);
imageData = imageDataUrl.replace(/data:image\/jpeg;base64,/, '');
- if ($rootScope.platformOS != "desktop") {
- try {
-
- cordova.exec(
- SaveSuccess,
- SaveError,
- 'Canvas2ImagePlugin',
- 'saveImageDataToLibrary', [imageData]
- );
- } catch (e) {
-
- SaveError(e.message);
- }
- } else {
-
var fname = $scope.monitorName + "-" +
moment().format('MMM-DD-YY_HH-mm-ss') + ".png";
canvas.toBlob(function (blob) {
@@ -1217,7 +1260,7 @@ angular.module('zmApp.controllers').controller('MonitorModalCtrl', ['$scope', '$
SaveSuccess();
});
- }
+
};
try {
img.src = url;
@@ -1227,6 +1270,7 @@ angular.module('zmApp.controllers').controller('MonitorModalCtrl', ['$scope', '$
}
}
+ }
$scope.constructSingleStream = function () {