Layoutanpassungen
This commit is contained in:
@@ -14,6 +14,10 @@ angular.module('starter', ['ionic', 'ngCordova', 'starter.controllers', 'starter
|
||||
// Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
|
||||
// for form inputs)
|
||||
|
||||
|
||||
|
||||
$rootScope.storeinit=99;
|
||||
|
||||
$ionicPlatform.registerBackButtonAction(function(event) {
|
||||
|
||||
// Handle Android back button to avoid the application exits accidentaly
|
||||
@@ -56,6 +60,7 @@ angular.module('starter', ['ionic', 'ngCordova', 'starter.controllers', 'starter
|
||||
|
||||
|
||||
function successHandler (result) {
|
||||
/*
|
||||
var strResult = "";
|
||||
if(typeof result === 'object') {
|
||||
strResult = JSON.stringify(result);
|
||||
@@ -63,10 +68,13 @@ angular.module('starter', ['ionic', 'ngCordova', 'starter.controllers', 'starter
|
||||
strResult = result;
|
||||
}
|
||||
alert("SUCCESS: \r\n"+strResult );
|
||||
*/
|
||||
$rootScope.storeinit=1;
|
||||
}
|
||||
|
||||
function errorHandler (error) {
|
||||
alert("ERROR: \r\n"+error );
|
||||
//alert("ERROR: \r\n"+error );
|
||||
$rootScope.storeinit=0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
angular.module('starter.controllers', [])
|
||||
|
||||
.controller('DashCtrl', function($scope,$ionicPopup,$http, $database) {
|
||||
.controller('DashCtrl', function($scope,$ionicPopup,$http, $database, $timeout,$rootScope) {
|
||||
|
||||
$scope.preis="";
|
||||
$scope.name="";
|
||||
@@ -25,6 +25,7 @@ angular.module('starter.controllers', [])
|
||||
};
|
||||
|
||||
|
||||
|
||||
$scope.loaddata = function() {
|
||||
$scope.items=[];
|
||||
$database.getAllBuys().then(function (result) {
|
||||
@@ -51,6 +52,7 @@ angular.module('starter.controllers', [])
|
||||
};
|
||||
|
||||
function successBuyHandler (result) {
|
||||
/*
|
||||
var strResult = "";
|
||||
if(typeof result === 'object') {
|
||||
strResult = JSON.stringify(result);
|
||||
@@ -58,9 +60,12 @@ angular.module('starter.controllers', [])
|
||||
strResult = result;
|
||||
}
|
||||
alert("SUCCESS: \r\n"+strResult );
|
||||
*/
|
||||
$timeout(consumesuccessHandler, 1000);
|
||||
}
|
||||
|
||||
function successConsumeHandler (result) {
|
||||
/*
|
||||
var strResult = "";
|
||||
if(typeof result === 'object') {
|
||||
strResult = JSON.stringify(result);
|
||||
@@ -68,18 +73,33 @@ angular.module('starter.controllers', [])
|
||||
strResult = result;
|
||||
}
|
||||
alert("SUCCESS: \r\n"+strResult );
|
||||
*/
|
||||
}
|
||||
|
||||
function errorBuyHandler (error) {
|
||||
alert("ERROR: \r\n"+error );
|
||||
var alertPopup = $ionicPopup.alert({
|
||||
title: 'Oh Nein',
|
||||
template: 'Der Kauf konnte nicht durchgeführt werden.'
|
||||
});
|
||||
|
||||
alertPopup.then(function(res) {
|
||||
console.log('Der Kauf konnte nicht durchgeführt werden');
|
||||
});
|
||||
}
|
||||
|
||||
function errorConsumeHandler (error) {
|
||||
alert("ERROR: \r\n"+error );
|
||||
var alertPopup = $ionicPopup.alert({
|
||||
title: 'Oh Nein',
|
||||
template: 'Der Kauf wurde durchgeführt, aber deine Rosen konnten freigeschaltet werden.'
|
||||
});
|
||||
|
||||
alertPopup.then(function(res) {
|
||||
console.log('Der Kauf wurde durchgeführt, aber deine Rosen konnten freigeschaltet werden');
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
function buysuccessHandler (result) {
|
||||
function consumesuccessHandler (result) {
|
||||
inappbilling.consumePurchase(successConsumeHandler, errorConsumeHandler, $scope.preis);
|
||||
}
|
||||
|
||||
@@ -88,7 +108,22 @@ angular.module('starter.controllers', [])
|
||||
//alert($scope.preis);
|
||||
|
||||
if((window.device && device.platform == "Android") && typeof inappbilling !== "undefined") {
|
||||
inappbilling.buy(successBuyHandler, errorBuyHandler, $scope.preis);
|
||||
|
||||
if ($rootScope.storeinit==1){
|
||||
inappbilling.buy(successBuyHandler, errorBuyHandler, $scope.preis);
|
||||
}
|
||||
else{
|
||||
var alertPopup = $ionicPopup.alert({
|
||||
title: 'Achtung',
|
||||
template: 'Der Google-Store konnte nicht initialisiert werden.'
|
||||
});
|
||||
|
||||
alertPopup.then(function(res) {
|
||||
console.log('Store steht nicht zur Verfuegung');
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
<ion-view view-title="Gekaufte Rosen">
|
||||
<ion-content class="padding">
|
||||
|
||||
<div style="padding-bottom:15px;">
|
||||
|
||||
<ul class="list card">
|
||||
<div class="item item-divider oleo">Hier können Sie Ihre gekauften Rosen ansehen oder nochmals versenden!</div>
|
||||
|
||||
<a class="item item-thumbnail-left item-button-right" href="#" ng-repeat="i in items" ng-model="items">
|
||||
<img src="img/rose1.png">
|
||||
<h2>{{i.name}}</h2>
|
||||
<p>{{i.freitext}} </p>
|
||||
<div class="buttons" style="margin-top:30px;">
|
||||
<button class="button button-small" >
|
||||
<i class="button button-icon icon ion-settings"></i>
|
||||
</button>
|
||||
<button class="button button-small">
|
||||
<i class="icon ion-android-share-alt"> Teilen</i>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
</a>
|
||||
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
|
||||
</ion-content>
|
||||
</ion-view>
|
||||
@@ -46,6 +46,214 @@ module.exports = [
|
||||
"cordova.plugins.Keyboard"
|
||||
],
|
||||
"runs": true
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-inappbrowser/www/inappbrowser.js",
|
||||
"id": "cordova-plugin-inappbrowser.inappbrowser",
|
||||
"pluginId": "cordova-plugin-inappbrowser",
|
||||
"clobbers": [
|
||||
"cordova.InAppBrowser.open",
|
||||
"window.open"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/DirectoryEntry.js",
|
||||
"id": "cordova-plugin-file.DirectoryEntry",
|
||||
"pluginId": "cordova-plugin-file",
|
||||
"clobbers": [
|
||||
"window.DirectoryEntry"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/DirectoryReader.js",
|
||||
"id": "cordova-plugin-file.DirectoryReader",
|
||||
"pluginId": "cordova-plugin-file",
|
||||
"clobbers": [
|
||||
"window.DirectoryReader"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/Entry.js",
|
||||
"id": "cordova-plugin-file.Entry",
|
||||
"pluginId": "cordova-plugin-file",
|
||||
"clobbers": [
|
||||
"window.Entry"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/File.js",
|
||||
"id": "cordova-plugin-file.File",
|
||||
"pluginId": "cordova-plugin-file",
|
||||
"clobbers": [
|
||||
"window.File"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/FileEntry.js",
|
||||
"id": "cordova-plugin-file.FileEntry",
|
||||
"pluginId": "cordova-plugin-file",
|
||||
"clobbers": [
|
||||
"window.FileEntry"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/FileError.js",
|
||||
"id": "cordova-plugin-file.FileError",
|
||||
"pluginId": "cordova-plugin-file",
|
||||
"clobbers": [
|
||||
"window.FileError"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/FileReader.js",
|
||||
"id": "cordova-plugin-file.FileReader",
|
||||
"pluginId": "cordova-plugin-file",
|
||||
"clobbers": [
|
||||
"window.FileReader"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/FileSystem.js",
|
||||
"id": "cordova-plugin-file.FileSystem",
|
||||
"pluginId": "cordova-plugin-file",
|
||||
"clobbers": [
|
||||
"window.FileSystem"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/FileUploadOptions.js",
|
||||
"id": "cordova-plugin-file.FileUploadOptions",
|
||||
"pluginId": "cordova-plugin-file",
|
||||
"clobbers": [
|
||||
"window.FileUploadOptions"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/FileUploadResult.js",
|
||||
"id": "cordova-plugin-file.FileUploadResult",
|
||||
"pluginId": "cordova-plugin-file",
|
||||
"clobbers": [
|
||||
"window.FileUploadResult"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/FileWriter.js",
|
||||
"id": "cordova-plugin-file.FileWriter",
|
||||
"pluginId": "cordova-plugin-file",
|
||||
"clobbers": [
|
||||
"window.FileWriter"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/Flags.js",
|
||||
"id": "cordova-plugin-file.Flags",
|
||||
"pluginId": "cordova-plugin-file",
|
||||
"clobbers": [
|
||||
"window.Flags"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/LocalFileSystem.js",
|
||||
"id": "cordova-plugin-file.LocalFileSystem",
|
||||
"pluginId": "cordova-plugin-file",
|
||||
"clobbers": [
|
||||
"window.LocalFileSystem"
|
||||
],
|
||||
"merges": [
|
||||
"window"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/Metadata.js",
|
||||
"id": "cordova-plugin-file.Metadata",
|
||||
"pluginId": "cordova-plugin-file",
|
||||
"clobbers": [
|
||||
"window.Metadata"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/ProgressEvent.js",
|
||||
"id": "cordova-plugin-file.ProgressEvent",
|
||||
"pluginId": "cordova-plugin-file",
|
||||
"clobbers": [
|
||||
"window.ProgressEvent"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/fileSystems.js",
|
||||
"id": "cordova-plugin-file.fileSystems",
|
||||
"pluginId": "cordova-plugin-file"
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/requestFileSystem.js",
|
||||
"id": "cordova-plugin-file.requestFileSystem",
|
||||
"pluginId": "cordova-plugin-file",
|
||||
"clobbers": [
|
||||
"window.requestFileSystem"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/resolveLocalFileSystemURI.js",
|
||||
"id": "cordova-plugin-file.resolveLocalFileSystemURI",
|
||||
"pluginId": "cordova-plugin-file",
|
||||
"merges": [
|
||||
"window"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/android/FileSystem.js",
|
||||
"id": "cordova-plugin-file.androidFileSystem",
|
||||
"pluginId": "cordova-plugin-file",
|
||||
"merges": [
|
||||
"FileSystem"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/fileSystems-roots.js",
|
||||
"id": "cordova-plugin-file.fileSystems-roots",
|
||||
"pluginId": "cordova-plugin-file",
|
||||
"runs": true
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file/www/fileSystemPaths.js",
|
||||
"id": "cordova-plugin-file.fileSystemPaths",
|
||||
"pluginId": "cordova-plugin-file",
|
||||
"merges": [
|
||||
"cordova"
|
||||
],
|
||||
"runs": true
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file-transfer/www/FileTransferError.js",
|
||||
"id": "cordova-plugin-file-transfer.FileTransferError",
|
||||
"pluginId": "cordova-plugin-file-transfer",
|
||||
"clobbers": [
|
||||
"window.FileTransferError"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-plugin-file-transfer/www/FileTransfer.js",
|
||||
"id": "cordova-plugin-file-transfer.FileTransfer",
|
||||
"pluginId": "cordova-plugin-file-transfer",
|
||||
"clobbers": [
|
||||
"window.FileTransfer"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/cordova-sqlite-storage/www/SQLitePlugin.js",
|
||||
"id": "cordova-sqlite-storage.SQLitePlugin",
|
||||
"pluginId": "cordova-sqlite-storage",
|
||||
"clobbers": [
|
||||
"SQLitePlugin"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "plugins/me.rahul.plugins.sqlDB/www/sqlDB.js",
|
||||
"id": "me.rahul.plugins.sqlDB.sqlDB",
|
||||
"pluginId": "me.rahul.plugins.sqlDB",
|
||||
"clobbers": [
|
||||
"window.plugins.sqlDB"
|
||||
]
|
||||
}
|
||||
];
|
||||
module.exports.metadata =
|
||||
@@ -57,7 +265,12 @@ module.exports.metadata =
|
||||
"cordova-plugin-splashscreen": "3.0.0",
|
||||
"cordova-plugin-statusbar": "2.0.0",
|
||||
"cordova-plugin-whitelist": "1.2.0",
|
||||
"ionic-plugin-keyboard": "1.0.8"
|
||||
"ionic-plugin-keyboard": "1.0.8",
|
||||
"cordova-plugin-inappbrowser": "1.1.1",
|
||||
"cordova-plugin-file": "3.0.0",
|
||||
"cordova-plugin-file-transfer": "1.4.0",
|
||||
"cordova-sqlite-storage": "0.7.15-pre",
|
||||
"me.rahul.plugins.sqlDB": "1.0.3"
|
||||
}
|
||||
// BOTTOM OF METADATA
|
||||
});
|
||||
@@ -3,6 +3,7 @@
|
||||
font-family: 'Lobster', cursive;
|
||||
}
|
||||
|
||||
|
||||
.lobsterMiddle{
|
||||
font-family: 'Lobster', cursive;
|
||||
font-size: 1.2em;
|
||||
@@ -22,35 +23,45 @@
|
||||
|
||||
.item-divider{
|
||||
background-image: linear-gradient(
|
||||
hsla(340, 100%, 35%, 1) 20%,
|
||||
hsl(340,100%,54%) 90%
|
||||
hsla(0, 94%, 33%, 1) 20%,
|
||||
hsl(0,94%,54%) 90%
|
||||
);
|
||||
color:white;
|
||||
}
|
||||
|
||||
|
||||
.tabs-addddssertive > .tabs{
|
||||
background-image: linear-gradient(
|
||||
hsla(340, 100%, 35%, 1) 20%,
|
||||
hsl(340,100%,54%) 90%
|
||||
hsla(0, 94%, 33%, 1) 20%,
|
||||
hsl(0,94%,54%) 90%
|
||||
) !important;
|
||||
}
|
||||
|
||||
.tabs-assertive > .tabs{
|
||||
background-color: #BD0340 !important;
|
||||
.tabs-assertive > .tabs{
|
||||
background-color: #A50505 !important;
|
||||
|
||||
}
|
||||
|
||||
.bar-custom{
|
||||
background-image: linear-gradient(
|
||||
hsla(340, 100%, 35%, 1) 20%,
|
||||
hsl(340,100%,54%) 90%
|
||||
hsla(0, 94%, 33%, 1) 20%,
|
||||
hsl(0,94%,54%) 90%
|
||||
) !important;
|
||||
font-family: 'Bubblegum Sans', cursive;
|
||||
|
||||
}
|
||||
|
||||
|
||||
.button-custom{
|
||||
background-color: #C60545;
|
||||
text-decoration: none;
|
||||
border: 1px solid #C60545;
|
||||
border-color: #F9135F #F9135F #F9135F #F9135F;
|
||||
color: #fff
|
||||
}
|
||||
font-family: 'Bubblegum Sans', cursive;
|
||||
background-color: #A50505;
|
||||
text-decoration: none;
|
||||
border: 1px solid #A50505;
|
||||
color: #fff
|
||||
}
|
||||
|
||||
.oleo{
|
||||
font-family: 'Bubblegum Sans', cursive;
|
||||
font-size: 1.3em !important;
|
||||
}
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
<link href="lib/ionic/css/ionic.css" rel="stylesheet">
|
||||
<link href='https://fonts.googleapis.com/css?family=Lobster' rel='stylesheet' type='text/css'>
|
||||
<link href='https://fonts.googleapis.com/css?family=Oswald:400,300,700' rel='stylesheet' type='text/css'>
|
||||
<link href='https://fonts.googleapis.com/css?family=Bubblegum+Sans' rel='stylesheet' type='text/css'>
|
||||
<link href="css/style.css" rel="stylesheet">
|
||||
|
||||
<!-- IF using Sass (run gulp sass first), then uncomment below and remove the CSS includes above
|
||||
@@ -16,7 +17,7 @@
|
||||
|
||||
<!-- ionic/angularjs js -->
|
||||
<script src="lib/ionic/js/ionic.bundle.js"></script>
|
||||
|
||||
<script src="js/ng-cordova.min.js"></script>
|
||||
<!-- cordova script (this will be a 404 during development) -->
|
||||
<script src="cordova.js"></script>
|
||||
|
||||
|
||||
@@ -5,21 +5,55 @@
|
||||
// the 2nd parameter is an array of 'requires'
|
||||
// 'starter.services' is found in services.js
|
||||
// 'starter.controllers' is found in controllers.js
|
||||
angular.module('starter', ['ionic', 'starter.controllers', 'starter.services'])
|
||||
var db;
|
||||
|
||||
.run(function($ionicPlatform, $ionicPopup) {
|
||||
angular.module('starter', ['ionic', 'ngCordova', 'starter.controllers', 'starter.services'])
|
||||
|
||||
.run(function($ionicPlatform, $window, $ionicHistory, $database, $ionicPopup, $state, $localstorage, $rootScope) {
|
||||
$ionicPlatform.ready(function() {
|
||||
// Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
|
||||
// for form inputs)
|
||||
|
||||
$ionicPlatform.registerBackButtonAction(function(event) {
|
||||
|
||||
// Handle Android back button to avoid the application exits accidentaly
|
||||
if ($state.current.name=="tab.dash") {
|
||||
$ionicPopup.confirm({
|
||||
title: 'System-Hinweis',
|
||||
template: 'Möchten Sie die App beenden?'
|
||||
}).then(function(res) {
|
||||
if (res) {
|
||||
ionic.Platform.exitApp();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
$ionicHistory.clearCache();
|
||||
$ionicHistory.nextViewOptions({
|
||||
historyRoot: true
|
||||
});
|
||||
$state.go('tab.dash');
|
||||
}
|
||||
}, 100);
|
||||
|
||||
|
||||
if (window.cordova && window.cordova.plugins && window.cordova.plugins.Keyboard) {
|
||||
cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
|
||||
cordova.plugins.Keyboard.disableScroll(true);
|
||||
|
||||
}
|
||||
if (window.StatusBar) {
|
||||
// org.apache.cordova.statusbar required
|
||||
StatusBar.styleDefault();
|
||||
|
||||
// Mandatory for InAppBrowser plugin
|
||||
if(window.cordova){
|
||||
window.open = cordova.InAppBrowser.open;
|
||||
}
|
||||
// Copy the populated database to mobile device destination
|
||||
//if (window.sqlitePlugin && window.cordova) {
|
||||
if (window.sqlitePlugin && window.cordova) {
|
||||
window.plugins.sqlDB.copy("raataar_wrk.db", function (e) {
|
||||
console.log(e);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
function successHandler (result) {
|
||||
var strResult = "";
|
||||
@@ -39,7 +73,16 @@ angular.module('starter', ['ionic', 'starter.controllers', 'starter.services'])
|
||||
if((window.device && device.platform == "Android") && typeof inappbilling !== "undefined") {
|
||||
inappbilling.init(successHandler, errorHandler, {showLog:true});
|
||||
}
|
||||
|
||||
|
||||
// Initialize database through $database service
|
||||
db = $database.initDB();
|
||||
|
||||
if (window.StatusBar) {
|
||||
// org.apache.cordova.statusbar required
|
||||
StatusBar.styleDefault();
|
||||
}
|
||||
|
||||
|
||||
});
|
||||
})
|
||||
|
||||
|
||||
@@ -1,38 +1,56 @@
|
||||
angular.module('starter.controllers', [])
|
||||
|
||||
.controller('DashCtrl', function($scope,$ionicPopup) {
|
||||
.controller('DashCtrl', function($scope,$ionicPopup,$http, $database, $timeout) {
|
||||
|
||||
$scope.preis="";
|
||||
$scope.name="";
|
||||
$scope.freitext="";
|
||||
var showAlert=0;
|
||||
$scope.items=[];
|
||||
$scope.item=[];
|
||||
|
||||
//db = Database.getDb();
|
||||
|
||||
//$scope.items=$localstorage.getObject('items');
|
||||
|
||||
$scope.validate = function() {
|
||||
showAlert=0;
|
||||
if ($scope.name.length < 1){
|
||||
showAlert=1;
|
||||
}
|
||||
if ($scope.freitext.length < 1){
|
||||
showAlert=1;
|
||||
}
|
||||
|
||||
if (showAlert==1){
|
||||
$scope.showAlert();
|
||||
}
|
||||
var link = 'http://api.raataar.de/rosen/vorschau.php';
|
||||
|
||||
$http.post(link, {name : $scope.name, freitext: $scope.freitext, rosen: $scope.preis}).then(function (res){
|
||||
$scope.response = res.data;
|
||||
window.open($scope.response, '_system', 'location=yes');
|
||||
return false;
|
||||
});
|
||||
|
||||
};
|
||||
|
||||
$scope.showAlert = function() {
|
||||
var alertPopup = $ionicPopup.alert({
|
||||
title: 'Uuuupppsssiii',
|
||||
template: 'Bitte prüfe deine Eingaben.'
|
||||
});
|
||||
alertPopup.then(function(res) {
|
||||
console.log('Thank you for not eating my delicious ice cream cone');
|
||||
});
|
||||
};
|
||||
|
||||
function successHandler (result) {
|
||||
$scope.loaddata = function() {
|
||||
$scope.items=[];
|
||||
$database.getAllBuys().then(function (result) {
|
||||
if(result.length>0){
|
||||
alert("daten da");
|
||||
for(i=0;i<result.length;i++){
|
||||
$scope.items.push(result[i]);
|
||||
alert(i);
|
||||
}
|
||||
|
||||
} else {
|
||||
$scope.items=[];
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
$scope.savedata = function() {
|
||||
$scope.item={name: $scope.name, bild: "test"};
|
||||
$scope.items.push($scope.item);
|
||||
$database.setBuys($scope.name,"test");
|
||||
};
|
||||
|
||||
function successBuyHandler (result) {
|
||||
var strResult = "";
|
||||
if(typeof result === 'object') {
|
||||
strResult = JSON.stringify(result);
|
||||
@@ -40,42 +58,68 @@ angular.module('starter.controllers', [])
|
||||
strResult = result;
|
||||
}
|
||||
alert("SUCCESS: \r\n"+strResult );
|
||||
}
|
||||
$timeout(buysuccessHandler, 1000);
|
||||
}
|
||||
|
||||
function errorHandler (error) {
|
||||
function successConsumeHandler (result) {
|
||||
var strResult = "";
|
||||
if(typeof result === 'object') {
|
||||
strResult = JSON.stringify(result);
|
||||
} else {
|
||||
strResult = result;
|
||||
}
|
||||
alert("SUCCESS: \r\n"+strResult );
|
||||
}
|
||||
|
||||
function errorBuyHandler (error) {
|
||||
alert("ERROR: \r\n"+error );
|
||||
}
|
||||
}
|
||||
|
||||
$scope.buyAdFree = function() {
|
||||
function errorConsumeHandler (error) {
|
||||
alert("ERROR: \r\n"+error );
|
||||
}
|
||||
|
||||
|
||||
function buysuccessHandler (result) {
|
||||
inappbilling.consumePurchase(successConsumeHandler, errorConsumeHandler, $scope.preis);
|
||||
var strResult = "";
|
||||
if(typeof result === 'object') {
|
||||
strResult = JSON.stringify(result);
|
||||
} else {
|
||||
strResult = result;
|
||||
}
|
||||
alert("SUCCESS: \r\n"+strResult );
|
||||
}
|
||||
|
||||
$scope.buyRose = function() {
|
||||
|
||||
//alert($scope.preis);
|
||||
|
||||
if((window.device && device.platform == "Android") && typeof inappbilling !== "undefined") {
|
||||
|
||||
|
||||
alert($scope.preis);
|
||||
inappbilling.buy(successHandler, errorHandler,"3xrose");
|
||||
inappbilling.consumePurchase(successHandler, errorHandler, "3xrose");
|
||||
|
||||
|
||||
inappbilling.buy(successBuyHandler, errorBuyHandler, $scope.preis);
|
||||
}
|
||||
}
|
||||
|
||||
})
|
||||
|
||||
.controller('BuysCtrl', function($scope) {
|
||||
// With the new view caching in Ionic, Controllers are only called
|
||||
// when they are recreated or on app start, instead of every page change.
|
||||
// To listen for when this page is active (for example, to refresh data),
|
||||
// listen for the $ionicView.enter event:
|
||||
//
|
||||
//$scope.$on('$ionicView.enter', function(e) {
|
||||
//});
|
||||
|
||||
|
||||
.controller('BuysCtrl', function($scope, $database,$location) {
|
||||
$scope.items=[];
|
||||
//$scope.items=$localstorage.getObject('items');
|
||||
|
||||
$scope.$on('$stateChangeSuccess', function(event, toState, toParams, fromState, fromParams) {
|
||||
if ($location.path() == "/tab/buys") {
|
||||
$database.getAllBuys().then(function (result) {
|
||||
if(result.length>0){
|
||||
for(i=0;i<result.length;i++){
|
||||
$scope.items.push(result[i]);
|
||||
}
|
||||
} else {
|
||||
$scope.items=[];
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
})
|
||||
|
||||
|
||||
11
platforms/android/build/intermediates/assets/release/www/js/ng-cordova.min.js
vendored
Normal file
11
platforms/android/build/intermediates/assets/release/www/js/ng-cordova.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
@@ -1,50 +1,94 @@
|
||||
angular.module('starter.services', [])
|
||||
|
||||
.factory('Chats', function() {
|
||||
// Might use a resource here that returns a JSON array
|
||||
.factory('$localstorage', ['$window', function($window) {
|
||||
return {
|
||||
set: function(key, value) {
|
||||
$window.localStorage[key] = value;
|
||||
},
|
||||
get: function(key, defaultValue) {
|
||||
return $window.localStorage[key] || defaultValue;
|
||||
},
|
||||
setObject: function(key, value) {
|
||||
$window.localStorage[key] = angular.toJson(value);
|
||||
},
|
||||
getObject: function(key) {
|
||||
return JSON.parse($window.localStorage[key] || '[]');
|
||||
},
|
||||
destroy: function(key) {
|
||||
$window.localStorage.removeItem(key);
|
||||
},
|
||||
log: function(key, defaultValue) {
|
||||
console.log($window.localStorage[key] || defaultValue);
|
||||
},
|
||||
logObject: function(key) {
|
||||
console.log(JSON.stringify($window.localStorage[key] || '{}'));
|
||||
}
|
||||
};
|
||||
}])
|
||||
|
||||
// Some fake testing data
|
||||
var chats = [{
|
||||
id: 0,
|
||||
name: 'Ben Sparrow',
|
||||
lastText: 'You on your way?',
|
||||
face: 'img/ben.png'
|
||||
}, {
|
||||
id: 1,
|
||||
name: 'Max Lynx',
|
||||
lastText: 'Hey, it\'s me',
|
||||
face: 'img/max.png'
|
||||
}, {
|
||||
id: 2,
|
||||
name: 'Adam Bradleyson',
|
||||
lastText: 'I should buy a boat',
|
||||
face: 'img/adam.jpg'
|
||||
}, {
|
||||
id: 3,
|
||||
name: 'Perry Governor',
|
||||
lastText: 'Look at my mukluks!',
|
||||
face: 'img/perry.png'
|
||||
}, {
|
||||
id: 4,
|
||||
name: 'Mike Harrington',
|
||||
lastText: 'This is wicked good ice cream.',
|
||||
face: 'img/mike.png'
|
||||
}];
|
||||
.factory('$database',['$cordovaSQLite', function($cordovaSQLite) {
|
||||
var self = this;
|
||||
self.db = null;
|
||||
var query;
|
||||
|
||||
//this updateTable function is for ilustrative use here, it can be changed to manage all queries indeed.
|
||||
updateTable=function (table, column, value, condition) {
|
||||
if(!condition){
|
||||
query = "UPDATE " + table + " SET " + column + " = " + value;
|
||||
} else{
|
||||
query = "UPDATE " + table + " SET " + column + " = " + value + " WHERE " + condition;
|
||||
}
|
||||
return $cordovaSQLite.execute(self.db,query,[]).
|
||||
then(function(result) {
|
||||
console.log(query);
|
||||
query=null;
|
||||
return result;
|
||||
},function(error) {
|
||||
console.error(error);
|
||||
query=null;
|
||||
return error;
|
||||
});
|
||||
};
|
||||
|
||||
return {
|
||||
all: function() {
|
||||
return chats;
|
||||
},
|
||||
remove: function(chat) {
|
||||
chats.splice(chats.indexOf(chat), 1);
|
||||
},
|
||||
get: function(chatId) {
|
||||
for (var i = 0; i < chats.length; i++) {
|
||||
if (chats[i].id === parseInt(chatId)) {
|
||||
return chats[i];
|
||||
initDB: function() {
|
||||
if(window.cordova){
|
||||
//self.db = sqlitePlugin.openDatabase({name: "data.db", location: 2, createFromLocation: 1});
|
||||
self.db = $cordovaSQLite.openDB("raataar_wrk.db");
|
||||
} else {
|
||||
self.db = window.openDatabase('raataar_wrk.db','1','my',800*1024); // only available when WebSQL is available in Browser
|
||||
}
|
||||
console.log('Database opened');
|
||||
return self.db;
|
||||
},
|
||||
setBuys: function(itemName,itemBild) {
|
||||
query="INSERT INTO buys (Name, Bild) VALUES (?,?);";
|
||||
return $cordovaSQLite.execute(self.db,query,[itemName,itemBild]).
|
||||
then(function(result) {
|
||||
console.log("Gespeichert");
|
||||
query=null;
|
||||
}, function(error) {
|
||||
console.error(error);
|
||||
});
|
||||
},
|
||||
getAllBuys: function(){
|
||||
var ArrayQ=[];
|
||||
query="SELECT * FROM buys order by id ASC";
|
||||
return $cordovaSQLite.execute(self.db,query).
|
||||
then(function(result) {
|
||||
for(j=0;j<result.rows.length;j++){
|
||||
var List={};
|
||||
//console.log(result.rows.item(j));
|
||||
List.name=result.rows.item(j).Name;
|
||||
List.bild=result.rows.item(j).Bild;
|
||||
ArrayQ.push(List);
|
||||
}
|
||||
//console.log(ArrayQ);
|
||||
return ArrayQ;
|
||||
},function(e){
|
||||
console.error(error);
|
||||
return error;
|
||||
});
|
||||
}
|
||||
return null;
|
||||
}
|
||||
};
|
||||
});
|
||||
};
|
||||
}]);
|
||||
@@ -1,4 +1,4 @@
|
||||
@charset "UTF-8";
|
||||
@charset "UTF-8";
|
||||
/*!
|
||||
* Copyright 2014 Drifty Co.
|
||||
* http://drifty.com/
|
||||
|
||||
@@ -0,0 +1,237 @@
|
||||
cordova.define("cordova-plugin-file-transfer.FileTransfer", function(require, exports, module) { /*
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
var argscheck = require('cordova/argscheck'),
|
||||
exec = require('cordova/exec'),
|
||||
FileTransferError = require('./FileTransferError'),
|
||||
ProgressEvent = require('cordova-plugin-file.ProgressEvent');
|
||||
|
||||
function newProgressEvent(result) {
|
||||
var pe = new ProgressEvent();
|
||||
pe.lengthComputable = result.lengthComputable;
|
||||
pe.loaded = result.loaded;
|
||||
pe.total = result.total;
|
||||
return pe;
|
||||
}
|
||||
|
||||
function getUrlCredentials(urlString) {
|
||||
var credentialsPattern = /^https?\:\/\/(?:(?:(([^:@\/]*)(?::([^@\/]*))?)?@)?([^:\/?#]*)(?::(\d*))?).*$/,
|
||||
credentials = credentialsPattern.exec(urlString);
|
||||
|
||||
return credentials && credentials[1];
|
||||
}
|
||||
|
||||
function getBasicAuthHeader(urlString) {
|
||||
var header = null;
|
||||
|
||||
|
||||
// This is changed due to MS Windows doesn't support credentials in http uris
|
||||
// so we detect them by regexp and strip off from result url
|
||||
// Proof: http://social.msdn.microsoft.com/Forums/windowsapps/en-US/a327cf3c-f033-4a54-8b7f-03c56ba3203f/windows-foundation-uri-security-problem
|
||||
|
||||
if (window.btoa) {
|
||||
var credentials = getUrlCredentials(urlString);
|
||||
if (credentials) {
|
||||
var authHeader = "Authorization";
|
||||
var authHeaderValue = "Basic " + window.btoa(credentials);
|
||||
|
||||
header = {
|
||||
name : authHeader,
|
||||
value : authHeaderValue
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
return header;
|
||||
}
|
||||
|
||||
function convertHeadersToArray(headers) {
|
||||
var result = [];
|
||||
for (var header in headers) {
|
||||
if (headers.hasOwnProperty(header)) {
|
||||
var headerValue = headers[header];
|
||||
result.push({
|
||||
name: header,
|
||||
value: headerValue.toString()
|
||||
});
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
var idCounter = 0;
|
||||
|
||||
/**
|
||||
* FileTransfer uploads a file to a remote server.
|
||||
* @constructor
|
||||
*/
|
||||
var FileTransfer = function() {
|
||||
this._id = ++idCounter;
|
||||
this.onprogress = null; // optional callback
|
||||
};
|
||||
|
||||
/**
|
||||
* Given an absolute file path, uploads a file on the device to a remote server
|
||||
* using a multipart HTTP request.
|
||||
* @param filePath {String} Full path of the file on the device
|
||||
* @param server {String} URL of the server to receive the file
|
||||
* @param successCallback (Function} Callback to be invoked when upload has completed
|
||||
* @param errorCallback {Function} Callback to be invoked upon error
|
||||
* @param options {FileUploadOptions} Optional parameters such as file name and mimetype
|
||||
* @param trustAllHosts {Boolean} Optional trust all hosts (e.g. for self-signed certs), defaults to false
|
||||
*/
|
||||
FileTransfer.prototype.upload = function(filePath, server, successCallback, errorCallback, options, trustAllHosts) {
|
||||
argscheck.checkArgs('ssFFO*', 'FileTransfer.upload', arguments);
|
||||
// check for options
|
||||
var fileKey = null;
|
||||
var fileName = null;
|
||||
var mimeType = null;
|
||||
var params = null;
|
||||
var chunkedMode = true;
|
||||
var headers = null;
|
||||
var httpMethod = null;
|
||||
var basicAuthHeader = getBasicAuthHeader(server);
|
||||
if (basicAuthHeader) {
|
||||
server = server.replace(getUrlCredentials(server) + '@', '');
|
||||
|
||||
options = options || {};
|
||||
options.headers = options.headers || {};
|
||||
options.headers[basicAuthHeader.name] = basicAuthHeader.value;
|
||||
}
|
||||
|
||||
if (options) {
|
||||
fileKey = options.fileKey;
|
||||
fileName = options.fileName;
|
||||
mimeType = options.mimeType;
|
||||
headers = options.headers;
|
||||
httpMethod = options.httpMethod || "POST";
|
||||
if (httpMethod.toUpperCase() == "PUT"){
|
||||
httpMethod = "PUT";
|
||||
} else {
|
||||
httpMethod = "POST";
|
||||
}
|
||||
if (options.chunkedMode !== null || typeof options.chunkedMode != "undefined") {
|
||||
chunkedMode = options.chunkedMode;
|
||||
}
|
||||
if (options.params) {
|
||||
params = options.params;
|
||||
}
|
||||
else {
|
||||
params = {};
|
||||
}
|
||||
}
|
||||
|
||||
if (cordova.platformId === "windowsphone") {
|
||||
headers = headers && convertHeadersToArray(headers);
|
||||
params = params && convertHeadersToArray(params);
|
||||
}
|
||||
|
||||
var fail = errorCallback && function(e) {
|
||||
var error = new FileTransferError(e.code, e.source, e.target, e.http_status, e.body, e.exception);
|
||||
errorCallback(error);
|
||||
};
|
||||
|
||||
var self = this;
|
||||
var win = function(result) {
|
||||
if (typeof result.lengthComputable != "undefined") {
|
||||
if (self.onprogress) {
|
||||
self.onprogress(newProgressEvent(result));
|
||||
}
|
||||
} else {
|
||||
successCallback && successCallback(result);
|
||||
}
|
||||
};
|
||||
exec(win, fail, 'FileTransfer', 'upload', [filePath, server, fileKey, fileName, mimeType, params, trustAllHosts, chunkedMode, headers, this._id, httpMethod]);
|
||||
};
|
||||
|
||||
/**
|
||||
* Downloads a file form a given URL and saves it to the specified directory.
|
||||
* @param source {String} URL of the server to receive the file
|
||||
* @param target {String} Full path of the file on the device
|
||||
* @param successCallback (Function} Callback to be invoked when upload has completed
|
||||
* @param errorCallback {Function} Callback to be invoked upon error
|
||||
* @param trustAllHosts {Boolean} Optional trust all hosts (e.g. for self-signed certs), defaults to false
|
||||
* @param options {FileDownloadOptions} Optional parameters such as headers
|
||||
*/
|
||||
FileTransfer.prototype.download = function(source, target, successCallback, errorCallback, trustAllHosts, options) {
|
||||
argscheck.checkArgs('ssFF*', 'FileTransfer.download', arguments);
|
||||
var self = this;
|
||||
|
||||
var basicAuthHeader = getBasicAuthHeader(source);
|
||||
if (basicAuthHeader) {
|
||||
source = source.replace(getUrlCredentials(source) + '@', '');
|
||||
|
||||
options = options || {};
|
||||
options.headers = options.headers || {};
|
||||
options.headers[basicAuthHeader.name] = basicAuthHeader.value;
|
||||
}
|
||||
|
||||
var headers = null;
|
||||
if (options) {
|
||||
headers = options.headers || null;
|
||||
}
|
||||
|
||||
if (cordova.platformId === "windowsphone" && headers) {
|
||||
headers = convertHeadersToArray(headers);
|
||||
}
|
||||
|
||||
var win = function(result) {
|
||||
if (typeof result.lengthComputable != "undefined") {
|
||||
if (self.onprogress) {
|
||||
return self.onprogress(newProgressEvent(result));
|
||||
}
|
||||
} else if (successCallback) {
|
||||
var entry = null;
|
||||
if (result.isDirectory) {
|
||||
entry = new (require('cordova-plugin-file.DirectoryEntry'))();
|
||||
}
|
||||
else if (result.isFile) {
|
||||
entry = new (require('cordova-plugin-file.FileEntry'))();
|
||||
}
|
||||
entry.isDirectory = result.isDirectory;
|
||||
entry.isFile = result.isFile;
|
||||
entry.name = result.name;
|
||||
entry.fullPath = result.fullPath;
|
||||
entry.filesystem = new FileSystem(result.filesystemName || (result.filesystem == window.PERSISTENT ? 'persistent' : 'temporary'));
|
||||
entry.nativeURL = result.nativeURL;
|
||||
successCallback(entry);
|
||||
}
|
||||
};
|
||||
|
||||
var fail = errorCallback && function(e) {
|
||||
var error = new FileTransferError(e.code, e.source, e.target, e.http_status, e.body, e.exception);
|
||||
errorCallback(error);
|
||||
};
|
||||
|
||||
exec(win, fail, 'FileTransfer', 'download', [source, target, trustAllHosts, this._id, headers]);
|
||||
};
|
||||
|
||||
/**
|
||||
* Aborts the ongoing file transfer on this object. The original error
|
||||
* callback for the file transfer will be called if necessary.
|
||||
*/
|
||||
FileTransfer.prototype.abort = function() {
|
||||
exec(null, null, 'FileTransfer', 'abort', [this._id]);
|
||||
};
|
||||
|
||||
module.exports = FileTransfer;
|
||||
|
||||
});
|
||||
@@ -0,0 +1,43 @@
|
||||
cordova.define("cordova-plugin-file-transfer.FileTransferError", function(require, exports, module) { /*
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* FileTransferError
|
||||
* @constructor
|
||||
*/
|
||||
var FileTransferError = function(code, source, target, status, body, exception) {
|
||||
this.code = code || null;
|
||||
this.source = source || null;
|
||||
this.target = target || null;
|
||||
this.http_status = status || null;
|
||||
this.body = body || null;
|
||||
this.exception = exception || null;
|
||||
};
|
||||
|
||||
FileTransferError.FILE_NOT_FOUND_ERR = 1;
|
||||
FileTransferError.INVALID_URL_ERR = 2;
|
||||
FileTransferError.CONNECTION_ERR = 3;
|
||||
FileTransferError.ABORT_ERR = 4;
|
||||
FileTransferError.NOT_MODIFIED_ERR = 5;
|
||||
|
||||
module.exports = FileTransferError;
|
||||
|
||||
});
|
||||
@@ -0,0 +1,119 @@
|
||||
cordova.define("cordova-plugin-file.DirectoryEntry", function(require, exports, module) { /*
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
var argscheck = require('cordova/argscheck'),
|
||||
utils = require('cordova/utils'),
|
||||
exec = require('cordova/exec'),
|
||||
Entry = require('./Entry'),
|
||||
FileError = require('./FileError'),
|
||||
DirectoryReader = require('./DirectoryReader');
|
||||
|
||||
/**
|
||||
* An interface representing a directory on the file system.
|
||||
*
|
||||
* {boolean} isFile always false (readonly)
|
||||
* {boolean} isDirectory always true (readonly)
|
||||
* {DOMString} name of the directory, excluding the path leading to it (readonly)
|
||||
* {DOMString} fullPath the absolute full path to the directory (readonly)
|
||||
* {FileSystem} filesystem on which the directory resides (readonly)
|
||||
*/
|
||||
var DirectoryEntry = function(name, fullPath, fileSystem, nativeURL) {
|
||||
|
||||
// add trailing slash if it is missing
|
||||
if ((fullPath) && !/\/$/.test(fullPath)) {
|
||||
fullPath += "/";
|
||||
}
|
||||
// add trailing slash if it is missing
|
||||
if (nativeURL && !/\/$/.test(nativeURL)) {
|
||||
nativeURL += "/";
|
||||
}
|
||||
DirectoryEntry.__super__.constructor.call(this, false, true, name, fullPath, fileSystem, nativeURL);
|
||||
};
|
||||
|
||||
utils.extend(DirectoryEntry, Entry);
|
||||
|
||||
/**
|
||||
* Creates a new DirectoryReader to read entries from this directory
|
||||
*/
|
||||
DirectoryEntry.prototype.createReader = function() {
|
||||
return new DirectoryReader(this.toInternalURL());
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates or looks up a directory
|
||||
*
|
||||
* @param {DOMString} path either a relative or absolute path from this directory in which to look up or create a directory
|
||||
* @param {Flags} options to create or exclusively create the directory
|
||||
* @param {Function} successCallback is called with the new entry
|
||||
* @param {Function} errorCallback is called with a FileError
|
||||
*/
|
||||
DirectoryEntry.prototype.getDirectory = function(path, options, successCallback, errorCallback) {
|
||||
argscheck.checkArgs('sOFF', 'DirectoryEntry.getDirectory', arguments);
|
||||
var fs = this.filesystem;
|
||||
var win = successCallback && function(result) {
|
||||
var entry = new DirectoryEntry(result.name, result.fullPath, fs, result.nativeURL);
|
||||
successCallback(entry);
|
||||
};
|
||||
var fail = errorCallback && function(code) {
|
||||
errorCallback(new FileError(code));
|
||||
};
|
||||
exec(win, fail, "File", "getDirectory", [this.toInternalURL(), path, options]);
|
||||
};
|
||||
|
||||
/**
|
||||
* Deletes a directory and all of it's contents
|
||||
*
|
||||
* @param {Function} successCallback is called with no parameters
|
||||
* @param {Function} errorCallback is called with a FileError
|
||||
*/
|
||||
DirectoryEntry.prototype.removeRecursively = function(successCallback, errorCallback) {
|
||||
argscheck.checkArgs('FF', 'DirectoryEntry.removeRecursively', arguments);
|
||||
var fail = errorCallback && function(code) {
|
||||
errorCallback(new FileError(code));
|
||||
};
|
||||
exec(successCallback, fail, "File", "removeRecursively", [this.toInternalURL()]);
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates or looks up a file
|
||||
*
|
||||
* @param {DOMString} path either a relative or absolute path from this directory in which to look up or create a file
|
||||
* @param {Flags} options to create or exclusively create the file
|
||||
* @param {Function} successCallback is called with the new entry
|
||||
* @param {Function} errorCallback is called with a FileError
|
||||
*/
|
||||
DirectoryEntry.prototype.getFile = function(path, options, successCallback, errorCallback) {
|
||||
argscheck.checkArgs('sOFF', 'DirectoryEntry.getFile', arguments);
|
||||
var fs = this.filesystem;
|
||||
var win = successCallback && function(result) {
|
||||
var FileEntry = require('./FileEntry');
|
||||
var entry = new FileEntry(result.name, result.fullPath, fs, result.nativeURL);
|
||||
successCallback(entry);
|
||||
};
|
||||
var fail = errorCallback && function(code) {
|
||||
errorCallback(new FileError(code));
|
||||
};
|
||||
exec(win, fail, "File", "getFile", [this.toInternalURL(), path, options]);
|
||||
};
|
||||
|
||||
module.exports = DirectoryEntry;
|
||||
|
||||
});
|
||||
@@ -0,0 +1,75 @@
|
||||
cordova.define("cordova-plugin-file.DirectoryReader", function(require, exports, module) { /*
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
var exec = require('cordova/exec'),
|
||||
FileError = require('./FileError') ;
|
||||
|
||||
/**
|
||||
* An interface that lists the files and directories in a directory.
|
||||
*/
|
||||
function DirectoryReader(localURL) {
|
||||
this.localURL = localURL || null;
|
||||
this.hasReadEntries = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of entries from a directory.
|
||||
*
|
||||
* @param {Function} successCallback is called with a list of entries
|
||||
* @param {Function} errorCallback is called with a FileError
|
||||
*/
|
||||
DirectoryReader.prototype.readEntries = function(successCallback, errorCallback) {
|
||||
// If we've already read and passed on this directory's entries, return an empty list.
|
||||
if (this.hasReadEntries) {
|
||||
successCallback([]);
|
||||
return;
|
||||
}
|
||||
var reader = this;
|
||||
var win = typeof successCallback !== 'function' ? null : function(result) {
|
||||
var retVal = [];
|
||||
for (var i=0; i<result.length; i++) {
|
||||
var entry = null;
|
||||
if (result[i].isDirectory) {
|
||||
entry = new (require('./DirectoryEntry'))();
|
||||
}
|
||||
else if (result[i].isFile) {
|
||||
entry = new (require('./FileEntry'))();
|
||||
}
|
||||
entry.isDirectory = result[i].isDirectory;
|
||||
entry.isFile = result[i].isFile;
|
||||
entry.name = result[i].name;
|
||||
entry.fullPath = result[i].fullPath;
|
||||
entry.filesystem = new (require('./FileSystem'))(result[i].filesystemName);
|
||||
entry.nativeURL = result[i].nativeURL;
|
||||
retVal.push(entry);
|
||||
}
|
||||
reader.hasReadEntries = true;
|
||||
successCallback(retVal);
|
||||
};
|
||||
var fail = typeof errorCallback !== 'function' ? null : function(code) {
|
||||
errorCallback(new FileError(code));
|
||||
};
|
||||
exec(win, fail, "File", "readEntries", [this.localURL]);
|
||||
};
|
||||
|
||||
module.exports = DirectoryReader;
|
||||
|
||||
});
|
||||
262
platforms/android/build/intermediates/assets/release/www/plugins/cordova-plugin-file/www/Entry.js
vendored
Normal file
262
platforms/android/build/intermediates/assets/release/www/plugins/cordova-plugin-file/www/Entry.js
vendored
Normal file
@@ -0,0 +1,262 @@
|
||||
cordova.define("cordova-plugin-file.Entry", function(require, exports, module) { /*
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
var argscheck = require('cordova/argscheck'),
|
||||
exec = require('cordova/exec'),
|
||||
FileError = require('./FileError'),
|
||||
Metadata = require('./Metadata');
|
||||
|
||||
/**
|
||||
* Represents a file or directory on the local file system.
|
||||
*
|
||||
* @param isFile
|
||||
* {boolean} true if Entry is a file (readonly)
|
||||
* @param isDirectory
|
||||
* {boolean} true if Entry is a directory (readonly)
|
||||
* @param name
|
||||
* {DOMString} name of the file or directory, excluding the path
|
||||
* leading to it (readonly)
|
||||
* @param fullPath
|
||||
* {DOMString} the absolute full path to the file or directory
|
||||
* (readonly)
|
||||
* @param fileSystem
|
||||
* {FileSystem} the filesystem on which this entry resides
|
||||
* (readonly)
|
||||
* @param nativeURL
|
||||
* {DOMString} an alternate URL which can be used by native
|
||||
* webview controls, for example media players.
|
||||
* (optional, readonly)
|
||||
*/
|
||||
function Entry(isFile, isDirectory, name, fullPath, fileSystem, nativeURL) {
|
||||
this.isFile = !!isFile;
|
||||
this.isDirectory = !!isDirectory;
|
||||
this.name = name || '';
|
||||
this.fullPath = fullPath || '';
|
||||
this.filesystem = fileSystem || null;
|
||||
this.nativeURL = nativeURL || null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Look up the metadata of the entry.
|
||||
*
|
||||
* @param successCallback
|
||||
* {Function} is called with a Metadata object
|
||||
* @param errorCallback
|
||||
* {Function} is called with a FileError
|
||||
*/
|
||||
Entry.prototype.getMetadata = function(successCallback, errorCallback) {
|
||||
argscheck.checkArgs('FF', 'Entry.getMetadata', arguments);
|
||||
var success = successCallback && function(entryMetadata) {
|
||||
var metadata = new Metadata({
|
||||
size: entryMetadata.size,
|
||||
modificationTime: entryMetadata.lastModifiedDate
|
||||
});
|
||||
successCallback(metadata);
|
||||
};
|
||||
var fail = errorCallback && function(code) {
|
||||
errorCallback(new FileError(code));
|
||||
};
|
||||
exec(success, fail, "File", "getFileMetadata", [this.toInternalURL()]);
|
||||
};
|
||||
|
||||
/**
|
||||
* Set the metadata of the entry.
|
||||
*
|
||||
* @param successCallback
|
||||
* {Function} is called with a Metadata object
|
||||
* @param errorCallback
|
||||
* {Function} is called with a FileError
|
||||
* @param metadataObject
|
||||
* {Object} keys and values to set
|
||||
*/
|
||||
Entry.prototype.setMetadata = function(successCallback, errorCallback, metadataObject) {
|
||||
argscheck.checkArgs('FFO', 'Entry.setMetadata', arguments);
|
||||
exec(successCallback, errorCallback, "File", "setMetadata", [this.toInternalURL(), metadataObject]);
|
||||
};
|
||||
|
||||
/**
|
||||
* Move a file or directory to a new location.
|
||||
*
|
||||
* @param parent
|
||||
* {DirectoryEntry} the directory to which to move this entry
|
||||
* @param newName
|
||||
* {DOMString} new name of the entry, defaults to the current name
|
||||
* @param successCallback
|
||||
* {Function} called with the new DirectoryEntry object
|
||||
* @param errorCallback
|
||||
* {Function} called with a FileError
|
||||
*/
|
||||
Entry.prototype.moveTo = function(parent, newName, successCallback, errorCallback) {
|
||||
argscheck.checkArgs('oSFF', 'Entry.moveTo', arguments);
|
||||
var fail = errorCallback && function(code) {
|
||||
errorCallback(new FileError(code));
|
||||
};
|
||||
var filesystem = this.filesystem,
|
||||
srcURL = this.toInternalURL(),
|
||||
// entry name
|
||||
name = newName || this.name,
|
||||
success = function(entry) {
|
||||
if (entry) {
|
||||
if (successCallback) {
|
||||
// create appropriate Entry object
|
||||
var newFSName = entry.filesystemName || (entry.filesystem && entry.filesystem.name);
|
||||
var fs = newFSName ? new FileSystem(newFSName, { name: "", fullPath: "/" }) : new FileSystem(parent.filesystem.name, { name: "", fullPath: "/" });
|
||||
var result = (entry.isDirectory) ? new (require('./DirectoryEntry'))(entry.name, entry.fullPath, fs, entry.nativeURL) : new (require('cordova-plugin-file.FileEntry'))(entry.name, entry.fullPath, fs, entry.nativeURL);
|
||||
successCallback(result);
|
||||
}
|
||||
}
|
||||
else {
|
||||
// no Entry object returned
|
||||
fail && fail(FileError.NOT_FOUND_ERR);
|
||||
}
|
||||
};
|
||||
|
||||
// copy
|
||||
exec(success, fail, "File", "moveTo", [srcURL, parent.toInternalURL(), name]);
|
||||
};
|
||||
|
||||
/**
|
||||
* Copy a directory to a different location.
|
||||
*
|
||||
* @param parent
|
||||
* {DirectoryEntry} the directory to which to copy the entry
|
||||
* @param newName
|
||||
* {DOMString} new name of the entry, defaults to the current name
|
||||
* @param successCallback
|
||||
* {Function} called with the new Entry object
|
||||
* @param errorCallback
|
||||
* {Function} called with a FileError
|
||||
*/
|
||||
Entry.prototype.copyTo = function(parent, newName, successCallback, errorCallback) {
|
||||
argscheck.checkArgs('oSFF', 'Entry.copyTo', arguments);
|
||||
var fail = errorCallback && function(code) {
|
||||
errorCallback(new FileError(code));
|
||||
};
|
||||
var filesystem = this.filesystem,
|
||||
srcURL = this.toInternalURL(),
|
||||
// entry name
|
||||
name = newName || this.name,
|
||||
// success callback
|
||||
success = function(entry) {
|
||||
if (entry) {
|
||||
if (successCallback) {
|
||||
// create appropriate Entry object
|
||||
var newFSName = entry.filesystemName || (entry.filesystem && entry.filesystem.name);
|
||||
var fs = newFSName ? new FileSystem(newFSName, { name: "", fullPath: "/" }) : new FileSystem(parent.filesystem.name, { name: "", fullPath: "/" });
|
||||
var result = (entry.isDirectory) ? new (require('./DirectoryEntry'))(entry.name, entry.fullPath, fs, entry.nativeURL) : new (require('cordova-plugin-file.FileEntry'))(entry.name, entry.fullPath, fs, entry.nativeURL);
|
||||
successCallback(result);
|
||||
}
|
||||
}
|
||||
else {
|
||||
// no Entry object returned
|
||||
fail && fail(FileError.NOT_FOUND_ERR);
|
||||
}
|
||||
};
|
||||
|
||||
// copy
|
||||
exec(success, fail, "File", "copyTo", [srcURL, parent.toInternalURL(), name]);
|
||||
};
|
||||
|
||||
/**
|
||||
* Return a URL that can be passed across the bridge to identify this entry.
|
||||
*/
|
||||
Entry.prototype.toInternalURL = function() {
|
||||
if (this.filesystem && this.filesystem.__format__) {
|
||||
return this.filesystem.__format__(this.fullPath, this.nativeURL);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Return a URL that can be used to identify this entry.
|
||||
* Use a URL that can be used to as the src attribute of a <video> or
|
||||
* <audio> tag. If that is not possible, construct a cdvfile:// URL.
|
||||
*/
|
||||
Entry.prototype.toURL = function() {
|
||||
if (this.nativeURL) {
|
||||
return this.nativeURL;
|
||||
}
|
||||
// fullPath attribute may contain the full URL in the case that
|
||||
// toInternalURL fails.
|
||||
return this.toInternalURL() || "file://localhost" + this.fullPath;
|
||||
};
|
||||
|
||||
/**
|
||||
* Backwards-compatibility: In v1.0.0 - 1.0.2, .toURL would only return a
|
||||
* cdvfile:// URL, and this method was necessary to obtain URLs usable by the
|
||||
* webview.
|
||||
* See CB-6051, CB-6106, CB-6117, CB-6152, CB-6199, CB-6201, CB-6243, CB-6249,
|
||||
* and CB-6300.
|
||||
*/
|
||||
Entry.prototype.toNativeURL = function() {
|
||||
console.log("DEPRECATED: Update your code to use 'toURL'");
|
||||
return this.toURL();
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns a URI that can be used to identify this entry.
|
||||
*
|
||||
* @param {DOMString} mimeType for a FileEntry, the mime type to be used to interpret the file, when loaded through this URI.
|
||||
* @return uri
|
||||
*/
|
||||
Entry.prototype.toURI = function(mimeType) {
|
||||
console.log("DEPRECATED: Update your code to use 'toURL'");
|
||||
return this.toURL();
|
||||
};
|
||||
|
||||
/**
|
||||
* Remove a file or directory. It is an error to attempt to delete a
|
||||
* directory that is not empty. It is an error to attempt to delete a
|
||||
* root directory of a file system.
|
||||
*
|
||||
* @param successCallback {Function} called with no parameters
|
||||
* @param errorCallback {Function} called with a FileError
|
||||
*/
|
||||
Entry.prototype.remove = function(successCallback, errorCallback) {
|
||||
argscheck.checkArgs('FF', 'Entry.remove', arguments);
|
||||
var fail = errorCallback && function(code) {
|
||||
errorCallback(new FileError(code));
|
||||
};
|
||||
exec(successCallback, fail, "File", "remove", [this.toInternalURL()]);
|
||||
};
|
||||
|
||||
/**
|
||||
* Look up the parent DirectoryEntry of this entry.
|
||||
*
|
||||
* @param successCallback {Function} called with the parent DirectoryEntry object
|
||||
* @param errorCallback {Function} called with a FileError
|
||||
*/
|
||||
Entry.prototype.getParent = function(successCallback, errorCallback) {
|
||||
argscheck.checkArgs('FF', 'Entry.getParent', arguments);
|
||||
var fs = this.filesystem;
|
||||
var win = successCallback && function(result) {
|
||||
var DirectoryEntry = require('./DirectoryEntry');
|
||||
var entry = new DirectoryEntry(result.name, result.fullPath, fs, result.nativeURL);
|
||||
successCallback(entry);
|
||||
};
|
||||
var fail = errorCallback && function(code) {
|
||||
errorCallback(new FileError(code));
|
||||
};
|
||||
exec(win, fail, "File", "getParent", [this.toInternalURL()]);
|
||||
};
|
||||
|
||||
module.exports = Entry;
|
||||
|
||||
});
|
||||
81
platforms/android/build/intermediates/assets/release/www/plugins/cordova-plugin-file/www/File.js
vendored
Normal file
81
platforms/android/build/intermediates/assets/release/www/plugins/cordova-plugin-file/www/File.js
vendored
Normal file
@@ -0,0 +1,81 @@
|
||||
cordova.define("cordova-plugin-file.File", function(require, exports, module) { /*
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
* name {DOMString} name of the file, without path information
|
||||
* fullPath {DOMString} the full path of the file, including the name
|
||||
* type {DOMString} mime type
|
||||
* lastModifiedDate {Date} last modified date
|
||||
* size {Number} size of the file in bytes
|
||||
*/
|
||||
|
||||
var File = function(name, localURL, type, lastModifiedDate, size){
|
||||
this.name = name || '';
|
||||
this.localURL = localURL || null;
|
||||
this.type = type || null;
|
||||
this.lastModified = lastModifiedDate || null;
|
||||
// For backwards compatibility, store the timestamp in lastModifiedDate as well
|
||||
this.lastModifiedDate = lastModifiedDate || null;
|
||||
this.size = size || 0;
|
||||
|
||||
// These store the absolute start and end for slicing the file.
|
||||
this.start = 0;
|
||||
this.end = this.size;
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns a "slice" of the file. Since Cordova Files don't contain the actual
|
||||
* content, this really returns a File with adjusted start and end.
|
||||
* Slices of slices are supported.
|
||||
* start {Number} The index at which to start the slice (inclusive).
|
||||
* end {Number} The index at which to end the slice (exclusive).
|
||||
*/
|
||||
File.prototype.slice = function(start, end) {
|
||||
var size = this.end - this.start;
|
||||
var newStart = 0;
|
||||
var newEnd = size;
|
||||
if (arguments.length) {
|
||||
if (start < 0) {
|
||||
newStart = Math.max(size + start, 0);
|
||||
} else {
|
||||
newStart = Math.min(size, start);
|
||||
}
|
||||
}
|
||||
|
||||
if (arguments.length >= 2) {
|
||||
if (end < 0) {
|
||||
newEnd = Math.max(size + end, 0);
|
||||
} else {
|
||||
newEnd = Math.min(end, size);
|
||||
}
|
||||
}
|
||||
|
||||
var newFile = new File(this.name, this.localURL, this.type, this.lastModified, this.size);
|
||||
newFile.start = this.start + newStart;
|
||||
newFile.end = this.start + newEnd;
|
||||
return newFile;
|
||||
};
|
||||
|
||||
|
||||
module.exports = File;
|
||||
|
||||
});
|
||||
@@ -0,0 +1,83 @@
|
||||
cordova.define("cordova-plugin-file.FileEntry", function(require, exports, module) { /*
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
var utils = require('cordova/utils'),
|
||||
exec = require('cordova/exec'),
|
||||
Entry = require('./Entry'),
|
||||
FileWriter = require('./FileWriter'),
|
||||
File = require('./File'),
|
||||
FileError = require('./FileError');
|
||||
|
||||
/**
|
||||
* An interface representing a file on the file system.
|
||||
*
|
||||
* {boolean} isFile always true (readonly)
|
||||
* {boolean} isDirectory always false (readonly)
|
||||
* {DOMString} name of the file, excluding the path leading to it (readonly)
|
||||
* {DOMString} fullPath the absolute full path to the file (readonly)
|
||||
* {FileSystem} filesystem on which the file resides (readonly)
|
||||
*/
|
||||
var FileEntry = function(name, fullPath, fileSystem, nativeURL) {
|
||||
FileEntry.__super__.constructor.apply(this, [true, false, name, fullPath, fileSystem, nativeURL]);
|
||||
};
|
||||
|
||||
utils.extend(FileEntry, Entry);
|
||||
|
||||
/**
|
||||
* Creates a new FileWriter associated with the file that this FileEntry represents.
|
||||
*
|
||||
* @param {Function} successCallback is called with the new FileWriter
|
||||
* @param {Function} errorCallback is called with a FileError
|
||||
*/
|
||||
FileEntry.prototype.createWriter = function(successCallback, errorCallback) {
|
||||
this.file(function(filePointer) {
|
||||
var writer = new FileWriter(filePointer);
|
||||
|
||||
if (writer.localURL === null || writer.localURL === "") {
|
||||
errorCallback && errorCallback(new FileError(FileError.INVALID_STATE_ERR));
|
||||
} else {
|
||||
successCallback && successCallback(writer);
|
||||
}
|
||||
}, errorCallback);
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns a File that represents the current state of the file that this FileEntry represents.
|
||||
*
|
||||
* @param {Function} successCallback is called with the new File object
|
||||
* @param {Function} errorCallback is called with a FileError
|
||||
*/
|
||||
FileEntry.prototype.file = function(successCallback, errorCallback) {
|
||||
var localURL = this.toInternalURL();
|
||||
var win = successCallback && function(f) {
|
||||
var file = new File(f.name, localURL, f.type, f.lastModifiedDate, f.size);
|
||||
successCallback(file);
|
||||
};
|
||||
var fail = errorCallback && function(code) {
|
||||
errorCallback(new FileError(code));
|
||||
};
|
||||
exec(win, fail, "File", "getFileMetadata", [localURL]);
|
||||
};
|
||||
|
||||
|
||||
module.exports = FileEntry;
|
||||
|
||||
});
|
||||
@@ -0,0 +1,48 @@
|
||||
cordova.define("cordova-plugin-file.FileError", function(require, exports, module) { /*
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* FileError
|
||||
*/
|
||||
function FileError(error) {
|
||||
this.code = error || null;
|
||||
}
|
||||
|
||||
// File error codes
|
||||
// Found in DOMException
|
||||
FileError.NOT_FOUND_ERR = 1;
|
||||
FileError.SECURITY_ERR = 2;
|
||||
FileError.ABORT_ERR = 3;
|
||||
|
||||
// Added by File API specification
|
||||
FileError.NOT_READABLE_ERR = 4;
|
||||
FileError.ENCODING_ERR = 5;
|
||||
FileError.NO_MODIFICATION_ALLOWED_ERR = 6;
|
||||
FileError.INVALID_STATE_ERR = 7;
|
||||
FileError.SYNTAX_ERR = 8;
|
||||
FileError.INVALID_MODIFICATION_ERR = 9;
|
||||
FileError.QUOTA_EXCEEDED_ERR = 10;
|
||||
FileError.TYPE_MISMATCH_ERR = 11;
|
||||
FileError.PATH_EXISTS_ERR = 12;
|
||||
|
||||
module.exports = FileError;
|
||||
|
||||
});
|
||||
@@ -0,0 +1,392 @@
|
||||
cordova.define("cordova-plugin-file.FileReader", function(require, exports, module) { /*
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
var exec = require('cordova/exec'),
|
||||
modulemapper = require('cordova/modulemapper'),
|
||||
utils = require('cordova/utils'),
|
||||
File = require('./File'),
|
||||
FileError = require('./FileError'),
|
||||
ProgressEvent = require('./ProgressEvent'),
|
||||
origFileReader = modulemapper.getOriginalSymbol(window, 'FileReader');
|
||||
|
||||
/**
|
||||
* This class reads the mobile device file system.
|
||||
*
|
||||
* For Android:
|
||||
* The root directory is the root of the file system.
|
||||
* To read from the SD card, the file name is "sdcard/my_file.txt"
|
||||
* @constructor
|
||||
*/
|
||||
var FileReader = function() {
|
||||
this._readyState = 0;
|
||||
this._error = null;
|
||||
this._result = null;
|
||||
this._localURL = '';
|
||||
this._realReader = origFileReader ? new origFileReader() : {};
|
||||
};
|
||||
|
||||
// States
|
||||
FileReader.EMPTY = 0;
|
||||
FileReader.LOADING = 1;
|
||||
FileReader.DONE = 2;
|
||||
|
||||
utils.defineGetter(FileReader.prototype, 'readyState', function() {
|
||||
return this._localURL ? this._readyState : this._realReader.readyState;
|
||||
});
|
||||
|
||||
utils.defineGetter(FileReader.prototype, 'error', function() {
|
||||
return this._localURL ? this._error: this._realReader.error;
|
||||
});
|
||||
|
||||
utils.defineGetter(FileReader.prototype, 'result', function() {
|
||||
return this._localURL ? this._result: this._realReader.result;
|
||||
});
|
||||
|
||||
function defineEvent(eventName) {
|
||||
utils.defineGetterSetter(FileReader.prototype, eventName, function() {
|
||||
return this._realReader[eventName] || null;
|
||||
}, function(value) {
|
||||
this._realReader[eventName] = value;
|
||||
});
|
||||
}
|
||||
defineEvent('onloadstart'); // When the read starts.
|
||||
defineEvent('onprogress'); // While reading (and decoding) file or fileBlob data, and reporting partial file data (progress.loaded/progress.total)
|
||||
defineEvent('onload'); // When the read has successfully completed.
|
||||
defineEvent('onerror'); // When the read has failed (see errors).
|
||||
defineEvent('onloadend'); // When the request has completed (either in success or failure).
|
||||
defineEvent('onabort'); // When the read has been aborted. For instance, by invoking the abort() method.
|
||||
|
||||
function initRead(reader, file) {
|
||||
// Already loading something
|
||||
if (reader.readyState == FileReader.LOADING) {
|
||||
throw new FileError(FileError.INVALID_STATE_ERR);
|
||||
}
|
||||
|
||||
reader._result = null;
|
||||
reader._error = null;
|
||||
reader._readyState = FileReader.LOADING;
|
||||
|
||||
if (typeof file.localURL == 'string') {
|
||||
reader._localURL = file.localURL;
|
||||
} else {
|
||||
reader._localURL = '';
|
||||
return true;
|
||||
}
|
||||
|
||||
reader.onloadstart && reader.onloadstart(new ProgressEvent("loadstart", {target:reader}));
|
||||
}
|
||||
|
||||
/**
|
||||
* Abort reading file.
|
||||
*/
|
||||
FileReader.prototype.abort = function() {
|
||||
if (origFileReader && !this._localURL) {
|
||||
return this._realReader.abort();
|
||||
}
|
||||
this._result = null;
|
||||
|
||||
if (this._readyState == FileReader.DONE || this._readyState == FileReader.EMPTY) {
|
||||
return;
|
||||
}
|
||||
|
||||
this._readyState = FileReader.DONE;
|
||||
|
||||
// If abort callback
|
||||
if (typeof this.onabort === 'function') {
|
||||
this.onabort(new ProgressEvent('abort', {target:this}));
|
||||
}
|
||||
// If load end callback
|
||||
if (typeof this.onloadend === 'function') {
|
||||
this.onloadend(new ProgressEvent('loadend', {target:this}));
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Read text file.
|
||||
*
|
||||
* @param file {File} File object containing file properties
|
||||
* @param encoding [Optional] (see http://www.iana.org/assignments/character-sets)
|
||||
*/
|
||||
FileReader.prototype.readAsText = function(file, encoding) {
|
||||
if (initRead(this, file)) {
|
||||
return this._realReader.readAsText(file, encoding);
|
||||
}
|
||||
|
||||
// Default encoding is UTF-8
|
||||
var enc = encoding ? encoding : "UTF-8";
|
||||
var me = this;
|
||||
var execArgs = [this._localURL, enc, file.start, file.end];
|
||||
|
||||
// Read file
|
||||
exec(
|
||||
// Success callback
|
||||
function(r) {
|
||||
// If DONE (cancelled), then don't do anything
|
||||
if (me._readyState === FileReader.DONE) {
|
||||
return;
|
||||
}
|
||||
|
||||
// DONE state
|
||||
me._readyState = FileReader.DONE;
|
||||
|
||||
// Save result
|
||||
me._result = r;
|
||||
|
||||
// If onload callback
|
||||
if (typeof me.onload === "function") {
|
||||
me.onload(new ProgressEvent("load", {target:me}));
|
||||
}
|
||||
|
||||
// If onloadend callback
|
||||
if (typeof me.onloadend === "function") {
|
||||
me.onloadend(new ProgressEvent("loadend", {target:me}));
|
||||
}
|
||||
},
|
||||
// Error callback
|
||||
function(e) {
|
||||
// If DONE (cancelled), then don't do anything
|
||||
if (me._readyState === FileReader.DONE) {
|
||||
return;
|
||||
}
|
||||
|
||||
// DONE state
|
||||
me._readyState = FileReader.DONE;
|
||||
|
||||
// null result
|
||||
me._result = null;
|
||||
|
||||
// Save error
|
||||
me._error = new FileError(e);
|
||||
|
||||
// If onerror callback
|
||||
if (typeof me.onerror === "function") {
|
||||
me.onerror(new ProgressEvent("error", {target:me}));
|
||||
}
|
||||
|
||||
// If onloadend callback
|
||||
if (typeof me.onloadend === "function") {
|
||||
me.onloadend(new ProgressEvent("loadend", {target:me}));
|
||||
}
|
||||
}, "File", "readAsText", execArgs);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Read file and return data as a base64 encoded data url.
|
||||
* A data url is of the form:
|
||||
* data:[<mediatype>][;base64],<data>
|
||||
*
|
||||
* @param file {File} File object containing file properties
|
||||
*/
|
||||
FileReader.prototype.readAsDataURL = function(file) {
|
||||
if (initRead(this, file)) {
|
||||
return this._realReader.readAsDataURL(file);
|
||||
}
|
||||
|
||||
var me = this;
|
||||
var execArgs = [this._localURL, file.start, file.end];
|
||||
|
||||
// Read file
|
||||
exec(
|
||||
// Success callback
|
||||
function(r) {
|
||||
// If DONE (cancelled), then don't do anything
|
||||
if (me._readyState === FileReader.DONE) {
|
||||
return;
|
||||
}
|
||||
|
||||
// DONE state
|
||||
me._readyState = FileReader.DONE;
|
||||
|
||||
// Save result
|
||||
me._result = r;
|
||||
|
||||
// If onload callback
|
||||
if (typeof me.onload === "function") {
|
||||
me.onload(new ProgressEvent("load", {target:me}));
|
||||
}
|
||||
|
||||
// If onloadend callback
|
||||
if (typeof me.onloadend === "function") {
|
||||
me.onloadend(new ProgressEvent("loadend", {target:me}));
|
||||
}
|
||||
},
|
||||
// Error callback
|
||||
function(e) {
|
||||
// If DONE (cancelled), then don't do anything
|
||||
if (me._readyState === FileReader.DONE) {
|
||||
return;
|
||||
}
|
||||
|
||||
// DONE state
|
||||
me._readyState = FileReader.DONE;
|
||||
|
||||
me._result = null;
|
||||
|
||||
// Save error
|
||||
me._error = new FileError(e);
|
||||
|
||||
// If onerror callback
|
||||
if (typeof me.onerror === "function") {
|
||||
me.onerror(new ProgressEvent("error", {target:me}));
|
||||
}
|
||||
|
||||
// If onloadend callback
|
||||
if (typeof me.onloadend === "function") {
|
||||
me.onloadend(new ProgressEvent("loadend", {target:me}));
|
||||
}
|
||||
}, "File", "readAsDataURL", execArgs);
|
||||
};
|
||||
|
||||
/**
|
||||
* Read file and return data as a binary data.
|
||||
*
|
||||
* @param file {File} File object containing file properties
|
||||
*/
|
||||
FileReader.prototype.readAsBinaryString = function(file) {
|
||||
if (initRead(this, file)) {
|
||||
return this._realReader.readAsBinaryString(file);
|
||||
}
|
||||
|
||||
var me = this;
|
||||
var execArgs = [this._localURL, file.start, file.end];
|
||||
|
||||
// Read file
|
||||
exec(
|
||||
// Success callback
|
||||
function(r) {
|
||||
// If DONE (cancelled), then don't do anything
|
||||
if (me._readyState === FileReader.DONE) {
|
||||
return;
|
||||
}
|
||||
|
||||
// DONE state
|
||||
me._readyState = FileReader.DONE;
|
||||
|
||||
me._result = r;
|
||||
|
||||
// If onload callback
|
||||
if (typeof me.onload === "function") {
|
||||
me.onload(new ProgressEvent("load", {target:me}));
|
||||
}
|
||||
|
||||
// If onloadend callback
|
||||
if (typeof me.onloadend === "function") {
|
||||
me.onloadend(new ProgressEvent("loadend", {target:me}));
|
||||
}
|
||||
},
|
||||
// Error callback
|
||||
function(e) {
|
||||
// If DONE (cancelled), then don't do anything
|
||||
if (me._readyState === FileReader.DONE) {
|
||||
return;
|
||||
}
|
||||
|
||||
// DONE state
|
||||
me._readyState = FileReader.DONE;
|
||||
|
||||
me._result = null;
|
||||
|
||||
// Save error
|
||||
me._error = new FileError(e);
|
||||
|
||||
// If onerror callback
|
||||
if (typeof me.onerror === "function") {
|
||||
me.onerror(new ProgressEvent("error", {target:me}));
|
||||
}
|
||||
|
||||
// If onloadend callback
|
||||
if (typeof me.onloadend === "function") {
|
||||
me.onloadend(new ProgressEvent("loadend", {target:me}));
|
||||
}
|
||||
}, "File", "readAsBinaryString", execArgs);
|
||||
};
|
||||
|
||||
/**
|
||||
* Read file and return data as a binary data.
|
||||
*
|
||||
* @param file {File} File object containing file properties
|
||||
*/
|
||||
FileReader.prototype.readAsArrayBuffer = function(file) {
|
||||
if (initRead(this, file)) {
|
||||
return this._realReader.readAsArrayBuffer(file);
|
||||
}
|
||||
|
||||
var me = this;
|
||||
var execArgs = [this._localURL, file.start, file.end];
|
||||
|
||||
// Read file
|
||||
exec(
|
||||
// Success callback
|
||||
function(r) {
|
||||
// If DONE (cancelled), then don't do anything
|
||||
if (me._readyState === FileReader.DONE) {
|
||||
return;
|
||||
}
|
||||
|
||||
// DONE state
|
||||
me._readyState = FileReader.DONE;
|
||||
|
||||
if (r instanceof Array) {
|
||||
r = new Uint8Array(r).buffer;
|
||||
}
|
||||
me._result = r;
|
||||
|
||||
// If onload callback
|
||||
if (typeof me.onload === "function") {
|
||||
me.onload(new ProgressEvent("load", {target:me}));
|
||||
}
|
||||
|
||||
// If onloadend callback
|
||||
if (typeof me.onloadend === "function") {
|
||||
me.onloadend(new ProgressEvent("loadend", {target:me}));
|
||||
}
|
||||
},
|
||||
// Error callback
|
||||
function(e) {
|
||||
// If DONE (cancelled), then don't do anything
|
||||
if (me._readyState === FileReader.DONE) {
|
||||
return;
|
||||
}
|
||||
|
||||
// DONE state
|
||||
me._readyState = FileReader.DONE;
|
||||
|
||||
me._result = null;
|
||||
|
||||
// Save error
|
||||
me._error = new FileError(e);
|
||||
|
||||
// If onerror callback
|
||||
if (typeof me.onerror === "function") {
|
||||
me.onerror(new ProgressEvent("error", {target:me}));
|
||||
}
|
||||
|
||||
// If onloadend callback
|
||||
if (typeof me.onloadend === "function") {
|
||||
me.onloadend(new ProgressEvent("loadend", {target:me}));
|
||||
}
|
||||
}, "File", "readAsArrayBuffer", execArgs);
|
||||
};
|
||||
|
||||
module.exports = FileReader;
|
||||
|
||||
});
|
||||
@@ -0,0 +1,50 @@
|
||||
cordova.define("cordova-plugin-file.FileSystem", function(require, exports, module) { /*
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
var DirectoryEntry = require('./DirectoryEntry');
|
||||
|
||||
/**
|
||||
* An interface representing a file system
|
||||
*
|
||||
* @constructor
|
||||
* {DOMString} name the unique name of the file system (readonly)
|
||||
* {DirectoryEntry} root directory of the file system (readonly)
|
||||
*/
|
||||
var FileSystem = function(name, root) {
|
||||
this.name = name;
|
||||
if (root) {
|
||||
this.root = new DirectoryEntry(root.name, root.fullPath, this, root.nativeURL);
|
||||
} else {
|
||||
this.root = new DirectoryEntry(this.name, '/', this);
|
||||
}
|
||||
};
|
||||
|
||||
FileSystem.prototype.__format__ = function(fullPath, nativeUrl) {
|
||||
return fullPath;
|
||||
};
|
||||
|
||||
FileSystem.prototype.toJSON = function() {
|
||||
return "<FileSystem: " + this.name + ">";
|
||||
};
|
||||
|
||||
module.exports = FileSystem;
|
||||
|
||||
});
|
||||
@@ -0,0 +1,43 @@
|
||||
cordova.define("cordova-plugin-file.FileUploadOptions", function(require, exports, module) { /*
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* Options to customize the HTTP request used to upload files.
|
||||
* @constructor
|
||||
* @param fileKey {String} Name of file request parameter.
|
||||
* @param fileName {String} Filename to be used by the server. Defaults to image.jpg.
|
||||
* @param mimeType {String} Mimetype of the uploaded file. Defaults to image/jpeg.
|
||||
* @param params {Object} Object with key: value params to send to the server.
|
||||
* @param headers {Object} Keys are header names, values are header values. Multiple
|
||||
* headers of the same name are not supported.
|
||||
*/
|
||||
var FileUploadOptions = function(fileKey, fileName, mimeType, params, headers, httpMethod) {
|
||||
this.fileKey = fileKey || null;
|
||||
this.fileName = fileName || null;
|
||||
this.mimeType = mimeType || null;
|
||||
this.params = params || null;
|
||||
this.headers = headers || null;
|
||||
this.httpMethod = httpMethod || null;
|
||||
};
|
||||
|
||||
module.exports = FileUploadOptions;
|
||||
|
||||
});
|
||||
@@ -0,0 +1,31 @@
|
||||
cordova.define("cordova-plugin-file.FileUploadResult", function(require, exports, module) { /*
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* FileUploadResult
|
||||
* @constructor
|
||||
*/
|
||||
module.exports = function FileUploadResult(size, code, content) {
|
||||
this.bytesSent = size;
|
||||
this.responseCode = code;
|
||||
this.response = content;
|
||||
};
|
||||
});
|
||||
@@ -0,0 +1,304 @@
|
||||
cordova.define("cordova-plugin-file.FileWriter", function(require, exports, module) { /*
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
var exec = require('cordova/exec'),
|
||||
FileError = require('./FileError'),
|
||||
ProgressEvent = require('./ProgressEvent');
|
||||
|
||||
/**
|
||||
* This class writes to the mobile device file system.
|
||||
*
|
||||
* For Android:
|
||||
* The root directory is the root of the file system.
|
||||
* To write to the SD card, the file name is "sdcard/my_file.txt"
|
||||
*
|
||||
* @constructor
|
||||
* @param file {File} File object containing file properties
|
||||
* @param append if true write to the end of the file, otherwise overwrite the file
|
||||
*/
|
||||
var FileWriter = function(file) {
|
||||
this.fileName = "";
|
||||
this.length = 0;
|
||||
if (file) {
|
||||
this.localURL = file.localURL || file;
|
||||
this.length = file.size || 0;
|
||||
}
|
||||
// default is to write at the beginning of the file
|
||||
this.position = 0;
|
||||
|
||||
this.readyState = 0; // EMPTY
|
||||
|
||||
this.result = null;
|
||||
|
||||
// Error
|
||||
this.error = null;
|
||||
|
||||
// Event handlers
|
||||
this.onwritestart = null; // When writing starts
|
||||
this.onprogress = null; // While writing the file, and reporting partial file data
|
||||
this.onwrite = null; // When the write has successfully completed.
|
||||
this.onwriteend = null; // When the request has completed (either in success or failure).
|
||||
this.onabort = null; // When the write has been aborted. For instance, by invoking the abort() method.
|
||||
this.onerror = null; // When the write has failed (see errors).
|
||||
};
|
||||
|
||||
// States
|
||||
FileWriter.INIT = 0;
|
||||
FileWriter.WRITING = 1;
|
||||
FileWriter.DONE = 2;
|
||||
|
||||
/**
|
||||
* Abort writing file.
|
||||
*/
|
||||
FileWriter.prototype.abort = function() {
|
||||
// check for invalid state
|
||||
if (this.readyState === FileWriter.DONE || this.readyState === FileWriter.INIT) {
|
||||
throw new FileError(FileError.INVALID_STATE_ERR);
|
||||
}
|
||||
|
||||
// set error
|
||||
this.error = new FileError(FileError.ABORT_ERR);
|
||||
|
||||
this.readyState = FileWriter.DONE;
|
||||
|
||||
// If abort callback
|
||||
if (typeof this.onabort === "function") {
|
||||
this.onabort(new ProgressEvent("abort", {"target":this}));
|
||||
}
|
||||
|
||||
// If write end callback
|
||||
if (typeof this.onwriteend === "function") {
|
||||
this.onwriteend(new ProgressEvent("writeend", {"target":this}));
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Writes data to the file
|
||||
*
|
||||
* @param data text or blob to be written
|
||||
*/
|
||||
FileWriter.prototype.write = function(data) {
|
||||
|
||||
var that=this;
|
||||
var supportsBinary = (typeof window.Blob !== 'undefined' && typeof window.ArrayBuffer !== 'undefined');
|
||||
var isProxySupportBlobNatively = (cordova.platformId === "windows8" || cordova.platformId === "windows");
|
||||
var isBinary;
|
||||
|
||||
// Check to see if the incoming data is a blob
|
||||
if (data instanceof File || (!isProxySupportBlobNatively && supportsBinary && data instanceof Blob)) {
|
||||
var fileReader = new FileReader();
|
||||
fileReader.onload = function() {
|
||||
// Call this method again, with the arraybuffer as argument
|
||||
FileWriter.prototype.write.call(that, this.result);
|
||||
};
|
||||
if (supportsBinary) {
|
||||
fileReader.readAsArrayBuffer(data);
|
||||
} else {
|
||||
fileReader.readAsText(data);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// Mark data type for safer transport over the binary bridge
|
||||
isBinary = supportsBinary && (data instanceof ArrayBuffer);
|
||||
if (isBinary && cordova.platformId === "windowsphone") {
|
||||
// create a plain array, using the keys from the Uint8Array view so that we can serialize it
|
||||
data = Array.apply(null, new Uint8Array(data));
|
||||
}
|
||||
|
||||
// Throw an exception if we are already writing a file
|
||||
if (this.readyState === FileWriter.WRITING) {
|
||||
throw new FileError(FileError.INVALID_STATE_ERR);
|
||||
}
|
||||
|
||||
// WRITING state
|
||||
this.readyState = FileWriter.WRITING;
|
||||
|
||||
var me = this;
|
||||
|
||||
// If onwritestart callback
|
||||
if (typeof me.onwritestart === "function") {
|
||||
me.onwritestart(new ProgressEvent("writestart", {"target":me}));
|
||||
}
|
||||
|
||||
// Write file
|
||||
exec(
|
||||
// Success callback
|
||||
function(r) {
|
||||
// If DONE (cancelled), then don't do anything
|
||||
if (me.readyState === FileWriter.DONE) {
|
||||
return;
|
||||
}
|
||||
|
||||
// position always increases by bytes written because file would be extended
|
||||
me.position += r;
|
||||
// The length of the file is now where we are done writing.
|
||||
|
||||
me.length = me.position;
|
||||
|
||||
// DONE state
|
||||
me.readyState = FileWriter.DONE;
|
||||
|
||||
// If onwrite callback
|
||||
if (typeof me.onwrite === "function") {
|
||||
me.onwrite(new ProgressEvent("write", {"target":me}));
|
||||
}
|
||||
|
||||
// If onwriteend callback
|
||||
if (typeof me.onwriteend === "function") {
|
||||
me.onwriteend(new ProgressEvent("writeend", {"target":me}));
|
||||
}
|
||||
},
|
||||
// Error callback
|
||||
function(e) {
|
||||
// If DONE (cancelled), then don't do anything
|
||||
if (me.readyState === FileWriter.DONE) {
|
||||
return;
|
||||
}
|
||||
|
||||
// DONE state
|
||||
me.readyState = FileWriter.DONE;
|
||||
|
||||
// Save error
|
||||
me.error = new FileError(e);
|
||||
|
||||
// If onerror callback
|
||||
if (typeof me.onerror === "function") {
|
||||
me.onerror(new ProgressEvent("error", {"target":me}));
|
||||
}
|
||||
|
||||
// If onwriteend callback
|
||||
if (typeof me.onwriteend === "function") {
|
||||
me.onwriteend(new ProgressEvent("writeend", {"target":me}));
|
||||
}
|
||||
}, "File", "write", [this.localURL, data, this.position, isBinary]);
|
||||
};
|
||||
|
||||
/**
|
||||
* Moves the file pointer to the location specified.
|
||||
*
|
||||
* If the offset is a negative number the position of the file
|
||||
* pointer is rewound. If the offset is greater than the file
|
||||
* size the position is set to the end of the file.
|
||||
*
|
||||
* @param offset is the location to move the file pointer to.
|
||||
*/
|
||||
FileWriter.prototype.seek = function(offset) {
|
||||
// Throw an exception if we are already writing a file
|
||||
if (this.readyState === FileWriter.WRITING) {
|
||||
throw new FileError(FileError.INVALID_STATE_ERR);
|
||||
}
|
||||
|
||||
if (!offset && offset !== 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
// See back from end of file.
|
||||
if (offset < 0) {
|
||||
this.position = Math.max(offset + this.length, 0);
|
||||
}
|
||||
// Offset is bigger than file size so set position
|
||||
// to the end of the file.
|
||||
else if (offset > this.length) {
|
||||
this.position = this.length;
|
||||
}
|
||||
// Offset is between 0 and file size so set the position
|
||||
// to start writing.
|
||||
else {
|
||||
this.position = offset;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Truncates the file to the size specified.
|
||||
*
|
||||
* @param size to chop the file at.
|
||||
*/
|
||||
FileWriter.prototype.truncate = function(size) {
|
||||
// Throw an exception if we are already writing a file
|
||||
if (this.readyState === FileWriter.WRITING) {
|
||||
throw new FileError(FileError.INVALID_STATE_ERR);
|
||||
}
|
||||
|
||||
// WRITING state
|
||||
this.readyState = FileWriter.WRITING;
|
||||
|
||||
var me = this;
|
||||
|
||||
// If onwritestart callback
|
||||
if (typeof me.onwritestart === "function") {
|
||||
me.onwritestart(new ProgressEvent("writestart", {"target":this}));
|
||||
}
|
||||
|
||||
// Write file
|
||||
exec(
|
||||
// Success callback
|
||||
function(r) {
|
||||
// If DONE (cancelled), then don't do anything
|
||||
if (me.readyState === FileWriter.DONE) {
|
||||
return;
|
||||
}
|
||||
|
||||
// DONE state
|
||||
me.readyState = FileWriter.DONE;
|
||||
|
||||
// Update the length of the file
|
||||
me.length = r;
|
||||
me.position = Math.min(me.position, r);
|
||||
|
||||
// If onwrite callback
|
||||
if (typeof me.onwrite === "function") {
|
||||
me.onwrite(new ProgressEvent("write", {"target":me}));
|
||||
}
|
||||
|
||||
// If onwriteend callback
|
||||
if (typeof me.onwriteend === "function") {
|
||||
me.onwriteend(new ProgressEvent("writeend", {"target":me}));
|
||||
}
|
||||
},
|
||||
// Error callback
|
||||
function(e) {
|
||||
// If DONE (cancelled), then don't do anything
|
||||
if (me.readyState === FileWriter.DONE) {
|
||||
return;
|
||||
}
|
||||
|
||||
// DONE state
|
||||
me.readyState = FileWriter.DONE;
|
||||
|
||||
// Save error
|
||||
me.error = new FileError(e);
|
||||
|
||||
// If onerror callback
|
||||
if (typeof me.onerror === "function") {
|
||||
me.onerror(new ProgressEvent("error", {"target":me}));
|
||||
}
|
||||
|
||||
// If onwriteend callback
|
||||
if (typeof me.onwriteend === "function") {
|
||||
me.onwriteend(new ProgressEvent("writeend", {"target":me}));
|
||||
}
|
||||
}, "File", "truncate", [this.localURL, size]);
|
||||
};
|
||||
|
||||
module.exports = FileWriter;
|
||||
|
||||
});
|
||||
@@ -0,0 +1,38 @@
|
||||
cordova.define("cordova-plugin-file.Flags", function(require, exports, module) { /*
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* Supplies arguments to methods that lookup or create files and directories.
|
||||
*
|
||||
* @param create
|
||||
* {boolean} file or directory if it doesn't exist
|
||||
* @param exclusive
|
||||
* {boolean} used with create; if true the command will fail if
|
||||
* target path exists
|
||||
*/
|
||||
function Flags(create, exclusive) {
|
||||
this.create = create || false;
|
||||
this.exclusive = exclusive || false;
|
||||
}
|
||||
|
||||
module.exports = Flags;
|
||||
|
||||
});
|
||||
@@ -0,0 +1,25 @@
|
||||
cordova.define("cordova-plugin-file.LocalFileSystem", function(require, exports, module) { /*
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
exports.TEMPORARY = 0;
|
||||
exports.PERSISTENT = 1;
|
||||
|
||||
});
|
||||
@@ -0,0 +1,42 @@
|
||||
cordova.define("cordova-plugin-file.Metadata", function(require, exports, module) { /*
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* Information about the state of the file or directory
|
||||
*
|
||||
* {Date} modificationTime (readonly)
|
||||
*/
|
||||
var Metadata = function(metadata) {
|
||||
if (typeof metadata == "object") {
|
||||
this.modificationTime = new Date(metadata.modificationTime);
|
||||
this.size = metadata.size || 0;
|
||||
} else if (typeof metadata == "undefined") {
|
||||
this.modificationTime = null;
|
||||
this.size = 0;
|
||||
} else {
|
||||
/* Backwards compatiblity with platforms that only return a timestamp */
|
||||
this.modificationTime = new Date(metadata);
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = Metadata;
|
||||
|
||||
});
|
||||
@@ -0,0 +1,69 @@
|
||||
cordova.define("cordova-plugin-file.ProgressEvent", function(require, exports, module) { /*
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
// If ProgressEvent exists in global context, use it already, otherwise use our own polyfill
|
||||
// Feature test: See if we can instantiate a native ProgressEvent;
|
||||
// if so, use that approach,
|
||||
// otherwise fill-in with our own implementation.
|
||||
//
|
||||
// NOTE: right now we always fill in with our own. Down the road would be nice if we can use whatever is native in the webview.
|
||||
var ProgressEvent = (function() {
|
||||
/*
|
||||
var createEvent = function(data) {
|
||||
var event = document.createEvent('Events');
|
||||
event.initEvent('ProgressEvent', false, false);
|
||||
if (data) {
|
||||
for (var i in data) {
|
||||
if (data.hasOwnProperty(i)) {
|
||||
event[i] = data[i];
|
||||
}
|
||||
}
|
||||
if (data.target) {
|
||||
// TODO: cannot call <some_custom_object>.dispatchEvent
|
||||
// need to first figure out how to implement EventTarget
|
||||
}
|
||||
}
|
||||
return event;
|
||||
};
|
||||
try {
|
||||
var ev = createEvent({type:"abort",target:document});
|
||||
return function ProgressEvent(type, data) {
|
||||
data.type = type;
|
||||
return createEvent(data);
|
||||
};
|
||||
} catch(e){
|
||||
*/
|
||||
return function ProgressEvent(type, dict) {
|
||||
this.type = type;
|
||||
this.bubbles = false;
|
||||
this.cancelBubble = false;
|
||||
this.cancelable = false;
|
||||
this.lengthComputable = false;
|
||||
this.loaded = dict && dict.loaded ? dict.loaded : 0;
|
||||
this.total = dict && dict.total ? dict.total : 0;
|
||||
this.target = dict && dict.target ? dict.target : null;
|
||||
};
|
||||
//}
|
||||
})();
|
||||
|
||||
module.exports = ProgressEvent;
|
||||
|
||||
});
|
||||
@@ -0,0 +1,38 @@
|
||||
cordova.define("cordova-plugin-file.androidFileSystem", function(require, exports, module) { /*
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
FILESYSTEM_PROTOCOL = "cdvfile";
|
||||
|
||||
module.exports = {
|
||||
__format__: function(fullPath, nativeUrl) {
|
||||
var path = '/' + this.name + '/' + encodeURI(fullPath);
|
||||
path = path.replace('//','/');
|
||||
var ret = FILESYSTEM_PROTOCOL + '://localhost' + path;
|
||||
var m = /\?.*/.exec(nativeUrl);
|
||||
if (m) {
|
||||
ret += m[0];
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
});
|
||||
@@ -0,0 +1,65 @@
|
||||
cordova.define("cordova-plugin-file.fileSystemPaths", function(require, exports, module) { /*
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
var exec = require('cordova/exec');
|
||||
var channel = require('cordova/channel');
|
||||
|
||||
exports.file = {
|
||||
// Read-only directory where the application is installed.
|
||||
applicationDirectory: null,
|
||||
// Root of app's private writable storage
|
||||
applicationStorageDirectory: null,
|
||||
// Where to put app-specific data files.
|
||||
dataDirectory: null,
|
||||
// Cached files that should survive app restarts.
|
||||
// Apps should not rely on the OS to delete files in here.
|
||||
cacheDirectory: null,
|
||||
// Android: the application space on external storage.
|
||||
externalApplicationStorageDirectory: null,
|
||||
// Android: Where to put app-specific data files on external storage.
|
||||
externalDataDirectory: null,
|
||||
// Android: the application cache on external storage.
|
||||
externalCacheDirectory: null,
|
||||
// Android: the external storage (SD card) root.
|
||||
externalRootDirectory: null,
|
||||
// iOS: Temp directory that the OS can clear at will.
|
||||
tempDirectory: null,
|
||||
// iOS: Holds app-specific files that should be synced (e.g. to iCloud).
|
||||
syncedDataDirectory: null,
|
||||
// iOS: Files private to the app, but that are meaningful to other applciations (e.g. Office files)
|
||||
documentsDirectory: null,
|
||||
// BlackBerry10: Files globally available to all apps
|
||||
sharedDirectory: null
|
||||
};
|
||||
|
||||
channel.waitForInitialization('onFileSystemPathsReady');
|
||||
channel.onCordovaReady.subscribe(function() {
|
||||
function after(paths) {
|
||||
for (var k in paths) {
|
||||
exports.file[k] = paths[k];
|
||||
}
|
||||
channel.initializationComplete('onFileSystemPathsReady');
|
||||
}
|
||||
exec(after, null, 'File', 'requestAllPaths', []);
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
@@ -0,0 +1,46 @@
|
||||
cordova.define("cordova-plugin-file.fileSystems-roots", function(require, exports, module) { /*
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
// Map of fsName -> FileSystem.
|
||||
var fsMap = null;
|
||||
var FileSystem = require('./FileSystem');
|
||||
var exec = require('cordova/exec');
|
||||
|
||||
// Overridden by Android, BlackBerry 10 and iOS to populate fsMap.
|
||||
require('./fileSystems').getFs = function(name, callback) {
|
||||
if (fsMap) {
|
||||
callback(fsMap[name]);
|
||||
} else {
|
||||
exec(success, null, "File", "requestAllFileSystems", []);
|
||||
function success(response) {
|
||||
fsMap = {};
|
||||
for (var i = 0; i < response.length; ++i) {
|
||||
var fsRoot = response[i];
|
||||
var fs = new FileSystem(fsRoot.filesystemName, fsRoot);
|
||||
fsMap[fs.name] = fs;
|
||||
}
|
||||
callback(fsMap[name]);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
});
|
||||
@@ -0,0 +1,27 @@
|
||||
cordova.define("cordova-plugin-file.fileSystems", function(require, exports, module) { /*
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
// Overridden by Android, BlackBerry 10 and iOS to populate fsMap.
|
||||
module.exports.getFs = function(name, callback) {
|
||||
callback(null);
|
||||
};
|
||||
|
||||
});
|
||||
@@ -0,0 +1,78 @@
|
||||
cordova.define("cordova-plugin-file.requestFileSystem", function(require, exports, module) { /*
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
//For browser platform: not all browsers use this file.
|
||||
function checkBrowser() {
|
||||
if (cordova.platformId === "browser" && navigator.userAgent.search(/Chrome/) > 0) {
|
||||
var requestFileSystem = window.requestFileSystem || window.webkitRequestFileSystem;
|
||||
module.exports = requestFileSystem;
|
||||
return;
|
||||
}
|
||||
}
|
||||
checkBrowser();
|
||||
|
||||
var argscheck = require('cordova/argscheck'),
|
||||
FileError = require('./FileError'),
|
||||
FileSystem = require('./FileSystem'),
|
||||
exec = require('cordova/exec');
|
||||
var fileSystems = require('./fileSystems');
|
||||
|
||||
/**
|
||||
* Request a file system in which to store application data.
|
||||
* @param type local file system type
|
||||
* @param size indicates how much storage space, in bytes, the application expects to need
|
||||
* @param successCallback invoked with a FileSystem object
|
||||
* @param errorCallback invoked if error occurs retrieving file system
|
||||
*/
|
||||
var requestFileSystem = function(type, size, successCallback, errorCallback) {
|
||||
argscheck.checkArgs('nnFF', 'requestFileSystem', arguments);
|
||||
var fail = function(code) {
|
||||
errorCallback && errorCallback(new FileError(code));
|
||||
};
|
||||
|
||||
if (type < 0) {
|
||||
fail(FileError.SYNTAX_ERR);
|
||||
} else {
|
||||
// if successful, return a FileSystem object
|
||||
var success = function(file_system) {
|
||||
if (file_system) {
|
||||
if (successCallback) {
|
||||
fileSystems.getFs(file_system.name, function(fs) {
|
||||
// This should happen only on platforms that haven't implemented requestAllFileSystems (windows)
|
||||
if (!fs) {
|
||||
fs = new FileSystem(file_system.name, file_system.root);
|
||||
}
|
||||
successCallback(fs);
|
||||
});
|
||||
}
|
||||
}
|
||||
else {
|
||||
// no FileSystem object returned
|
||||
fail(FileError.NOT_FOUND_ERR);
|
||||
}
|
||||
};
|
||||
exec(success, fail, "File", "requestFileSystem", [type, size]);
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = requestFileSystem;
|
||||
|
||||
});
|
||||
@@ -0,0 +1,89 @@
|
||||
cordova.define("cordova-plugin-file.resolveLocalFileSystemURI", function(require, exports, module) { /*
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
//For browser platform: not all browsers use overrided `resolveLocalFileSystemURL`.
|
||||
function checkBrowser() {
|
||||
if (cordova.platformId === "browser" && navigator.userAgent.search(/Chrome/) > 0) {
|
||||
var requestFileSystem = window.requestFileSystem || window.webkitRequestFileSystem;
|
||||
module.exports = requestFileSystem;
|
||||
return;
|
||||
}
|
||||
}
|
||||
checkBrowser();
|
||||
|
||||
var argscheck = require('cordova/argscheck'),
|
||||
DirectoryEntry = require('./DirectoryEntry'),
|
||||
FileEntry = require('./FileEntry'),
|
||||
FileError = require('./FileError'),
|
||||
exec = require('cordova/exec');
|
||||
var fileSystems = require('./fileSystems');
|
||||
|
||||
/**
|
||||
* Look up file system Entry referred to by local URI.
|
||||
* @param {DOMString} uri URI referring to a local file or directory
|
||||
* @param successCallback invoked with Entry object corresponding to URI
|
||||
* @param errorCallback invoked if error occurs retrieving file system entry
|
||||
*/
|
||||
module.exports.resolveLocalFileSystemURL = function(uri, successCallback, errorCallback) {
|
||||
argscheck.checkArgs('sFF', 'resolveLocalFileSystemURI', arguments);
|
||||
// error callback
|
||||
var fail = function(error) {
|
||||
errorCallback && errorCallback(new FileError(error));
|
||||
};
|
||||
// sanity check for 'not:valid:filename' or '/not:valid:filename'
|
||||
// file.spec.12 window.resolveLocalFileSystemURI should error (ENCODING_ERR) when resolving invalid URI with leading /.
|
||||
if(!uri || uri.split(":").length > 2) {
|
||||
setTimeout( function() {
|
||||
fail(FileError.ENCODING_ERR);
|
||||
},0);
|
||||
return;
|
||||
}
|
||||
// if successful, return either a file or directory entry
|
||||
var success = function(entry) {
|
||||
if (entry) {
|
||||
if (successCallback) {
|
||||
// create appropriate Entry object
|
||||
var fsName = entry.filesystemName || (entry.filesystem && entry.filesystem.name) || (entry.filesystem == window.PERSISTENT ? 'persistent' : 'temporary');
|
||||
fileSystems.getFs(fsName, function(fs) {
|
||||
// This should happen only on platforms that haven't implemented requestAllFileSystems (windows)
|
||||
if (!fs) {
|
||||
fs = new FileSystem(fsName, {name:"", fullPath:"/"});
|
||||
}
|
||||
var result = (entry.isDirectory) ? new DirectoryEntry(entry.name, entry.fullPath, fs, entry.nativeURL) : new FileEntry(entry.name, entry.fullPath, fs, entry.nativeURL);
|
||||
successCallback(result);
|
||||
});
|
||||
}
|
||||
}
|
||||
else {
|
||||
// no Entry object returned
|
||||
fail(FileError.NOT_FOUND_ERR);
|
||||
}
|
||||
};
|
||||
|
||||
exec(success, fail, "File", "resolveLocalFileSystemURI", [uri]);
|
||||
};
|
||||
|
||||
module.exports.resolveLocalFileSystemURI = function() {
|
||||
console.log("resolveLocalFileSystemURI is deprecated. Please call resolveLocalFileSystemURL instead.");
|
||||
module.exports.resolveLocalFileSystemURL.apply(this, arguments);
|
||||
};
|
||||
|
||||
});
|
||||
@@ -0,0 +1,112 @@
|
||||
cordova.define("cordova-plugin-inappbrowser.inappbrowser", function(require, exports, module) { /*
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
// special patch to correctly work on Ripple emulator (CB-9760)
|
||||
if (window.parent && !!window.parent.ripple) { // https://gist.github.com/triceam/4658021
|
||||
module.exports = window.open.bind(window); // fallback to default window.open behaviour
|
||||
return;
|
||||
}
|
||||
|
||||
var exec = require('cordova/exec');
|
||||
var channel = require('cordova/channel');
|
||||
var modulemapper = require('cordova/modulemapper');
|
||||
var urlutil = require('cordova/urlutil');
|
||||
|
||||
function InAppBrowser() {
|
||||
this.channels = {
|
||||
'loadstart': channel.create('loadstart'),
|
||||
'loadstop' : channel.create('loadstop'),
|
||||
'loaderror' : channel.create('loaderror'),
|
||||
'exit' : channel.create('exit')
|
||||
};
|
||||
}
|
||||
|
||||
InAppBrowser.prototype = {
|
||||
_eventHandler: function (event) {
|
||||
if (event && (event.type in this.channels)) {
|
||||
this.channels[event.type].fire(event);
|
||||
}
|
||||
},
|
||||
close: function (eventname) {
|
||||
exec(null, null, "InAppBrowser", "close", []);
|
||||
},
|
||||
show: function (eventname) {
|
||||
exec(null, null, "InAppBrowser", "show", []);
|
||||
},
|
||||
addEventListener: function (eventname,f) {
|
||||
if (eventname in this.channels) {
|
||||
this.channels[eventname].subscribe(f);
|
||||
}
|
||||
},
|
||||
removeEventListener: function(eventname, f) {
|
||||
if (eventname in this.channels) {
|
||||
this.channels[eventname].unsubscribe(f);
|
||||
}
|
||||
},
|
||||
|
||||
executeScript: function(injectDetails, cb) {
|
||||
if (injectDetails.code) {
|
||||
exec(cb, null, "InAppBrowser", "injectScriptCode", [injectDetails.code, !!cb]);
|
||||
} else if (injectDetails.file) {
|
||||
exec(cb, null, "InAppBrowser", "injectScriptFile", [injectDetails.file, !!cb]);
|
||||
} else {
|
||||
throw new Error('executeScript requires exactly one of code or file to be specified');
|
||||
}
|
||||
},
|
||||
|
||||
insertCSS: function(injectDetails, cb) {
|
||||
if (injectDetails.code) {
|
||||
exec(cb, null, "InAppBrowser", "injectStyleCode", [injectDetails.code, !!cb]);
|
||||
} else if (injectDetails.file) {
|
||||
exec(cb, null, "InAppBrowser", "injectStyleFile", [injectDetails.file, !!cb]);
|
||||
} else {
|
||||
throw new Error('insertCSS requires exactly one of code or file to be specified');
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = function(strUrl, strWindowName, strWindowFeatures, callbacks) {
|
||||
// Don't catch calls that write to existing frames (e.g. named iframes).
|
||||
if (window.frames && window.frames[strWindowName]) {
|
||||
var origOpenFunc = modulemapper.getOriginalSymbol(window, 'open');
|
||||
return origOpenFunc.apply(window, arguments);
|
||||
}
|
||||
|
||||
strUrl = urlutil.makeAbsolute(strUrl);
|
||||
var iab = new InAppBrowser();
|
||||
|
||||
callbacks = callbacks || {};
|
||||
for (var callbackName in callbacks) {
|
||||
iab.addEventListener(callbackName, callbacks[callbackName]);
|
||||
}
|
||||
|
||||
var cb = function(eventname) {
|
||||
iab._eventHandler(eventname);
|
||||
};
|
||||
|
||||
strWindowFeatures = strWindowFeatures || "";
|
||||
|
||||
exec(cb, cb, "InAppBrowser", "open", [strUrl, strWindowName, strWindowFeatures]);
|
||||
return iab;
|
||||
};
|
||||
|
||||
|
||||
});
|
||||
@@ -0,0 +1,576 @@
|
||||
cordova.define("cordova-sqlite-storage.SQLitePlugin", function(require, exports, module) { (function() {
|
||||
var DB_STATE_INIT, DB_STATE_OPEN, READ_ONLY_REGEX, SQLiteFactory, SQLitePlugin, SQLitePluginTransaction, argsArray, dblocations, newSQLError, nextTick, root, txLocks;
|
||||
|
||||
root = this;
|
||||
|
||||
READ_ONLY_REGEX = /^\s*(?:drop|delete|insert|update|create)\s/i;
|
||||
|
||||
DB_STATE_INIT = "INIT";
|
||||
|
||||
DB_STATE_OPEN = "OPEN";
|
||||
|
||||
txLocks = {};
|
||||
|
||||
newSQLError = function(error, code) {
|
||||
var sqlError;
|
||||
sqlError = error;
|
||||
if (!code) {
|
||||
code = 0;
|
||||
}
|
||||
if (!sqlError) {
|
||||
sqlError = new Error("a plugin had an error but provided no response");
|
||||
sqlError.code = code;
|
||||
}
|
||||
if (typeof sqlError === "string") {
|
||||
sqlError = new Error(error);
|
||||
sqlError.code = code;
|
||||
}
|
||||
if (!sqlError.code && sqlError.message) {
|
||||
sqlError.code = code;
|
||||
}
|
||||
if (!sqlError.code && !sqlError.message) {
|
||||
sqlError = new Error("an unknown error was returned: " + JSON.stringify(sqlError));
|
||||
sqlError.code = code;
|
||||
}
|
||||
return sqlError;
|
||||
};
|
||||
|
||||
nextTick = window.setImmediate || function(fun) {
|
||||
window.setTimeout(fun, 0);
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
Utility that avoids leaking the arguments object. See
|
||||
https://www.npmjs.org/package/argsarray
|
||||
*/
|
||||
|
||||
argsArray = function(fun) {
|
||||
return function() {
|
||||
var args, i, len;
|
||||
len = arguments.length;
|
||||
if (len) {
|
||||
args = [];
|
||||
i = -1;
|
||||
while (++i < len) {
|
||||
args[i] = arguments[i];
|
||||
}
|
||||
return fun.call(this, args);
|
||||
} else {
|
||||
return fun.call(this, []);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
SQLitePlugin = function(openargs, openSuccess, openError) {
|
||||
var dbname;
|
||||
if (!(openargs && openargs['name'])) {
|
||||
throw newSQLError("Cannot create a SQLitePlugin db instance without a db name");
|
||||
}
|
||||
dbname = openargs.name;
|
||||
if (typeof dbname !== 'string') {
|
||||
throw newSQLError('sqlite plugin database name must be a string');
|
||||
}
|
||||
this.openargs = openargs;
|
||||
this.dbname = dbname;
|
||||
this.openSuccess = openSuccess;
|
||||
this.openError = openError;
|
||||
this.openSuccess || (this.openSuccess = function() {
|
||||
console.log("DB opened: " + dbname);
|
||||
});
|
||||
this.openError || (this.openError = function(e) {
|
||||
console.log(e.message);
|
||||
});
|
||||
this.open(this.openSuccess, this.openError);
|
||||
};
|
||||
|
||||
SQLitePlugin.prototype.databaseFeatures = {
|
||||
isSQLitePluginDatabase: true
|
||||
};
|
||||
|
||||
SQLitePlugin.prototype.openDBs = {};
|
||||
|
||||
SQLitePlugin.prototype.addTransaction = function(t) {
|
||||
if (!txLocks[this.dbname]) {
|
||||
txLocks[this.dbname] = {
|
||||
queue: [],
|
||||
inProgress: false
|
||||
};
|
||||
}
|
||||
txLocks[this.dbname].queue.push(t);
|
||||
if (this.dbname in this.openDBs && this.openDBs[this.dbname] !== DB_STATE_INIT) {
|
||||
this.startNextTransaction();
|
||||
} else {
|
||||
if (this.dbname in this.openDBs) {
|
||||
console.log('new transaction is waiting for open operation');
|
||||
} else {
|
||||
console.log('database is closed, new transaction is [stuck] waiting until db is opened again!');
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
SQLitePlugin.prototype.transaction = function(fn, error, success) {
|
||||
if (!this.openDBs[this.dbname]) {
|
||||
error(newSQLError('database not open'));
|
||||
return;
|
||||
}
|
||||
this.addTransaction(new SQLitePluginTransaction(this, fn, error, success, true, false));
|
||||
};
|
||||
|
||||
SQLitePlugin.prototype.readTransaction = function(fn, error, success) {
|
||||
if (!this.openDBs[this.dbname]) {
|
||||
error(newSQLError('database not open'));
|
||||
return;
|
||||
}
|
||||
this.addTransaction(new SQLitePluginTransaction(this, fn, error, success, false, true));
|
||||
};
|
||||
|
||||
SQLitePlugin.prototype.startNextTransaction = function() {
|
||||
var self;
|
||||
self = this;
|
||||
nextTick((function(_this) {
|
||||
return function() {
|
||||
var txLock;
|
||||
if (!(_this.dbname in _this.openDBs) || _this.openDBs[_this.dbname] !== DB_STATE_OPEN) {
|
||||
console.log('cannot start next transaction: database not open');
|
||||
return;
|
||||
}
|
||||
txLock = txLocks[self.dbname];
|
||||
if (!txLock) {
|
||||
console.log('cannot start next transaction: database connection is lost');
|
||||
return;
|
||||
} else if (txLock.queue.length > 0 && !txLock.inProgress) {
|
||||
txLock.inProgress = true;
|
||||
txLock.queue.shift().start();
|
||||
}
|
||||
};
|
||||
})(this));
|
||||
};
|
||||
|
||||
SQLitePlugin.prototype.abortAllPendingTransactions = function() {
|
||||
var j, len1, ref, tx, txLock;
|
||||
txLock = txLocks[this.dbname];
|
||||
if (!!txLock && txLock.queue.length > 0) {
|
||||
ref = txLock.queue;
|
||||
for (j = 0, len1 = ref.length; j < len1; j++) {
|
||||
tx = ref[j];
|
||||
tx.abortFromQ(newSQLError('Invalid database handle'));
|
||||
}
|
||||
txLock.queue = [];
|
||||
txLock.inProgress = false;
|
||||
}
|
||||
};
|
||||
|
||||
SQLitePlugin.prototype.open = function(success, error) {
|
||||
var openerrorcb, opensuccesscb;
|
||||
if (this.dbname in this.openDBs) {
|
||||
console.log('database already open: ' + this.dbname);
|
||||
nextTick((function(_this) {
|
||||
return function() {
|
||||
success(_this);
|
||||
};
|
||||
})(this));
|
||||
} else {
|
||||
console.log('OPEN database: ' + this.dbname);
|
||||
opensuccesscb = (function(_this) {
|
||||
return function() {
|
||||
var txLock;
|
||||
if (!_this.openDBs[_this.dbname]) {
|
||||
console.log('database was closed during open operation');
|
||||
}
|
||||
if (_this.dbname in _this.openDBs) {
|
||||
_this.openDBs[_this.dbname] = DB_STATE_OPEN;
|
||||
}
|
||||
if (!!success) {
|
||||
success(_this);
|
||||
}
|
||||
txLock = txLocks[_this.dbname];
|
||||
if (!!txLock && txLock.queue.length > 0 && !txLock.inProgress) {
|
||||
_this.startNextTransaction();
|
||||
}
|
||||
};
|
||||
})(this);
|
||||
openerrorcb = (function(_this) {
|
||||
return function() {
|
||||
console.log('OPEN database: ' + _this.dbname + ' failed, aborting any pending transactions');
|
||||
if (!!error) {
|
||||
error(newSQLError('Could not open database'));
|
||||
}
|
||||
delete _this.openDBs[_this.dbname];
|
||||
_this.abortAllPendingTransactions();
|
||||
};
|
||||
})(this);
|
||||
this.openDBs[this.dbname] = DB_STATE_INIT;
|
||||
cordova.exec(opensuccesscb, openerrorcb, "SQLitePlugin", "open", [this.openargs]);
|
||||
}
|
||||
};
|
||||
|
||||
SQLitePlugin.prototype.close = function(success, error) {
|
||||
if (this.dbname in this.openDBs) {
|
||||
if (txLocks[this.dbname] && txLocks[this.dbname].inProgress) {
|
||||
console.log('cannot close: transaction is in progress');
|
||||
error(newSQLError('database cannot be closed while a transaction is in progress'));
|
||||
return;
|
||||
}
|
||||
console.log('CLOSE database: ' + this.dbname);
|
||||
delete this.openDBs[this.dbname];
|
||||
if (txLocks[this.dbname]) {
|
||||
console.log('closing db with transaction queue length: ' + txLocks[this.dbname].queue.length);
|
||||
} else {
|
||||
console.log('closing db with no transaction lock state');
|
||||
}
|
||||
cordova.exec(success, error, "SQLitePlugin", "close", [
|
||||
{
|
||||
path: this.dbname
|
||||
}
|
||||
]);
|
||||
} else {
|
||||
console.log('cannot close: database is not open');
|
||||
if (error) {
|
||||
nextTick(function() {
|
||||
return error();
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
SQLitePlugin.prototype.executeSql = function(statement, params, success, error) {
|
||||
var myerror, myfn, mysuccess;
|
||||
mysuccess = function(t, r) {
|
||||
if (!!success) {
|
||||
return success(r);
|
||||
}
|
||||
};
|
||||
myerror = function(t, e) {
|
||||
if (!!error) {
|
||||
return error(e);
|
||||
}
|
||||
};
|
||||
myfn = function(tx) {
|
||||
tx.addStatement(statement, params, mysuccess, myerror);
|
||||
};
|
||||
this.addTransaction(new SQLitePluginTransaction(this, myfn, null, null, false, false));
|
||||
};
|
||||
|
||||
SQLitePluginTransaction = function(db, fn, error, success, txlock, readOnly) {
|
||||
if (typeof fn !== "function") {
|
||||
|
||||
/*
|
||||
This is consistent with the implementation in Chrome -- it
|
||||
throws if you pass anything other than a function. This also
|
||||
prevents us from stalling our txQueue if somebody passes a
|
||||
false value for fn.
|
||||
*/
|
||||
throw newSQLError("transaction expected a function");
|
||||
}
|
||||
this.db = db;
|
||||
this.fn = fn;
|
||||
this.error = error;
|
||||
this.success = success;
|
||||
this.txlock = txlock;
|
||||
this.readOnly = readOnly;
|
||||
this.executes = [];
|
||||
if (txlock) {
|
||||
this.addStatement("BEGIN", [], null, function(tx, err) {
|
||||
throw newSQLError("unable to begin transaction: " + err.message, err.code);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
SQLitePluginTransaction.prototype.start = function() {
|
||||
var err, error1;
|
||||
try {
|
||||
this.fn(this);
|
||||
this.run();
|
||||
} catch (error1) {
|
||||
err = error1;
|
||||
txLocks[this.db.dbname].inProgress = false;
|
||||
this.db.startNextTransaction();
|
||||
if (this.error) {
|
||||
this.error(newSQLError(err));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
SQLitePluginTransaction.prototype.executeSql = function(sql, values, success, error) {
|
||||
if (this.finalized) {
|
||||
throw {
|
||||
message: 'InvalidStateError: DOM Exception 11: This transaction is already finalized. Transactions are committed after its success or failure handlers are called. If you are using a Promise to handle callbacks, be aware that implementations following the A+ standard adhere to run-to-completion semantics and so Promise resolution occurs on a subsequent tick and therefore after the transaction commits.',
|
||||
code: 11
|
||||
};
|
||||
return;
|
||||
}
|
||||
if (this.readOnly && READ_ONLY_REGEX.test(sql)) {
|
||||
this.handleStatementFailure(error, {
|
||||
message: 'invalid sql for a read-only transaction'
|
||||
});
|
||||
return;
|
||||
}
|
||||
this.addStatement(sql, values, success, error);
|
||||
};
|
||||
|
||||
SQLitePluginTransaction.prototype.addStatement = function(sql, values, success, error) {
|
||||
var j, len1, params, t, v;
|
||||
params = [];
|
||||
if (!!values && values.constructor === Array) {
|
||||
for (j = 0, len1 = values.length; j < len1; j++) {
|
||||
v = values[j];
|
||||
t = typeof v;
|
||||
params.push((v === null || v === void 0 || t === 'number' || t === 'string' ? v : v instanceof Blob ? v.valueOf() : v.toString()));
|
||||
}
|
||||
}
|
||||
this.executes.push({
|
||||
success: success,
|
||||
error: error,
|
||||
sql: sql,
|
||||
params: params
|
||||
});
|
||||
};
|
||||
|
||||
SQLitePluginTransaction.prototype.handleStatementSuccess = function(handler, response) {
|
||||
var payload, rows;
|
||||
if (!handler) {
|
||||
return;
|
||||
}
|
||||
rows = response.rows || [];
|
||||
payload = {
|
||||
rows: {
|
||||
item: function(i) {
|
||||
return rows[i];
|
||||
},
|
||||
length: rows.length
|
||||
},
|
||||
rowsAffected: response.rowsAffected || 0,
|
||||
insertId: response.insertId || void 0
|
||||
};
|
||||
handler(this, payload);
|
||||
};
|
||||
|
||||
SQLitePluginTransaction.prototype.handleStatementFailure = function(handler, response) {
|
||||
if (!handler) {
|
||||
throw newSQLError("a statement with no error handler failed: " + response.message, response.code);
|
||||
}
|
||||
if (handler(this, response) !== false) {
|
||||
throw newSQLError("a statement error callback did not return false: " + response.message, response.code);
|
||||
}
|
||||
};
|
||||
|
||||
SQLitePluginTransaction.prototype.run = function() {
|
||||
var batchExecutes, handlerFor, i, mycb, mycbmap, request, tropts, tx, txFailure, waiting;
|
||||
txFailure = null;
|
||||
tropts = [];
|
||||
batchExecutes = this.executes;
|
||||
waiting = batchExecutes.length;
|
||||
this.executes = [];
|
||||
tx = this;
|
||||
handlerFor = function(index, didSucceed) {
|
||||
return function(response) {
|
||||
var err, error1;
|
||||
try {
|
||||
if (didSucceed) {
|
||||
tx.handleStatementSuccess(batchExecutes[index].success, response);
|
||||
} else {
|
||||
tx.handleStatementFailure(batchExecutes[index].error, newSQLError(response));
|
||||
}
|
||||
} catch (error1) {
|
||||
err = error1;
|
||||
if (!txFailure) {
|
||||
txFailure = newSQLError(err);
|
||||
}
|
||||
}
|
||||
if (--waiting === 0) {
|
||||
if (txFailure) {
|
||||
tx.abort(txFailure);
|
||||
} else if (tx.executes.length > 0) {
|
||||
tx.run();
|
||||
} else {
|
||||
tx.finish();
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
i = 0;
|
||||
mycbmap = {};
|
||||
while (i < batchExecutes.length) {
|
||||
request = batchExecutes[i];
|
||||
mycbmap[i] = {
|
||||
success: handlerFor(i, true),
|
||||
error: handlerFor(i, false)
|
||||
};
|
||||
tropts.push({
|
||||
qid: 1111,
|
||||
sql: request.sql,
|
||||
params: request.params
|
||||
});
|
||||
i++;
|
||||
}
|
||||
mycb = function(result) {
|
||||
var j, last, q, r, ref, res, type;
|
||||
last = result.length - 1;
|
||||
for (i = j = 0, ref = last; 0 <= ref ? j <= ref : j >= ref; i = 0 <= ref ? ++j : --j) {
|
||||
r = result[i];
|
||||
type = r.type;
|
||||
res = r.result;
|
||||
q = mycbmap[i];
|
||||
if (q) {
|
||||
if (q[type]) {
|
||||
q[type](res);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
cordova.exec(mycb, null, "SQLitePlugin", "backgroundExecuteSqlBatch", [
|
||||
{
|
||||
dbargs: {
|
||||
dbname: this.db.dbname
|
||||
},
|
||||
executes: tropts
|
||||
}
|
||||
]);
|
||||
};
|
||||
|
||||
SQLitePluginTransaction.prototype.abort = function(txFailure) {
|
||||
var failed, succeeded, tx;
|
||||
if (this.finalized) {
|
||||
return;
|
||||
}
|
||||
tx = this;
|
||||
succeeded = function(tx) {
|
||||
txLocks[tx.db.dbname].inProgress = false;
|
||||
tx.db.startNextTransaction();
|
||||
if (tx.error) {
|
||||
tx.error(txFailure);
|
||||
}
|
||||
};
|
||||
failed = function(tx, err) {
|
||||
txLocks[tx.db.dbname].inProgress = false;
|
||||
tx.db.startNextTransaction();
|
||||
if (tx.error) {
|
||||
tx.error(newSQLError("error while trying to roll back: " + err.message, err.code));
|
||||
}
|
||||
};
|
||||
this.finalized = true;
|
||||
if (this.txlock) {
|
||||
this.addStatement("ROLLBACK", [], succeeded, failed);
|
||||
this.run();
|
||||
} else {
|
||||
succeeded(tx);
|
||||
}
|
||||
};
|
||||
|
||||
SQLitePluginTransaction.prototype.finish = function() {
|
||||
var failed, succeeded, tx;
|
||||
if (this.finalized) {
|
||||
return;
|
||||
}
|
||||
tx = this;
|
||||
succeeded = function(tx) {
|
||||
txLocks[tx.db.dbname].inProgress = false;
|
||||
tx.db.startNextTransaction();
|
||||
if (tx.success) {
|
||||
tx.success();
|
||||
}
|
||||
};
|
||||
failed = function(tx, err) {
|
||||
txLocks[tx.db.dbname].inProgress = false;
|
||||
tx.db.startNextTransaction();
|
||||
if (tx.error) {
|
||||
tx.error(newSQLError("error while trying to commit: " + err.message, err.code));
|
||||
}
|
||||
};
|
||||
this.finalized = true;
|
||||
if (this.txlock) {
|
||||
this.addStatement("COMMIT", [], succeeded, failed);
|
||||
this.run();
|
||||
} else {
|
||||
succeeded(tx);
|
||||
}
|
||||
};
|
||||
|
||||
SQLitePluginTransaction.prototype.abortFromQ = function(sqlerror) {
|
||||
if (this.error) {
|
||||
this.error(sqlerror);
|
||||
}
|
||||
};
|
||||
|
||||
dblocations = ["docs", "libs", "nosync"];
|
||||
|
||||
SQLiteFactory = {
|
||||
|
||||
/*
|
||||
NOTE: this function should NOT be translated from Javascript
|
||||
back to CoffeeScript by js2coffee.
|
||||
If this function is edited in Javascript then someone will
|
||||
have to translate it back to CoffeeScript by hand.
|
||||
*/
|
||||
opendb: argsArray(function(args) {
|
||||
var dblocation, errorcb, first, okcb, openargs;
|
||||
if (args.length < 1) {
|
||||
return null;
|
||||
}
|
||||
first = args[0];
|
||||
openargs = null;
|
||||
okcb = null;
|
||||
errorcb = null;
|
||||
if (first.constructor === String) {
|
||||
openargs = {
|
||||
name: first
|
||||
};
|
||||
if (args.length >= 5) {
|
||||
okcb = args[4];
|
||||
if (args.length > 5) {
|
||||
errorcb = args[5];
|
||||
}
|
||||
}
|
||||
} else {
|
||||
openargs = first;
|
||||
if (args.length >= 2) {
|
||||
okcb = args[1];
|
||||
if (args.length > 2) {
|
||||
errorcb = args[2];
|
||||
}
|
||||
}
|
||||
}
|
||||
dblocation = !!openargs.location ? dblocations[openargs.location] : null;
|
||||
openargs.dblocation = dblocation || dblocations[0];
|
||||
if (!!openargs.createFromLocation && openargs.createFromLocation === 1) {
|
||||
openargs.createFromResource = "1";
|
||||
}
|
||||
if (!!openargs.androidDatabaseImplementation && openargs.androidDatabaseImplementation === 2) {
|
||||
openargs.androidOldDatabaseImplementation = 1;
|
||||
}
|
||||
if (!!openargs.androidLockWorkaround && openargs.androidLockWorkaround === 1) {
|
||||
openargs.androidBugWorkaround = 1;
|
||||
}
|
||||
return new SQLitePlugin(openargs, okcb, errorcb);
|
||||
}),
|
||||
deleteDb: function(first, success, error) {
|
||||
var args, dblocation;
|
||||
args = {};
|
||||
if (first.constructor === String) {
|
||||
args.path = first;
|
||||
args.dblocation = dblocations[0];
|
||||
} else {
|
||||
if (!(first && first['name'])) {
|
||||
throw new Error("Please specify db name");
|
||||
}
|
||||
args.path = first.name;
|
||||
dblocation = !!first.location ? dblocations[first.location] : null;
|
||||
args.dblocation = dblocation || dblocations[0];
|
||||
}
|
||||
delete SQLitePlugin.prototype.openDBs[args.path];
|
||||
return cordova.exec(success, error, "SQLitePlugin", "delete", [args]);
|
||||
}
|
||||
};
|
||||
|
||||
root.sqlitePlugin = {
|
||||
sqliteFeatures: {
|
||||
isSQLitePlugin: true
|
||||
},
|
||||
openDatabase: SQLiteFactory.opendb,
|
||||
deleteDatabase: SQLiteFactory.deleteDb
|
||||
};
|
||||
|
||||
}).call(this);
|
||||
|
||||
});
|
||||
@@ -0,0 +1,11 @@
|
||||
cordova.define("me.rahul.plugins.sqlDB.sqlDB", function(require, exports, module) { var exec = require('cordova/exec');
|
||||
|
||||
exports.copy = function(dbname, location, success, error) {
|
||||
exec(success, error, "sqlDB", "copy", [dbname, location]);
|
||||
};
|
||||
|
||||
exports.remove = function(dbname, location, success,error) {
|
||||
exec(success, error, "sqlDB", "remove", [dbname, location]);
|
||||
};
|
||||
|
||||
});
|
||||
Binary file not shown.
@@ -1,16 +1,29 @@
|
||||
<ion-view view-title="Gekaufte Rosen">
|
||||
<ion-content>
|
||||
<ion-list>
|
||||
<ion-item class="item-remove-animate item-avatar item-icon-right" ng-repeat="chat in chats" type="item-text-wrap" href="#/tab/chats/{{chat.id}}">
|
||||
<img ng-src="{{chat.face}}">
|
||||
<h2>{{chat.name}}</h2>
|
||||
<p>{{chat.lastText}}</p>
|
||||
<i class="icon ion-chevron-right icon-accessory"></i>
|
||||
<ion-content class="padding">
|
||||
|
||||
<div style="padding-bottom:15px;">
|
||||
|
||||
<ul class="list card">
|
||||
<div class="item item-divider oleo">Hier können Sie Ihre gekauften Rosen ansehen oder nochmals versenden!</div>
|
||||
|
||||
<a class="item item-thumbnail-left item-button-right" href="#" ng-repeat="i in items" ng-model="items">
|
||||
<img src="img/rose1.png">
|
||||
<h1>{{i.name}}</h1>
|
||||
<p>{{i.freitext}} </p>
|
||||
<div class="buttons" style="margin-top:30px;">
|
||||
<button class="button button-small" >
|
||||
<i class="icon ion-image"> Vorschau</i>
|
||||
</button>
|
||||
<button class="button button-small">
|
||||
<i class="icon ion-android-share-alt"> Teilen</i>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
</a>
|
||||
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
|
||||
<ion-option-button class="button-assertive" ng-click="remove(chat)">
|
||||
Delete
|
||||
</ion-option-button>
|
||||
</ion-item>
|
||||
</ion-list>
|
||||
</ion-content>
|
||||
</ion-view>
|
||||
|
||||
@@ -1,49 +1,38 @@
|
||||
<ion-view view-title='Rosen kaufen'>
|
||||
<ion-content class="padding">
|
||||
<div class="list card">
|
||||
<div class="item item-divider oswald">Wolle Rose kaufen?</div>
|
||||
<div class="item item-body lobster">
|
||||
<div style="padding-bottom:25px;">
|
||||
Schenken Sie einem besonderen Menschen eine aussergewöhnliche Aufmerksamkeit.
|
||||
</div>
|
||||
<div class="item item-divider oswald">An wen wollen Sie die Rose verschenken</div>
|
||||
<div class="list list-inset" style="padding-bottom:15px;">
|
||||
<div class="item item-divider oleo">Schenken Sie einem besonderen Menschen eine außergewöhnliche Aufmerksamkeit!</div>
|
||||
<label class="item item-input item-stacked-label">
|
||||
<span class="input-label">Name Ihres Liebsten:</span>
|
||||
<input type="text" placeholder="" class="lobster" ng-model="$parent.name">
|
||||
<input type="text" placeholder="" class="oleo" ng-model="$parent.name">
|
||||
</label>
|
||||
<label class="item item-input item-stacked-label">
|
||||
<span class="input-label">Ihre persönliche Nachricht:</span>
|
||||
<textarea placeholder="" rows="4" cols="10" class="lobster" ng-model="$parent.freitext"></textarea>
|
||||
<textarea placeholder="" rows="4" cols="10" class="oleo" ng-model="$parent.freitext"></textarea>
|
||||
</label>
|
||||
</div>
|
||||
<div style="padding-bottom:15px;">
|
||||
<div class="item item-divider oswald">Wählen Sie Ihre Rosen aus</div>
|
||||
<div class="item item-divider oleo">Wählen Sie Ihre Rosen aus:</div>
|
||||
<ion-list>
|
||||
<ion-radio ng-model="preis" ng-value="'1xrose'" class="item item-thumbnail-left item-text-wrap"><img src="img/rose1.png"><h2 class="lobster">1 Rose </h2><p>Preis: 0,50 €</p></ion-radio>
|
||||
<ion-radio ng-model="preis" ng-value="'3xrose'" class="item item-thumbnail-left item-text-wrap"><img src="img/rose3.png"><h2 class="lobster">3 Rosen</h2><p>Preis: 1,00 €</p></ion-radio>
|
||||
<ion-radio ng-model="preis" ng-value="'9xrose'" class="item item-thumbnail-left item-text-wrap"><img src="img/rose10.png"><h2 class="lobster">9 Rosen</h2><p>Preis: 2,00 €</p></ion-radio>
|
||||
<ion-radio ng-model="$parent.preis" ng-value="'1xrose'" class="item item-thumbnail-left item-text-wrap"><img src="img/rose1.png"><h2 class="oleo">1 Rose </h2><p>Preis: 0,50 € (zzgl. gesetzl. MwSt.)</p></ion-radio>
|
||||
<ion-radio ng-model="$parent.preis" ng-value="'3xrose'" class="item item-thumbnail-left item-text-wrap"><img src="img/rose3.png"><h2 class="oleo">3 Rosen</h2><p>Preis: 1,00 € (zzgl. gesetzl. MwSt.)</p></ion-radio>
|
||||
<ion-radio ng-model="$parent.preis" ng-value="'9xrose'" class="item item-thumbnail-left item-text-wrap"><img src="img/rose10.png"><h2 class="oleo">9 Rosen</h2><p>Preis: 2,00 € (zzgl. gesetzl. MwSt.)</p></ion-radio>
|
||||
</ion-list>
|
||||
<label class="item item-input item-select">
|
||||
<div class="input-label">
|
||||
Farbe
|
||||
</div>
|
||||
<select>
|
||||
<option selected>Rot</option>
|
||||
<option>Gelb</option>
|
||||
<option>Weiß</option>
|
||||
</select>
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<div class="list card">
|
||||
<div class="item item-divider oleo">Rosen jetzt kaufen?</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col col-50"><button class="button button-full button-small icon-left ion-image button-custom" ng-disabled="!$parent.preis || !$parent.name || !$parent.freitext" ng-click="validate()">Vorschau</button></div>
|
||||
<div class="col col-50"><button class="button button-full button-small icon-left ion-social-euro button-custom" ng-disabled="!$parent.preis || !$parent.freitext || !$parent.name" ng-click="buyRose()">Jetzt Kaufen</button></div>
|
||||
</div>
|
||||
<div class="item item-divider oswald">Rosen kaufen?</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col"><h1 class="lobster">Preis: <span>{{preis}} €</span></h1></div>
|
||||
<div class="col"><br>
|
||||
<button class="button button-small icon-left ion-image button-custom" ng-click="validate()">Vorschau</button>
|
||||
<button class="button button-small icon-left ion-social-euro button-custom" ng-click="buyAdFree()">Jetzt Kaufen</button>
|
||||
</div>
|
||||
<div class="col col-50"><button class="button button-full button-small icon-left ion-image button-custom" ng-disabled="!$parent.preis || !$parent.name || !$parent.freitext" ng-click="loaddata()">Laden</button></div>
|
||||
<div class="col col-50"><button class="button button-full button-small icon-left ion-social-euro button-custom" ng-disabled="!$parent.preis || !$parent.freitext || !$parent.name" ng-click="savedata()">Speichern</button></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user