ComposeModal.vue 24 KB

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