ComposeModal.vue 23 KB

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