1
0

ComposeModal.vue 23 KB

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