Skip to content

Commit

Permalink
fix: admin withdraw paypal mass csv download issue
Browse files Browse the repository at this point in the history
  • Loading branch information
sabbir1991 committed Dec 13, 2018
1 parent 87f22d4 commit e24f004
Show file tree
Hide file tree
Showing 4 changed files with 352 additions and 73 deletions.
78 changes: 43 additions & 35 deletions assets/js/vue-admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -723,49 +723,57 @@ let Currency = dokan_get_lib('Currency');
$.post(ajaxurl, {
'dokan_withdraw_bulk': 'paypal',
'id': ids,
'action': 'withdraw_ajax_submission'
'action': 'withdraw_ajax_submission',
'nonce': dokan.nonce
}, function (response, status, xhr) {
var filename = "";
var disposition = xhr.getResponseHeader('Content-Disposition');
if ('html/csv' === xhr.getResponseHeader('Content-type')) {
var filename = "";
var disposition = xhr.getResponseHeader('Content-Disposition');

if (disposition && disposition.indexOf('attachment') !== -1) {
var filenameRegex = /filename[^;=\n]*=((['"]).*?\2|[^;\n]*)/;
var matches = filenameRegex.exec(disposition);
if (disposition && disposition.indexOf('attachment') !== -1) {
var filenameRegex = /filename[^;=\n]*=((['"]).*?\2|[^;\n]*)/;
var matches = filenameRegex.exec(disposition);

if (matches != null && matches[1]) {
filename = matches[1].replace(/['"]/g, '');
if (matches != null && matches[1]) {
filename = matches[1].replace(/['"]/g, '');
}
}
}

var type = xhr.getResponseHeader('Content-Type');

var blob = typeof File === 'function' ? new File([response], filename, { type: type }) : new Blob([response], { type: type });
if (typeof window.navigator.msSaveBlob !== 'undefined') {
// IE workaround for "HTML7007: One or more blob URLs were revoked by closing the blob for which they were created. These URLs will no longer resolve as the data backing the URL has been freed."
window.navigator.msSaveBlob(blob, filename);
} else {
var URL = window.URL || window.webkitURL;
var downloadUrl = URL.createObjectURL(blob);

if (filename) {
// use HTML5 a[download] attribute to specify filename
var a = document.createElement("a");
// safari doesn't support this yet
if (typeof a.download === 'undefined') {
window.location = downloadUrl;
var type = xhr.getResponseHeader('Content-Type');

var blob = typeof File === 'function' ? new File([response], filename, { type: type }) : new Blob([response], { type: type });
if (typeof window.navigator.msSaveBlob !== 'undefined') {
// IE workaround for "HTML7007: One or more blob URLs were revoked by closing the blob for which they were created. These URLs will no longer resolve as the data backing the URL has been freed."
window.navigator.msSaveBlob(blob, filename);
} else {
var URL = window.URL || window.webkitURL;
var downloadUrl = URL.createObjectURL(blob);

if (filename) {
// use HTML5 a[download] attribute to specify filename
var a = document.createElement("a");
// safari doesn't support this yet
if (typeof a.download === 'undefined') {
window.location = downloadUrl;
} else {
a.href = downloadUrl;
a.download = filename;
document.body.appendChild(a);
a.click();
}
} else {
a.href = downloadUrl;
a.download = filename;
document.body.appendChild(a);
a.click();
window.location = downloadUrl;
}
} else {
window.location = downloadUrl;

setTimeout(function () {
URL.revokeObjectURL(downloadUrl);
}, 100); // cleanup
}
}

setTimeout(function () {
URL.revokeObjectURL(downloadUrl);
}, 100); // cleanup
if (response && response.hasOwnProperty('success') && !response.success) {
alert(response.data);
return;
}
});
}
Expand Down Expand Up @@ -5508,4 +5516,4 @@ function menuFix(slug) {
exports.default = menuFix;

/***/ })
],[58]);
],[58]);
262 changes: 262 additions & 0 deletions assets/js/vue-vendor.js
Original file line number Diff line number Diff line change
Expand Up @@ -24075,5 +24075,267 @@ __webpack_require__(6);
module.exports = __webpack_require__(32);


/***/ }),
/* 149 */,
/* 150 */
/***/ (function(module, exports, __webpack_require__) {

/*
MIT License http://www.opensource.org/licenses/mit-license.php
Author Tobias Koppers @sokra
Modified by Evan You @yyx990803
*/

var hasDocument = typeof document !== 'undefined'

if (typeof DEBUG !== 'undefined' && DEBUG) {
if (!hasDocument) {
throw new Error(
'vue-style-loader cannot be used in a non-browser environment. ' +
"Use { target: 'node' } in your Webpack config to indicate a server-rendering environment."
) }
}

var listToStyles = __webpack_require__(151)

/*
type StyleObject = {
id: number;
parts: Array<StyleObjectPart>
}

type StyleObjectPart = {
css: string;
media: string;
sourceMap: ?string
}
*/

var stylesInDom = {/*
[id: number]: {
id: number,
refs: number,
parts: Array<(obj?: StyleObjectPart) => void>
}
*/}

var head = hasDocument && (document.head || document.getElementsByTagName('head')[0])
var singletonElement = null
var singletonCounter = 0
var isProduction = false
var noop = function () {}
var options = null
var ssrIdKey = 'data-vue-ssr-id'

// Force single-tag solution on IE6-9, which has a hard limit on the # of <style>
// tags it will allow on a page
var isOldIE = typeof navigator !== 'undefined' && /msie [6-9]\b/.test(navigator.userAgent.toLowerCase())

module.exports = function (parentId, list, _isProduction, _options) {
isProduction = _isProduction

options = _options || {}

var styles = listToStyles(parentId, list)
addStylesToDom(styles)

return function update (newList) {
var mayRemove = []
for (var i = 0; i < styles.length; i++) {
var item = styles[i]
var domStyle = stylesInDom[item.id]
domStyle.refs--
mayRemove.push(domStyle)
}
if (newList) {
styles = listToStyles(parentId, newList)
addStylesToDom(styles)
} else {
styles = []
}
for (var i = 0; i < mayRemove.length; i++) {
var domStyle = mayRemove[i]
if (domStyle.refs === 0) {
for (var j = 0; j < domStyle.parts.length; j++) {
domStyle.parts[j]()
}
delete stylesInDom[domStyle.id]
}
}
}
}

function addStylesToDom (styles /* Array<StyleObject> */) {
for (var i = 0; i < styles.length; i++) {
var item = styles[i]
var domStyle = stylesInDom[item.id]
if (domStyle) {
domStyle.refs++
for (var j = 0; j < domStyle.parts.length; j++) {
domStyle.parts[j](item.parts[j])
}
for (; j < item.parts.length; j++) {
domStyle.parts.push(addStyle(item.parts[j]))
}
if (domStyle.parts.length > item.parts.length) {
domStyle.parts.length = item.parts.length
}
} else {
var parts = []
for (var j = 0; j < item.parts.length; j++) {
parts.push(addStyle(item.parts[j]))
}
stylesInDom[item.id] = { id: item.id, refs: 1, parts: parts }
}
}
}

function createStyleElement () {
var styleElement = document.createElement('style')
styleElement.type = 'text/css'
head.appendChild(styleElement)
return styleElement
}

function addStyle (obj /* StyleObjectPart */) {
var update, remove
var styleElement = document.querySelector('style[' + ssrIdKey + '~="' + obj.id + '"]')

if (styleElement) {
if (isProduction) {
// has SSR styles and in production mode.
// simply do nothing.
return noop
} else {
// has SSR styles but in dev mode.
// for some reason Chrome can't handle source map in server-rendered
// style tags - source maps in <style> only works if the style tag is
// created and inserted dynamically. So we remove the server rendered
// styles and inject new ones.
styleElement.parentNode.removeChild(styleElement)
}
}

if (isOldIE) {
// use singleton mode for IE9.
var styleIndex = singletonCounter++
styleElement = singletonElement || (singletonElement = createStyleElement())
update = applyToSingletonTag.bind(null, styleElement, styleIndex, false)
remove = applyToSingletonTag.bind(null, styleElement, styleIndex, true)
} else {
// use multi-style-tag mode in all other cases
styleElement = createStyleElement()
update = applyToTag.bind(null, styleElement)
remove = function () {
styleElement.parentNode.removeChild(styleElement)
}
}

update(obj)

return function updateStyle (newObj /* StyleObjectPart */) {
if (newObj) {
if (newObj.css === obj.css &&
newObj.media === obj.media &&
newObj.sourceMap === obj.sourceMap) {
return
}
update(obj = newObj)
} else {
remove()
}
}
}

var replaceText = (function () {
var textStore = []

return function (index, replacement) {
textStore[index] = replacement
return textStore.filter(Boolean).join('\n')
}
})()

function applyToSingletonTag (styleElement, index, remove, obj) {
var css = remove ? '' : obj.css

if (styleElement.styleSheet) {
styleElement.styleSheet.cssText = replaceText(index, css)
} else {
var cssNode = document.createTextNode(css)
var childNodes = styleElement.childNodes
if (childNodes[index]) styleElement.removeChild(childNodes[index])
if (childNodes.length) {
styleElement.insertBefore(cssNode, childNodes[index])
} else {
styleElement.appendChild(cssNode)
}
}
}

function applyToTag (styleElement, obj) {
var css = obj.css
var media = obj.media
var sourceMap = obj.sourceMap

if (media) {
styleElement.setAttribute('media', media)
}
if (options.ssrId) {
styleElement.setAttribute(ssrIdKey, obj.id)
}

if (sourceMap) {
// https://developer.chrome.com/devtools/docs/javascript-debugging
// this makes source maps inside style tags work properly in Chrome
css += '\n/*# sourceURL=' + sourceMap.sources[0] + ' */'
// http://stackoverflow.com/a/26603875
css += '\n/*# sourceMappingURL=data:application/json;base64,' + btoa(unescape(encodeURIComponent(JSON.stringify(sourceMap)))) + ' */'
}

if (styleElement.styleSheet) {
styleElement.styleSheet.cssText = css
} else {
while (styleElement.firstChild) {
styleElement.removeChild(styleElement.firstChild)
}
styleElement.appendChild(document.createTextNode(css))
}
}


/***/ }),
/* 151 */
/***/ (function(module, exports) {

/**
* Translates the list format produced by css-loader into something
* easier to manipulate.
*/
module.exports = function listToStyles (parentId, list) {
var styles = []
var newStyles = {}
for (var i = 0; i < list.length; i++) {
var item = list[i]
var id = item[0]
var css = item[1]
var media = item[2]
var sourceMap = item[3]
var part = {
id: parentId + ':' + i,
css: css,
media: media,
sourceMap: sourceMap
}
if (!newStyles[id]) {
styles.push(newStyles[id] = { id: id, parts: [part] })
} else {
newStyles[id].parts.push(part)
}
}
return styles
}


/***/ })
/******/ ]);
9 changes: 5 additions & 4 deletions classes/admin-withdraw.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,12 @@ public static function init() {
* @return void
*/
public function withdraw_ajax() {

if ( ! current_user_can( 'manage_woocommerce' ) ) {
exit;
wp_send_json_error( __( 'You have no permission to do this action', 'dokan' ) );
}

if ( ! wp_verify_nonce( $_POST['nonce'], 'dokan_admin' ) ) {
wp_send_json_error( __( 'Invalid nonce', 'dokan' ) );
}

header( 'Content-type: html/csv' );
Expand All @@ -47,8 +50,6 @@ public function withdraw_ajax() {
$ids = $_POST['id'];

$this->generate_csv( $ids );

exit;
}

/**
Expand Down
Loading

0 comments on commit e24f004

Please sign in to comment.