| 1 |
jQuery(function ($) { |
| 2 |
const media = wp.media; |
| 3 |
const globalData = window.wpmcs_media_object; |
| 4 |
if (media) { |
| 5 |
const MediaView = media.view; |
| 6 |
const Button = MediaView.Button; |
| 7 |
const AttachmentDetailColumn = MediaView.Attachment.Details.TwoColumn; |
| 8 |
|
| 9 |
if (AttachmentDetailColumn) { |
| 10 |
MediaView.Attachment.Details.TwoColumn = |
| 11 |
AttachmentDetailColumn.extend({ |
| 12 |
render: function () { |
| 13 |
this.fetchProviderDetails(this.model.get("id")); |
| 14 |
}, |
| 15 |
|
| 16 |
fetchProviderDetails: function (id) { |
| 17 |
wp.ajax |
| 18 |
.send("wpmcs_get_attachment_details", { |
| 19 |
data: { |
| 20 |
_nonce: globalData.file_details_nonce, |
| 21 |
id: id, |
| 22 |
}, |
| 23 |
}) |
| 24 |
.done(_.bind(this.renderView, this)); |
| 25 |
}, |
| 26 |
|
| 27 |
renderView: function (response) { |
| 28 |
// Render parent media.view.Attachment.Details |
| 29 |
AttachmentDetailColumn.prototype.render.apply(this); |
| 30 |
|
| 31 |
this.renderServerDetails(response); |
| 32 |
}, |
| 33 |
|
| 34 |
renderServerDetails: function (response) { |
| 35 |
if (response.status) { |
| 36 |
var $detailsHtml = this.$el.find(".details"); |
| 37 |
var data = response.data; |
| 38 |
var append = []; |
| 39 |
if (data.provider) { |
| 40 |
var $providerDiv = $("<div>", { |
| 41 |
class: "wpmcs_provider", |
| 42 |
}); |
| 43 |
$providerDiv.append( |
| 44 |
$("<strong>").text( |
| 45 |
window.wpmcs_media_object.strings |
| 46 |
.provider |
| 47 |
) |
| 48 |
); |
| 49 |
$providerDiv.append( |
| 50 |
document.createTextNode(data.provider) |
| 51 |
); |
| 52 |
append.push($providerDiv); |
| 53 |
} |
| 54 |
if (data.region) { |
| 55 |
var $regionDiv = $("<div>", { |
| 56 |
class: "wpmcs_region", |
| 57 |
}); |
| 58 |
$regionDiv.append( |
| 59 |
$("<strong>").text( |
| 60 |
window.wpmcs_media_object.strings |
| 61 |
.region |
| 62 |
) |
| 63 |
); |
| 64 |
$regionDiv.append( |
| 65 |
document.createTextNode(data.region) |
| 66 |
); |
| 67 |
append.push($regionDiv); |
| 68 |
} |
| 69 |
|
| 70 |
var accessString = data.private |
| 71 |
? window.wpmcs_media_object.strings |
| 72 |
.access_private |
| 73 |
: window.wpmcs_media_object.strings |
| 74 |
.access_public; |
| 75 |
var $accessDiv = $("<div>", { |
| 76 |
class: "wpmcs_access", |
| 77 |
}); |
| 78 |
$accessDiv.append( |
| 79 |
$("<strong>").text( |
| 80 |
window.wpmcs_media_object.strings.access |
| 81 |
) |
| 82 |
); |
| 83 |
$accessDiv.append( |
| 84 |
document.createTextNode(accessString) |
| 85 |
); |
| 86 |
append.push($accessDiv); |
| 87 |
|
| 88 |
if (append.length) { |
| 89 |
append.forEach((element, key) => { |
| 90 |
$detailsHtml.append(element); |
| 91 |
}); |
| 92 |
} |
| 93 |
} |
| 94 |
}, |
| 95 |
}); |
| 96 |
} |
| 97 |
} |
| 98 |
}); |
| 99 |
|