2016-08-30 13:31:37 -03:00
|
|
|
|
'use strict';
|
|
|
|
|
|
|
2016-09-20 18:22:12 -03:00
|
|
|
|
angular.module('copayApp.services').service('popupService', function($log, $ionicPopup, platformInfo, gettextCatalog) {
|
2016-08-30 13:31:37 -03:00
|
|
|
|
|
2016-08-30 14:56:36 -03:00
|
|
|
|
var isCordova = platformInfo.isCordova;
|
2017-06-08 14:36:55 -03:00
|
|
|
|
var isWindowsPhoneApp = platformInfo.isCordova && platformInfo.isWP;
|
2016-08-30 13:31:37 -03:00
|
|
|
|
|
2016-08-30 14:56:36 -03:00
|
|
|
|
/*************** Ionic ****************/
|
2016-08-30 13:31:37 -03:00
|
|
|
|
|
2017-06-30 13:07:23 -03:00
|
|
|
|
var _ionicAlert = function(title, message, cb, okText) {
|
2016-08-30 13:31:37 -03:00
|
|
|
|
if (!cb) cb = function() {};
|
2016-08-30 14:56:36 -03:00
|
|
|
|
$ionicPopup.alert({
|
2016-08-30 13:31:37 -03:00
|
|
|
|
title: title,
|
2016-09-20 18:22:12 -03:00
|
|
|
|
subTitle: message,
|
2016-10-11 13:06:03 -03:00
|
|
|
|
okType: 'button-clear button-positive',
|
2017-06-30 13:07:23 -03:00
|
|
|
|
okText: okText || gettextCatalog.getString('OK'),
|
2016-08-30 13:31:37 -03:00
|
|
|
|
}).then(cb);
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2016-09-09 11:14:04 -03:00
|
|
|
|
var _ionicConfirm = function(title, message, okText, cancelText, cb) {
|
2016-08-30 13:31:37 -03:00
|
|
|
|
$ionicPopup.confirm({
|
|
|
|
|
|
title: title,
|
2016-09-20 18:22:12 -03:00
|
|
|
|
subTitle: message,
|
2016-09-09 11:14:04 -03:00
|
|
|
|
cancelText: cancelText,
|
|
|
|
|
|
cancelType: 'button-clear button-positive',
|
|
|
|
|
|
okText: okText,
|
|
|
|
|
|
okType: 'button-clear button-positive'
|
2016-08-30 13:31:37 -03:00
|
|
|
|
}).then(function(res) {
|
|
|
|
|
|
return cb(res);
|
|
|
|
|
|
});
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
var _ionicPrompt = function(title, message, opts, cb) {
|
|
|
|
|
|
opts = opts || {};
|
|
|
|
|
|
$ionicPopup.prompt({
|
|
|
|
|
|
title: title,
|
2016-09-16 21:01:19 -03:00
|
|
|
|
subTitle: message,
|
2016-12-20 12:04:29 -03:00
|
|
|
|
cssClass: opts.class,
|
2017-03-13 14:53:11 -03:00
|
|
|
|
template: '<input ng-model="data.response" type="' + opts.inputType + '" value ="" autocomplete="off" autofocus>',
|
2016-09-16 21:01:19 -03:00
|
|
|
|
inputPlaceholder: opts.inputPlaceholder,
|
|
|
|
|
|
defaultText: opts.defaultText
|
2016-08-30 13:31:37 -03:00
|
|
|
|
}).then(function(res) {
|
2016-09-21 14:55:56 -03:00
|
|
|
|
return cb(res);
|
2016-08-30 13:31:37 -03:00
|
|
|
|
});
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2016-08-30 14:56:36 -03:00
|
|
|
|
/*************** Cordova ****************/
|
|
|
|
|
|
|
2017-06-30 13:07:23 -03:00
|
|
|
|
var _cordovaAlert = function(title, message, cb, okText) {
|
2016-08-30 13:31:37 -03:00
|
|
|
|
if (!cb) cb = function() {};
|
2017-06-30 13:07:23 -03:00
|
|
|
|
title = title ? title : '';
|
|
|
|
|
|
okText = okText || gettextCatalog.getString('OK');
|
|
|
|
|
|
navigator.notification.alert(message, cb, title, okText);
|
2016-08-30 13:31:37 -03:00
|
|
|
|
};
|
|
|
|
|
|
|
2016-09-09 11:14:04 -03:00
|
|
|
|
var _cordovaConfirm = function(title, message, okText, cancelText, cb) {
|
|
|
|
|
|
var onConfirm = function(buttonIndex) {
|
2016-11-15 17:10:26 -05:00
|
|
|
|
if (buttonIndex == 2) return cb(true);
|
2016-08-30 13:31:37 -03:00
|
|
|
|
else return cb(false);
|
|
|
|
|
|
}
|
2016-09-20 18:22:12 -03:00
|
|
|
|
okText = okText || gettextCatalog.getString('OK');
|
|
|
|
|
|
cancelText = cancelText || gettextCatalog.getString('Cancel');
|
2017-06-30 13:07:23 -03:00
|
|
|
|
title = title ? title : '';
|
2016-11-15 17:10:26 -05:00
|
|
|
|
navigator.notification.confirm(message, onConfirm, title, [cancelText, okText]);
|
2016-08-30 13:31:37 -03:00
|
|
|
|
};
|
|
|
|
|
|
|
2016-09-21 17:46:20 -03:00
|
|
|
|
var _cordovaPrompt = function(title, message, opts, cb) {
|
2016-09-09 11:14:04 -03:00
|
|
|
|
var onPrompt = function(results) {
|
2016-08-30 14:56:36 -03:00
|
|
|
|
if (results.buttonIndex == 1) return cb(results.input1);
|
2016-08-30 13:31:37 -03:00
|
|
|
|
else return cb();
|
|
|
|
|
|
}
|
2017-06-30 13:07:23 -03:00
|
|
|
|
var okText = gettextCatalog.getString('OK');
|
|
|
|
|
|
var cancelText = gettextCatalog.getString('Cancel');
|
|
|
|
|
|
title = title ? title : '';
|
2017-07-06 10:29:42 -03:00
|
|
|
|
navigator.notification.prompt(message, onPrompt, title, [okText, cancelText], opts.defaultText);
|
2016-08-30 13:31:37 -03:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* Show a simple alert popup
|
|
|
|
|
|
*
|
2016-09-20 18:22:12 -03:00
|
|
|
|
* @param {String} Title (optional)
|
|
|
|
|
|
* @param {String} Message
|
2016-08-30 14:56:36 -03:00
|
|
|
|
* @param {Callback} Function (optional)
|
2016-08-30 13:31:37 -03:00
|
|
|
|
*/
|
|
|
|
|
|
|
2017-06-30 13:07:23 -03:00
|
|
|
|
this.showAlert = function(title, msg, cb, okText) {
|
2016-08-30 20:47:55 -03:00
|
|
|
|
var message = (msg && msg.message) ? msg.message : msg;
|
2016-10-17 11:15:36 -03:00
|
|
|
|
$log.warn(title ? (title + ': ' + message) : message);
|
2016-08-30 13:31:37 -03:00
|
|
|
|
|
|
|
|
|
|
if (isCordova)
|
2017-06-30 13:07:23 -03:00
|
|
|
|
_cordovaAlert(title, message, cb, okText);
|
2016-08-30 13:31:37 -03:00
|
|
|
|
else
|
2017-06-30 13:07:23 -03:00
|
|
|
|
_ionicAlert(title, message, cb, okText);
|
2016-08-30 13:31:37 -03:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* Show a simple confirm popup
|
|
|
|
|
|
*
|
2016-09-20 18:22:12 -03:00
|
|
|
|
* @param {String} Title (optional)
|
2016-08-30 13:31:37 -03:00
|
|
|
|
* @param {String} Message
|
2016-09-20 18:22:12 -03:00
|
|
|
|
* @param {String} okText (optional)
|
|
|
|
|
|
* @param {String} cancelText (optional)
|
2016-08-30 13:31:37 -03:00
|
|
|
|
* @param {Callback} Function
|
|
|
|
|
|
* @returns {Callback} OK: true, Cancel: false
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
2016-09-09 11:14:04 -03:00
|
|
|
|
this.showConfirm = function(title, message, okText, cancelText, cb) {
|
2016-10-17 11:15:36 -03:00
|
|
|
|
$log.warn(title ? (title + ': ' + message) : message);
|
2016-08-30 13:31:37 -03:00
|
|
|
|
|
|
|
|
|
|
if (isCordova)
|
2016-09-09 11:14:04 -03:00
|
|
|
|
_cordovaConfirm(title, message, okText, cancelText, cb);
|
2016-08-30 13:31:37 -03:00
|
|
|
|
else
|
2016-09-09 11:14:04 -03:00
|
|
|
|
_ionicConfirm(title, message, okText, cancelText, cb);
|
2016-08-30 13:31:37 -03:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* Show a simple prompt popup
|
|
|
|
|
|
*
|
2016-09-20 18:22:12 -03:00
|
|
|
|
* @param {String} Title (optional)
|
2016-08-30 13:31:37 -03:00
|
|
|
|
* @param {String} Message
|
2016-09-16 21:01:19 -03:00
|
|
|
|
* @param {Object} Object{ inputType, inputPlaceholder, defaultText } (optional)
|
2016-08-30 13:31:37 -03:00
|
|
|
|
* @param {Callback} Function
|
|
|
|
|
|
* @returns {Callback} Return the value of the input if user presses OK
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
this.showPrompt = function(title, message, opts, cb) {
|
2016-10-17 11:15:36 -03:00
|
|
|
|
$log.warn(title ? (title + ': ' + message) : message);
|
2016-08-30 13:31:37 -03:00
|
|
|
|
|
2016-12-05 16:56:44 -03:00
|
|
|
|
opts = opts || {};
|
2016-10-24 09:23:39 -03:00
|
|
|
|
|
2017-06-08 14:36:55 -03:00
|
|
|
|
if (isCordova && !isWindowsPhoneApp && !opts.forceHTMLPrompt)
|
2016-09-21 17:46:20 -03:00
|
|
|
|
_cordovaPrompt(title, message, opts, cb);
|
2016-08-30 13:31:37 -03:00
|
|
|
|
else
|
|
|
|
|
|
_ionicPrompt(title, message, opts, cb);
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
});
|