| 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 providerHtml = |
| 41 |
"<div class='wpmcs_provider'><strong>" + |
| 42 |
window.wpmcs_media_object.strings.provider + |
| 43 |
"</strong>" + |
| 44 |
data.provider + |
| 45 |
"</div>"; |
| 46 |
append.push(providerHtml); |
| 47 |
} |
| 48 |
if (data.region) { |
| 49 |
var regionHtml = |
| 50 |
"<div class='wpmcs_region'><strong>" + |
| 51 |
window.wpmcs_media_object.strings.region + |
| 52 |
"</strong>" + |
| 53 |
data.region + |
| 54 |
"</div>"; |
| 55 |
append.push(regionHtml); |
| 56 |
} |
| 57 |
|
| 58 |
var accessString = data.private |
| 59 |
? window.wpmcs_media_object.strings |
| 60 |
.access_private |
| 61 |
: window.wpmcs_media_object.strings |
| 62 |
.access_public; |
| 63 |
var accessHtml = |
| 64 |
"<div class='wpmcs_access'><strong>" + |
| 65 |
window.wpmcs_media_object.strings.access + |
| 66 |
"</strong>" + |
| 67 |
accessString + |
| 68 |
"</div>"; |
| 69 |
|
| 70 |
append.push(accessHtml); |
| 71 |
|
| 72 |
if (append.length) { |
| 73 |
append.forEach((element, key) => { |
| 74 |
$detailsHtml.append(element); |
| 75 |
}); |
| 76 |
} |
| 77 |
} |
| 78 |
}, |
| 79 |
}); |
| 80 |
} |
| 81 |
} |
| 82 |
}); |
| 83 |
|