1
0

ComposeModal.vue 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792
  1. <template>
  2. <div>
  3. <input type="file" id="pf-dz" name="media" class="w-100 h-100 d-none file-input" draggable="true" v-bind:accept="config.uploader.media_types">
  4. <div class="timeline">
  5. <div v-if="uploading">
  6. <div class="card status-card card-md-rounded-0 w-100 h-100 bg-light py-5" style="border-bottom: 1px solid #f1f1f1">
  7. <div class="p-5 mt-2">
  8. <b-progress :value="uploadProgress" :max="100" striped :animated="true"></b-progress>
  9. <p class="text-center mb-0 font-weight-bold">Uploading ... ({{uploadProgress}}%)</p>
  10. </div>
  11. </div>
  12. </div>
  13. <div v-else>
  14. <div class="card status-card card-md-rounded-0 w-100 h-100" style="display:flex;">
  15. <div class="card-header d-inline-flex align-items-center justify-content-between bg-white">
  16. <div>
  17. <a v-if="page == 1" href="#" @click.prevent="closeModal()" class="font-weight-bold text-decoration-none text-muted">
  18. <i class="fas fa-times fa-lg"></i>
  19. <span class="font-weight-bold mb-0">{{pageTitle}}</span>
  20. </a>
  21. <span v-else>
  22. <span>
  23. <a class="text-lighter text-decoration-none mr-3" href="#" @click.prevent="goBack()"><i class="fas fa-long-arrow-alt-left fa-lg"></i></a>
  24. </span>
  25. <span class="font-weight-bold mb-0">{{pageTitle}}</span>
  26. </span>
  27. </div>
  28. <div v-if="page == 2">
  29. <a href="#" class="text-center text-dark" @click.prevent="showCropPhotoCard"><i class="fas fa-magic fa-lg"></i></a>
  30. </div>
  31. <div>
  32. <!-- <a v-if="page > 1" class="font-weight-bold text-decoration-none" href="#" @click.prevent="page--">Back</a> -->
  33. <span v-if="pageLoading">
  34. <div class="spinner-border spinner-border-sm" role="status">
  35. <span class="sr-only">Loading...</span>
  36. </div>
  37. </span>
  38. <span v-else>
  39. <a v-if="!pageLoading && (page > 1 && page <= 2) || (page == 1 && ids.length != 0) || page == 'cropPhoto'" class="font-weight-bold text-decoration-none" href="#" @click.prevent="nextPage">Next</a>
  40. <a v-if="!pageLoading && page == 3" class="font-weight-bold text-decoration-none" href="#" @click.prevent="compose">Post</a>
  41. </span>
  42. </div>
  43. </div>
  44. <div class="card-body p-0 border-top">
  45. <div v-if="page == 1" class="w-100 h-100 d-flex justify-content-center align-items-center" style="min-height: 400px;">
  46. <div class="text-center">
  47. <p>
  48. <a class="btn btn-primary font-weight-bold" href="/i/compose">Compose Post</a>
  49. </p>
  50. <hr>
  51. <p v-if="media.length == 0">
  52. <button type="button" class="btn btn-outline-primary font-weight-bold" @click.prevent="addMedia">Compose Post <sup>BETA</sup></button>
  53. </p>
  54. <p>
  55. <button class="btn btn-outline-primary font-weight-bold" @click.prevent="createCollection">New Collection</button>
  56. </p>
  57. <!-- <p>
  58. <button class="btn btn-outline-primary font-weight-bold" @click.prevent="showAddToStoryCard()">Add To My Story</button>
  59. </p> -->
  60. <p>
  61. <a class="font-weight-bold" href="/site/help">Need Help?</a>
  62. </p>
  63. <p class="text-muted mb-0 small text-center">Formats: <b>{{acceptedFormats()}}</b> up to <b>{{maxSize()}}</b></p>
  64. <p class="text-muted mb-0 small text-center">Albums can contain up to <b>{{config.uploader.album_limit}}</b> photos or videos</p>
  65. </div>
  66. </div>
  67. <div v-if="page == 'cropPhoto'" class="w-100 h-100">
  68. <div v-if="ids.length > 0">
  69. <vue-cropper
  70. ref="cropper"
  71. :relativeZoom="cropper.zoom"
  72. :aspectRatio="cropper.aspectRatio"
  73. :viewMode="cropper.viewMode"
  74. :zoomable="cropper.zoomable"
  75. :rotatable="true"
  76. :src="media[0].url"
  77. >
  78. </vue-cropper>
  79. </div>
  80. </div>
  81. <div v-if="page == 2" class="w-100 h-100">
  82. <div slot="img" style="display:flex;min-height: 420px;align-items: center;">
  83. <img :class="'d-block img-fluid w-100 ' + [media[carouselCursor].filter_class?media[carouselCursor].filter_class:'']" :src="media[carouselCursor].url" :alt="media[carouselCursor].description" :title="media[carouselCursor].description">
  84. </div>
  85. <hr>
  86. <div v-if="ids.length > 0 && media[carouselCursor].type == 'Image'" class="align-items-center px-2 pt-2">
  87. <ul class="nav media-drawer-filters text-center">
  88. <li class="nav-item">
  89. <div class="p-1 pt-3">
  90. <img :src="media[carouselCursor].url" width="100px" height="60px" v-on:click.prevent="toggleFilter($event, null)" class="cursor-pointer">
  91. </div>
  92. <a :class="[media[carouselCursor].filter_class == null ? 'nav-link text-primary active' : 'nav-link text-muted']" href="#" v-on:click.prevent="toggleFilter($event, null)">No Filter</a>
  93. </li>
  94. <li class="nav-item" v-for="(filter, index) in filters">
  95. <div class="p-1 pt-3">
  96. <img :src="media[carouselCursor].url" width="100px" height="60px" :class="filter[1]" v-on:click.prevent="toggleFilter($event, filter[1])">
  97. </div>
  98. <a :class="[media[carouselCursor].filter_class == filter[1] ? 'nav-link text-primary active' : 'nav-link text-muted']" href="#" v-on:click.prevent="toggleFilter($event, filter[1])">{{filter[0]}}</a>
  99. </li>
  100. </ul>
  101. </div>
  102. </div>
  103. <div v-if="page == 3" class="w-100 h-100">
  104. <div class="border-bottom mt-2">
  105. <div class="media px-3">
  106. <img :src="media[0].url" width="42px" height="42px" :class="[media[0].filter_class?'mr-2 ' + media[0].filter_class:'mr-2']">
  107. <div class="media-body">
  108. <div class="form-group">
  109. <label class="font-weight-bold text-muted small d-none">Caption</label>
  110. <textarea class="form-control border-0 rounded-0 no-focus" rows="2" placeholder="Write a caption..." style="resize:none" v-model="composeText"></textarea>
  111. </div>
  112. </div>
  113. </div>
  114. </div>
  115. <div class="border-bottom">
  116. <p class="px-4 mb-0 py-2 cursor-pointer" @click="showTagCard()">Tag people</p>
  117. </div>
  118. <div class="border-bottom">
  119. <p class="px-4 mb-0 py-2 cursor-pointer" @click="showLocationCard()" v-if="!place">Add location</p>
  120. <p v-else class="px-4 mb-0 py-2">
  121. <span class="text-lighter">Location:</span> {{place.name}}, {{place.country}}
  122. <span class="float-right">
  123. <a href="#" @click.prevent="showLocationCard()" class="text-muted font-weight-bold small mr-2">Change</a>
  124. <a href="#" @click.prevent="place = false" class="text-muted font-weight-bold small">Remove</a>
  125. </span>
  126. </p>
  127. </div>
  128. <div class="border-bottom">
  129. <p class="px-4 mb-0 py-2">
  130. <span class="text-lighter">Visibility:</span> {{visibilityTag}}
  131. <span class="float-right">
  132. <a href="#" @click.prevent="showVisibilityCard()" class="text-muted font-weight-bold small mr-2">Change</a>
  133. </span>
  134. </p>
  135. </div>
  136. <div style="min-height: 200px;">
  137. <p class="px-4 mb-0 py-2 small font-weight-bold text-muted cursor-pointer" @click="showAdvancedSettingsCard()">Advanced settings</p>
  138. </div>
  139. </div>
  140. <div v-if="page == 'tagPeople'" class="w-100 h-100 p-3">
  141. <p class="text-center lead text-muted mb-0 py-5">This feature is not available yet.</p>
  142. </div>
  143. <div v-if="page == 'addLocation'" class="w-100 h-100 p-3">
  144. <p class="mb-0">Add Location</p>
  145. <autocomplete
  146. :search="locationSearch"
  147. placeholder="Search locations ..."
  148. aria-label="Search locations ..."
  149. :get-result-value="getResultValue"
  150. @submit="onSubmitLocation"
  151. >
  152. </autocomplete>
  153. </div>
  154. <div v-if="page == 'advancedSettings'" class="w-100 h-100">
  155. <div class="list-group list-group-flush">
  156. <div class="list-group-item d-flex justify-content-between">
  157. <div>
  158. <div class="text-dark ">Turn off commenting</div>
  159. <p class="text-muted small mb-0">Disables comments for this post, you can change this later.</p>
  160. </div>
  161. <div>
  162. <div class="custom-control custom-switch" style="z-index: 9999;">
  163. <input type="checkbox" class="custom-control-input" id="asdisablecomments" v-model="commentsDisabled">
  164. <label class="custom-control-label" for="asdisablecomments"></label>
  165. </div>
  166. </div>
  167. </div>
  168. <div class="list-group-item d-flex justify-content-between">
  169. <div>
  170. <div class="text-dark ">Contains NSFW Media</div>
  171. </div>
  172. <div>
  173. <div class="custom-control custom-switch" style="z-index: 9999;">
  174. <input type="checkbox" class="custom-control-input" id="asnsfw" v-model="nsfw">
  175. <label class="custom-control-label" for="asnsfw"></label>
  176. </div>
  177. </div>
  178. </div>
  179. <a href="#" class="list-group-item" @click.prevent="page = 'altText'">
  180. <div class="text-dark">Write alt text</div>
  181. <p class="text-muted small mb-0">Alt text describes your photos for people with visual impairments.</p>
  182. </a>
  183. <a href="#" class="list-group-item" @click.prevent="page = 'addToCollection'">
  184. <div class="text-dark">Add to Collection</div>
  185. <p class="text-muted small mb-0">Add this post to a collection.</p>
  186. </a>
  187. <a href="#" class="list-group-item" @click.prevent="page = 'schedulePost'">
  188. <div class="text-dark">Schedule</div>
  189. <p class="text-muted small mb-0">Schedule post for a future date.</p>
  190. </a>
  191. <a href="#" class="list-group-item" @click.prevent="page = 'mediaMetadata'">
  192. <div class="text-dark">Metadata</div>
  193. <p class="text-muted small mb-0">Manage media exif and metadata.</p>
  194. </a>
  195. </div>
  196. </div>
  197. <div v-if="page == 'visibility'" class="w-100 h-100">
  198. <div class="list-group list-group-flush">
  199. <div :class="'list-group-item lead cursor-pointer ' + [visibility == 'public'?'text-primary':'']" @click="toggleVisibility('public')">Public</div>
  200. <div :class="'list-group-item lead cursor-pointer ' + [visibility == 'unlisted'?'text-primary':'']" @click="toggleVisibility('unlisted')">Unlisted</div>
  201. <div :class="'list-group-item lead cursor-pointer ' + [visibility == 'private'?'text-primary':'']" @click="toggleVisibility('private')">Followers Only</div>
  202. </div>
  203. </div>
  204. <div v-if="page == 'altText'" class="w-100 h-100 p-3">
  205. <p class="text-center lead text-muted mb-0 py-5">This feature is not available yet.</p>
  206. </div>
  207. <div v-if="page == 'addToCollection'" class="w-100 h-100 p-3">
  208. <p class="text-center lead text-muted mb-0 py-5">This feature is not available yet.</p>
  209. </div>
  210. <div v-if="page == 'schedulePost'" class="w-100 h-100 p-3">
  211. <p class="text-center lead text-muted mb-0 py-5">This feature is not available yet.</p>
  212. </div>
  213. <div v-if="page == 'mediaMetadata'" class="w-100 h-100 p-3">
  214. <p class="text-center lead text-muted mb-0 py-5">This feature is not available yet.</p>
  215. </div>
  216. <div v-if="page == 'addToStory'" class="w-100 h-100 p-3">
  217. <p class="text-center lead text-muted mb-0 py-5">This feature is not available yet.</p>
  218. </div>
  219. </div>
  220. <!-- card-footers -->
  221. <div v-if="page == 'cropPhoto'" class="card-footer bg-white d-flex justify-content-between">
  222. <div>
  223. <button type="button" class="btn btn-outline-secondary" @click="rotate"><i class="fas fa-undo"></i></button>
  224. </div>
  225. <div>
  226. <div class="d-inline-block button-group">
  227. <button :class="'btn font-weight-bold ' + [cropper.aspectRatio == 16/9 ? 'btn-primary':'btn-light']" @click.prevent="changeAspect(16/9)">16:9</button>
  228. <button :class="'btn font-weight-bold ' + [cropper.aspectRatio == 4/3 ? 'btn-primary':'btn-light']" @click.prevent="changeAspect(4/3)">4:3</button>
  229. <button :class="'btn font-weight-bold ' + [cropper.aspectRatio == 3/2 ? 'btn-primary':'btn-light']" @click.prevent="changeAspect(3/2)">3:2</button>
  230. <button :class="'btn font-weight-bold ' + [cropper.aspectRatio == 1 ? 'btn-primary':'btn-light']" @click.prevent="changeAspect(1)">1:1</button>
  231. <button :class="'btn font-weight-bold ' + [cropper.aspectRatio == 2/3 ? 'btn-primary':'btn-light']" @click.prevent="changeAspect(2/3)">2:3</button>
  232. </div>
  233. </div>
  234. </div>
  235. </div>
  236. </div>
  237. </div>
  238. </div>
  239. </template>
  240. <style type="text/css" scoped>
  241. .media-drawer-filters {
  242. overflow-x: scroll;
  243. flex-wrap:unset;
  244. }
  245. .media-drawer-filters .nav-link {
  246. min-width:100px;
  247. padding-top: 1rem;
  248. padding-bottom: 1rem;
  249. }
  250. .media-drawer-filters .active {
  251. color: #fff;
  252. font-weight: bold;
  253. }
  254. @media (hover: none) and (pointer: coarse) {
  255. .media-drawer-filters::-webkit-scrollbar {
  256. display: none;
  257. }
  258. }
  259. .no-focus {
  260. border-color: none;
  261. outline: 0;
  262. box-shadow: none;
  263. }
  264. a.list-group-item {
  265. text-decoration: none;
  266. }
  267. a.list-group-item:hover {
  268. text-decoration: none;
  269. background-color: #f8f9fa !important;
  270. }
  271. </style>
  272. <script type="text/javascript">
  273. import VueCropper from 'vue-cropperjs';
  274. import 'cropperjs/dist/cropper.css';
  275. import Autocomplete from '@trevoreyre/autocomplete-vue'
  276. import '@trevoreyre/autocomplete-vue/dist/style.css'
  277. export default {
  278. components: {
  279. VueCropper,
  280. Autocomplete
  281. },
  282. data() {
  283. return {
  284. config: window.App.config,
  285. pageLoading: false,
  286. profile: {},
  287. composeText: '',
  288. composeTextLength: 0,
  289. nsfw: false,
  290. filters: [],
  291. ids: [],
  292. media: [],
  293. carouselCursor: 0,
  294. uploading: false,
  295. uploadProgress: 100,
  296. composeType: false,
  297. page: 1,
  298. composeState: 'publish',
  299. visibility: 'public',
  300. visibilityTag: 'Public',
  301. nsfw: false,
  302. place: false,
  303. commentsDisabled: false,
  304. pageTitle: '',
  305. cropper: {
  306. aspectRatio: 1,
  307. viewMode: 1,
  308. zoomable: true,
  309. zoom: 0
  310. },
  311. taggedUsernames: false,
  312. namedPages: [
  313. 'cropPhoto',
  314. 'tagPeople',
  315. 'addLocation',
  316. 'advancedSettings',
  317. 'visibility',
  318. 'altText',
  319. 'addToCollection',
  320. 'schedulePost',
  321. 'mediaMetadata',
  322. 'addToStory'
  323. ]
  324. }
  325. },
  326. beforeMount() {
  327. this.fetchProfile();
  328. if(this.config.uploader.media_types.includes('video/mp4') == false) {
  329. this.composeType = 'post'
  330. }
  331. },
  332. mounted() {
  333. this.mediaWatcher();
  334. this.filters = [
  335. ['1977','filter-1977'],
  336. ['Aden','filter-aden'],
  337. ['Amaro','filter-amaro'],
  338. ['Ashby','filter-ashby'],
  339. ['Brannan','filter-brannan'],
  340. ['Brooklyn','filter-brooklyn'],
  341. ['Charmes','filter-charmes'],
  342. ['Clarendon','filter-clarendon'],
  343. ['Crema','filter-crema'],
  344. ['Dogpatch','filter-dogpatch'],
  345. ['Earlybird','filter-earlybird'],
  346. ['Gingham','filter-gingham'],
  347. ['Ginza','filter-ginza'],
  348. ['Hefe','filter-hefe'],
  349. ['Helena','filter-helena'],
  350. ['Hudson','filter-hudson'],
  351. ['Inkwell','filter-inkwell'],
  352. ['Kelvin','filter-kelvin'],
  353. ['Kuno','filter-juno'],
  354. ['Lark','filter-lark'],
  355. ['Lo-Fi','filter-lofi'],
  356. ['Ludwig','filter-ludwig'],
  357. ['Maven','filter-maven'],
  358. ['Mayfair','filter-mayfair'],
  359. ['Moon','filter-moon'],
  360. ['Nashville','filter-nashville'],
  361. ['Perpetua','filter-perpetua'],
  362. ['Poprocket','filter-poprocket'],
  363. ['Reyes','filter-reyes'],
  364. ['Rise','filter-rise'],
  365. ['Sierra','filter-sierra'],
  366. ['Skyline','filter-skyline'],
  367. ['Slumber','filter-slumber'],
  368. ['Stinson','filter-stinson'],
  369. ['Sutro','filter-sutro'],
  370. ['Toaster','filter-toaster'],
  371. ['Valencia','filter-valencia'],
  372. ['Vesper','filter-vesper'],
  373. ['Walden','filter-walden'],
  374. ['Willow','filter-willow'],
  375. ['X-Pro II','filter-xpro-ii']
  376. ];
  377. },
  378. methods: {
  379. fetchProfile() {
  380. axios.get('/api/pixelfed/v1/accounts/verify_credentials').then(res => {
  381. this.profile = res.data;
  382. window.pixelfed.currentUser = res.data;
  383. if(res.data.locked == true) {
  384. this.visibility = 'private';
  385. }
  386. }).catch(err => {
  387. });
  388. },
  389. addMedia(event) {
  390. let el = $(event.target);
  391. el.attr('disabled', '');
  392. let fi = $('.file-input[name="media"]');
  393. fi.trigger('click');
  394. el.blur();
  395. el.removeAttr('disabled');
  396. },
  397. mediaWatcher() {
  398. let self = this;
  399. self.mediaDragAndDrop();
  400. $(document).on('change', '#pf-dz', function(e) {
  401. self.mediaUpload();
  402. });
  403. },
  404. mediaUpload() {
  405. let self = this;
  406. self.uploading = true;
  407. let io = document.querySelector('#pf-dz');
  408. Array.prototype.forEach.call(io.files, function(io, i) {
  409. if(self.media && self.media.length + i >= self.config.uploader.album_limit) {
  410. swal('Error', 'You can only upload ' + self.config.uploader.album_limit + ' photos per album', 'error');
  411. return;
  412. }
  413. let type = io.type;
  414. let acceptedMimes = self.config.uploader.media_types.split(',');
  415. let validated = $.inArray(type, acceptedMimes);
  416. if(validated == -1) {
  417. swal('Invalid File Type', 'The file you are trying to add is not a valid mime type. Please upload a '+self.config.uploader.media_types+' only.', 'error');
  418. return;
  419. }
  420. let form = new FormData();
  421. form.append('file', io);
  422. let xhrConfig = {
  423. onUploadProgress: function(e) {
  424. let progress = Math.round( (e.loaded * 100) / e.total );
  425. self.uploadProgress = progress;
  426. }
  427. };
  428. axios.post('/api/pixelfed/v1/media', form, xhrConfig)
  429. .then(function(e) {
  430. self.uploadProgress = 100;
  431. self.ids.push(e.data.id);
  432. self.media.push(e.data);
  433. self.page = 2;
  434. setTimeout(function() {
  435. self.uploading = false;
  436. }, 1000);
  437. }).catch(function(e) {
  438. self.uploading = false;
  439. io.value = null;
  440. swal('Oops, something went wrong!', 'An unexpected error occurred.', 'error');
  441. });
  442. io.value = null;
  443. self.uploadProgress = 0;
  444. });
  445. },
  446. mediaDragAndDrop() {
  447. let self = this;
  448. let pdz = document.getElementById('content');
  449. function allowDrag(e) {
  450. e.dataTransfer.dropEffect = 'copy';
  451. e.preventDefault();
  452. }
  453. function handleDrop(e) {
  454. e.preventDefault();
  455. let dz = document.querySelector('#pf-dz');
  456. dz.files = e.dataTransfer.files;
  457. $('#composeModal').modal('show');
  458. self.mediaUpload();
  459. }
  460. window.addEventListener('dragenter', function(e) {
  461. });
  462. pdz.addEventListener('dragenter', allowDrag);
  463. pdz.addEventListener('dragover', allowDrag);
  464. pdz.addEventListener('dragleave', function(e) {
  465. //
  466. });
  467. pdz.addEventListener('drop', handleDrop);
  468. },
  469. toggleFilter(e, filter) {
  470. this.media[this.carouselCursor].filter_class = filter;
  471. },
  472. updateMedia() {
  473. this.mediaDrawer = false;
  474. },
  475. deleteMedia() {
  476. if(window.confirm('Are you sure you want to delete this media?') == false) {
  477. return;
  478. }
  479. let id = this.media[this.carouselCursor].id;
  480. axios.delete('/api/pixelfed/v1/media', {
  481. params: {
  482. id: id
  483. }
  484. }).then(res => {
  485. if(this.media.length == 1) {
  486. this.mediaDrawer = false;
  487. this.ids = [];
  488. this.media = [];
  489. this.carouselCursor = 0;
  490. }
  491. this.ids.splice(this.carouselCursor, 1);
  492. this.media.splice(this.carouselCursor, 1);
  493. }).catch(err => {
  494. swal('Whoops!', 'An error occured when attempting to delete this, please try again', 'error');
  495. });
  496. },
  497. mediaAltText() {
  498. return;
  499. // deprecate
  500. swal({
  501. text: 'Add a media description',
  502. content: "input"
  503. }).then(val => {
  504. let media = this.media[this.carouselCursor];
  505. media.alt = val;
  506. });
  507. },
  508. mediaLicense() {
  509. return;
  510. // deprecate
  511. swal({
  512. text: 'Add a media license',
  513. content: "input",
  514. button: {
  515. text: "Update",
  516. closeModal: true,
  517. },
  518. }).then(val => {
  519. let media = this.media[this.carouselCursor];
  520. media.license = val;
  521. });
  522. },
  523. compose() {
  524. let state = this.composeState;
  525. if(this.uploadProgress != 100 || this.ids.length == 0) {
  526. return;
  527. }
  528. if(this.composeText.length > this.config.uploader.max_caption_length) {
  529. swal('Error', 'Caption is too long', 'error');
  530. return;
  531. }
  532. switch(state) {
  533. case 'publish' :
  534. if(this.media.length == 0) {
  535. swal('Whoops!', 'You need to add media before you can save this!', 'warning');
  536. return;
  537. }
  538. if(this.composeText == 'Add optional caption...') {
  539. this.composeText = '';
  540. }
  541. let data = {
  542. media: this.media,
  543. caption: this.composeText,
  544. visibility: this.visibility,
  545. cw: this.nsfw,
  546. comments_disabled: this.commentsDisabled,
  547. place: this.place
  548. };
  549. axios.post('/api/local/status/compose', data)
  550. .then(res => {
  551. let data = res.data;
  552. window.location.href = data;
  553. }).catch(err => {
  554. swal('Oops, something went wrong!', 'An unexpected error occurred.', 'error');
  555. });
  556. return;
  557. break;
  558. case 'delete' :
  559. this.mediaDrawer = false;
  560. this.ids = [];
  561. this.media = [];
  562. this.carouselCursor = 0;
  563. this.composeText = '';
  564. this.composeTextLength = 0;
  565. $('#composeModal').modal('hide');
  566. return;
  567. break;
  568. }
  569. },
  570. about() {
  571. let text = document.createElement('div');
  572. text.innerHTML = `
  573. <p class="small font-weight-bold">Please visit the <a href="/site/kb/sharing-media">Sharing Media</a> page for more info.</p>
  574. `;
  575. swal({
  576. title: 'Compose UI v3',
  577. content: text,
  578. icon: 'info'
  579. });
  580. },
  581. closeModal() {
  582. this.composeType = '';
  583. $('#composeModal').modal('hide');
  584. },
  585. composeMessage() {
  586. let config = this.config;
  587. let composeType = this.composeType;
  588. let video = config.uploader.media_types.includes('video/mp4');
  589. return video ?
  590. 'Click here to add photos or videos' :
  591. 'Click here to add photos';
  592. },
  593. createCollection() {
  594. window.location.href = '/i/collections/create';
  595. },
  596. nextPage() {
  597. this.pageTitle = '';
  598. switch(this.page) {
  599. case 1:
  600. this.page = 2;
  601. break;
  602. case 'cropPhoto':
  603. this.pageLoading = true;
  604. let self = this;
  605. this.$refs.cropper.getCroppedCanvas({
  606. maxWidth: 4096,
  607. maxHeight: 4096,
  608. fillColor: '#fff',
  609. imageSmoothingEnabled: false,
  610. imageSmoothingQuality: 'high',
  611. }).toBlob(function(blob) {
  612. let data = new FormData();
  613. data.append('file', blob);
  614. let url = '/api/local/compose/media/update/' + self.ids[self.carouselCursor];
  615. axios.post(url, data).then(res => {
  616. self.media[self.carouselCursor].url = res.data.url;
  617. self.pageLoading = false;
  618. self.page = 2;
  619. }).catch(err => {
  620. });
  621. });
  622. break;
  623. case 2:
  624. case 3:
  625. this.page++;
  626. break;
  627. }
  628. },
  629. rotate() {
  630. this.$refs.cropper.rotate(90);
  631. },
  632. changeAspect(ratio) {
  633. this.cropper.aspectRatio = ratio;
  634. this.$refs.cropper.setAspectRatio(ratio);
  635. },
  636. maxSize() {
  637. let limit = this.config.uploader.max_photo_size;
  638. return limit / 1000 + ' MB';
  639. },
  640. acceptedFormats() {
  641. let formats = this.config.uploader.media_types;
  642. return formats.split(',').map(f => {
  643. return ' ' + f.split('/')[1];
  644. }).toString();
  645. },
  646. showTagCard() {
  647. this.pageTitle = 'Tag People';
  648. this.page = 'tagPeople';
  649. },
  650. showLocationCard() {
  651. this.pageTitle = 'Add Location';
  652. this.page = 'addLocation';
  653. },
  654. showAdvancedSettingsCard() {
  655. this.pageTitle = 'Advanced Settings';
  656. this.page = 'advancedSettings';
  657. },
  658. locationSearch(input) {
  659. if (input.length < 1) { return []; };
  660. let results = [];
  661. return axios.get('/api/local/compose/location/search', {
  662. params: {
  663. q: input
  664. }
  665. }).then(res => {
  666. return res.data;
  667. });
  668. },
  669. getResultValue(result) {
  670. return result.name + ', ' + result.country
  671. },
  672. onSubmitLocation(result) {
  673. this.place = result;
  674. this.pageTitle = '';
  675. this.page = 3;
  676. return;
  677. },
  678. goBack() {
  679. this.pageTitle = '';
  680. switch(this.page) {
  681. case 'addToStory':
  682. this.page = 1;
  683. break;
  684. case 'cropPhoto':
  685. this.page = 2;
  686. break;
  687. default:
  688. this.namedPages.indexOf(this.page) != -1 ? this.page = 3 : this.page--;
  689. break;
  690. }
  691. },
  692. showVisibilityCard() {
  693. this.pageTitle = 'Post Visibility';
  694. this.page = 'visibility';
  695. },
  696. showAddToStoryCard() {
  697. this.pageTitle = 'Add to Story';
  698. this.page = 'addToStory';
  699. },
  700. showCropPhotoCard() {
  701. this.pageTitle = 'Edit Photo';
  702. this.page = 'cropPhoto';
  703. },
  704. toggleVisibility(state) {
  705. let tags = {
  706. public: 'Public',
  707. private: 'Followers Only',
  708. unlisted: 'Unlisted'
  709. }
  710. this.visibility = state;
  711. this.visibilityTag = tags[state];
  712. this.pageTitle = '';
  713. this.page = 3;
  714. }
  715. }
  716. }
  717. </script>