ComposeModal.vue 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925
  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" multiple="">
  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-3" 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-if="page == 'cameraRoll'">
  14. <div class="card status-card card-md-rounded-0" style="display:flex;">
  15. <div class="card-header d-inline-flex align-items-center justify-content-between bg-white">
  16. <span class="pr-3">
  17. <i class="fas fa-cog fa-lg text-muted"></i>
  18. </span>
  19. <span class="font-weight-bold">
  20. Camera Roll
  21. </span>
  22. <span class="text-primary font-weight-bold">Upload</span>
  23. </div>
  24. <div class="h-100 card-body p-0 border-top" style="width:100%; min-height: 400px;">
  25. <div v-if="cameraRollMedia.length > 0" class="row p-0 m-0">
  26. <div v-for="(m, index) in cameraRollMedia" :class="[index == 0 ? 'col-12 p-0' : 'col-3 p-0']">
  27. <div class="card info-overlay p-0 rounded-0 shadow-none border">
  28. <div class="square">
  29. <img class="square-content" :src="m.preview_url"></img>
  30. </div>
  31. </div>
  32. </div>
  33. </div>
  34. <div v-else class="w-100 h-100 d-flex justify-content-center align-items-center">
  35. <span class="w-100 h-100">
  36. <button type="button" class="btn btn-primary">Upload</button>
  37. <button type="button" class="btn btn-primary" @click="fetchCameraRollDrafts()">Load Camera Roll</button>
  38. </span>
  39. </div>
  40. </div>
  41. </div>
  42. </div>
  43. <div v-else>
  44. <div class="card status-card card-md-rounded-0 w-100 h-100" style="display:flex;">
  45. <div class="card-header d-inline-flex align-items-center justify-content-between bg-white">
  46. <div>
  47. <a v-if="page == 1" href="#" @click.prevent="closeModal()" class="font-weight-bold text-decoration-none text-muted">
  48. <i class="fas fa-times fa-lg"></i>
  49. <span class="font-weight-bold mb-0">{{pageTitle}}</span>
  50. </a>
  51. <span v-else-if="page == 2">
  52. <button v-if="config.uploader.album_limit > media.length" class="btn btn-outline-primary btn-sm font-weight-bold" @click.prevent="addMedia" data-toggle="tooltip" data-placement="bottom" title="Upload another photo or video" ><i class="fas fa-plus"></i></button>
  53. <!-- <button v-if="config.uploader.album_limit > media.length" class="btn btn-outline-primary btn-sm font-weight-bold" @click.prevent="page = 'cameraRoll'" data-toggle="tooltip" data-placement="bottom" title="Upload another photo or video" ><i class="fas fa-chevron-left"></i> Camera Roll</button> -->
  54. <button v-else class="btn btn-outline-secondary btn-sm font-weight-bold" disabled><i class="fas fa-plus"></i></button>
  55. </span>
  56. <span v-else-if="page == 3">
  57. <a class="text-lighter text-decoration-none mr-3 d-flex align-items-center" href="#" @click.prevent="goBack()">
  58. <i class="fas fa-long-arrow-alt-left fa-lg mr-2"></i>
  59. <span class="btn btn-outline-secondary btn-sm px-2 py-0 disabled" disabled="">{{media.length}}</span>
  60. </a>
  61. <span class="font-weight-bold mb-0">{{pageTitle}}</span>
  62. </span>
  63. <span v-else>
  64. <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>
  65. </span>
  66. <span class="font-weight-bold mb-0">{{pageTitle}}</span>
  67. </div>
  68. <div v-if="page == 2">
  69. <a v-if="media.length == 1" href="#" class="text-center text-dark" @click.prevent="showCropPhotoCard"><i class="fas fa-magic fa-lg"></i></a>
  70. </div>
  71. <div>
  72. <!-- <a v-if="page > 1" class="font-weight-bold text-decoration-none" href="#" @click.prevent="page--">Back</a> -->
  73. <span v-if="pageLoading">
  74. <div class="spinner-border spinner-border-sm" role="status">
  75. <span class="sr-only">Loading...</span>
  76. </div>
  77. </span>
  78. <span v-else>
  79. <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>
  80. <a v-if="!pageLoading && page == 3" class="font-weight-bold text-decoration-none" href="#" @click.prevent="compose()">Post</a>
  81. </span>
  82. </div>
  83. </div>
  84. <div class="card-body p-0 border-top">
  85. <div v-if="page == 1" class="w-100 h-100 d-flex justify-content-center align-items-center" style="min-height: 400px;">
  86. <div class="text-center">
  87. <a class="card mx-md-5 my-md-3 shadow-none border compose-action text-decoration-none text-dark" href="/i/compose">
  88. <div class="card-body">
  89. <div class="media">
  90. <div class="mr-3 align-items-center justify-content-center" style="display:inline-flex;width:40px;height:40px;border-radius: 100%;background-color: #008DF5">
  91. <i class="far fa-image text-white fa-lg"></i>
  92. </div>
  93. <div class="media-body text-left">
  94. <h5 class="mt-0 font-weight-bold text-primary">New Post</h5>
  95. <p class="mb-0 text-muted">Share up to {{config.uploader.album_limit}} photos or videos.</p>
  96. </div>
  97. </div>
  98. </div>
  99. </a>
  100. <a class="d-none card mx-md-5 my-md-3 shadow-none border compose-action text-decoration-none text-dark" :click="showAddToStoryCard">
  101. <div class="card-body">
  102. <div class="media">
  103. <div class="mr-3 align-items-center justify-content-center" style="display:inline-flex;width:40px;height:40px;border-radius: 100%;background-color: #008DF5">
  104. <i class="fas fa-history text-white fa-lg"></i>
  105. </div>
  106. <div class="media-body text-left">
  107. <p class="mb-0">
  108. <span class="h5 mt-0 font-weight-bold text-primary">Add to Story</span>
  109. </p>
  110. <p class="mb-0 text-muted">Add a photo or video to your story.</p>
  111. </div>
  112. </div>
  113. </div>
  114. </a>
  115. <a class="card mx-md-5 my-md-3 shadow-none border compose-action text-decoration-none text-dark" href="/i/collections/create">
  116. <div class="card-body">
  117. <div class="media">
  118. <div class="mr-3 align-items-center justify-content-center" style="display:inline-flex;width:40px;height:40px;border-radius: 100%;background-color: #008DF5">
  119. <i class="fas fa-images text-white fa-lg"></i>
  120. </div>
  121. <div class="media-body text-left">
  122. <p class="mb-0">
  123. <span class="h5 mt-0 font-weight-bold text-primary">New Collection</span>
  124. </p>
  125. <p class="mb-0 text-muted">Create a curated collection of photos.</p>
  126. </div>
  127. </div>
  128. </div>
  129. </a>
  130. <div v-if="media.length == 0" class="card mx-md-5 my-md-3 shadow-none border compose-action text-decoration-none text-dark">
  131. <div @click.prevent="addMedia" class="card-body">
  132. <div class="media">
  133. <div class="mr-3 align-items-center justify-content-center" style="display:inline-flex;width:40px;height:40px;border-radius: 100%;background-color: #008DF5">
  134. <i class="fas fa-bolt text-white fa-lg"></i>
  135. </div>
  136. <div class="media-body text-left">
  137. <p class="mb-0">
  138. <span class="h5 mt-0 font-weight-bold text-primary">Try ComposeUI v4</span>
  139. <sup>
  140. <span class="badge badge-primary pb-1">BETA</span>
  141. </sup>
  142. </p>
  143. <p class="mb-0 text-muted">The next generation compose experience.</p>
  144. </div>
  145. </div>
  146. </div>
  147. </div>
  148. <p class="pt-3">
  149. <a class="font-weight-bold" href="/site/help">Help</a>
  150. </p>
  151. </div>
  152. </div>
  153. <div v-if="page == 'cropPhoto'" class="w-100 h-100">
  154. <div v-if="ids.length > 0">
  155. <vue-cropper
  156. ref="cropper"
  157. :relativeZoom="cropper.zoom"
  158. :aspectRatio="cropper.aspectRatio"
  159. :viewMode="cropper.viewMode"
  160. :zoomable="cropper.zoomable"
  161. :rotatable="true"
  162. :src="media[carouselCursor].url"
  163. >
  164. </vue-cropper>
  165. </div>
  166. </div>
  167. <div v-if="page == 2" class="w-100 h-100">
  168. <div v-if="media.length == 1">
  169. <div slot="img" style="display:flex;min-height: 420px;align-items: center;">
  170. <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">
  171. </div>
  172. <hr>
  173. <div v-if="ids.length > 0 && media[carouselCursor].type == 'Image'" class="align-items-center px-2 pt-2">
  174. <ul class="nav media-drawer-filters text-center">
  175. <li class="nav-item">
  176. <div class="p-1 pt-3">
  177. <img :src="media[carouselCursor].url" width="100px" height="60px" v-on:click.prevent="toggleFilter($event, null)" class="cursor-pointer">
  178. </div>
  179. <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>
  180. </li>
  181. <li class="nav-item" v-for="(filter, index) in filters">
  182. <div class="p-1 pt-3">
  183. <img :src="media[carouselCursor].url" width="100px" height="60px" :class="filter[1]" v-on:click.prevent="toggleFilter($event, filter[1])">
  184. </div>
  185. <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>
  186. </li>
  187. </ul>
  188. </div>
  189. </div>
  190. <div v-else-if="media.length > 1" class="d-flex-inline px-2 pt-2">
  191. <ul class="nav media-drawer-filters text-center">
  192. <li class="nav-item mx-md-4">&nbsp;</li>
  193. <li v-for="(m, i) in media" class="nav-item mx-md-4">
  194. <div class="nav-link" style="display:block;width:300px;height:300px;" @click="carouselCursor = i">
  195. <!-- <img :class="'d-block img-fluid w-100 ' + [m.filter_class?m.filter_class:'']" :src="m.url" :alt="m.description" :title="m.description"> -->
  196. <span :class="[m.filter_class?m.filter_class:'']">
  197. <span :class="'rounded border ' + [i == carouselCursor ? ' border-primary shadow':'']" :style="'display:block;padding:5px;width:100%;height:100%;background-image: url(' + m.url + ');background-size:cover;border-width:3px !important;'"></span>
  198. </span>
  199. </div>
  200. <div v-if="i == carouselCursor" class="text-center mb-0 small text-lighter font-weight-bold pt-2">
  201. <span class="cursor-pointer" @click.prevent="showCropPhotoCard">Crop</span>
  202. <span class="cursor-pointer px-3" @click.prevent="showEditMediaCard()">Edit</span>
  203. <span class="cursor-pointer" @click="deleteMedia()">Delete</span>
  204. </div>
  205. </li>
  206. <li class="nav-item mx-md-4">&nbsp;</li>
  207. </ul>
  208. <hr>
  209. <div v-if="ids.length > 0 && media[carouselCursor].type == 'Image'" class="align-items-center px-2 pt-2">
  210. <ul class="nav media-drawer-filters text-center">
  211. <li class="nav-item">
  212. <div class="p-1 pt-3">
  213. <img :src="media[carouselCursor].url" width="100px" height="60px" v-on:click.prevent="toggleFilter($event, null)" class="cursor-pointer">
  214. </div>
  215. <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>
  216. </li>
  217. <li class="nav-item" v-for="(filter, index) in filters">
  218. <div class="p-1 pt-3">
  219. <img :src="media[carouselCursor].url" width="100px" height="60px" :class="filter[1]" v-on:click.prevent="toggleFilter($event, filter[1])">
  220. </div>
  221. <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>
  222. </li>
  223. </ul>
  224. </div>
  225. </div>
  226. <div v-else>
  227. <p class="mb-0 p-5 text-center font-weight-bold">An error occured, please refresh the page.</p>
  228. </div>
  229. </div>
  230. <div v-if="page == 3" class="w-100 h-100">
  231. <div class="border-bottom mt-2">
  232. <div class="media px-3">
  233. <img :src="media[0].url" width="42px" height="42px" :class="[media[0].filter_class?'mr-2 ' + media[0].filter_class:'mr-2']">
  234. <div class="media-body">
  235. <div class="form-group">
  236. <label class="font-weight-bold text-muted small d-none">Caption</label>
  237. <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>
  238. <p class="help-text small text-right text-muted mb-0">{{composeTextLength}}/{{config.uploader.max_caption_length}}</p>
  239. </div>
  240. </div>
  241. </div>
  242. </div>
  243. <div class="border-bottom d-flex justify-content-between px-4 mb-0 py-2 ">
  244. <div>
  245. <div class="text-dark ">Contains NSFW Media</div>
  246. </div>
  247. <div>
  248. <div class="custom-control custom-switch" style="z-index: 9999;">
  249. <input type="checkbox" class="custom-control-input" id="asnsfw" v-model="nsfw">
  250. <label class="custom-control-label" for="asnsfw"></label>
  251. </div>
  252. </div>
  253. </div>
  254. <!-- <div class="border-bottom">
  255. <p class="px-4 mb-0 py-2 cursor-pointer" @click="showTagCard()">Tag people</p>
  256. </div> -->
  257. <div class="border-bottom">
  258. <p class="px-4 mb-0 py-2 cursor-pointer" @click="showLocationCard()" v-if="!place">Add location</p>
  259. <p v-else class="px-4 mb-0 py-2">
  260. <span class="text-lighter">Location:</span> {{place.name}}, {{place.country}}
  261. <span class="float-right">
  262. <a href="#" @click.prevent="showLocationCard()" class="btn btn-outline-secondary btn-sm small mr-2" style="font-size:10px;padding:3px;text-transform: uppercase">Edit</a>
  263. <a href="#" @click.prevent="place = false" class="btn btn-outline-secondary btn-sm small" style="font-size:10px;padding:3px;text-transform: uppercase">Remove</a>
  264. </span>
  265. </p>
  266. </div>
  267. <div class="border-bottom">
  268. <p class="px-4 mb-0 py-2">
  269. <span class="text-lighter">Visibility:</span> {{visibilityTag}}
  270. <span class="float-right">
  271. <a v-if="profile.locked == false" href="#" @click.prevent="showVisibilityCard()" class="btn btn-outline-secondary btn-sm small mr-2" style="font-size:10px;padding:3px;text-transform: uppercase">Edit</a>
  272. </span>
  273. </p>
  274. </div>
  275. <!-- <div class="cursor-pointer border-bottom px-4 mb-0 py-2" @click.prevent="showMediaDescriptionsCard()">
  276. <div class="d-flex justify-content-between align-items-center">
  277. <div>
  278. <div class="text-dark">Media Descriptions</div>
  279. <p class="text-muted small mb-0">Describe your photos for people with visual impairments.</p>
  280. </div>
  281. <div>
  282. <i class="fas fa-chevron-right fa-lg text-lighter"></i>
  283. </div>
  284. </div>
  285. </div> -->
  286. <div style="min-height: 200px;">
  287. <p class="px-4 mb-0 py-2 small font-weight-bold text-muted cursor-pointer" @click="showAdvancedSettingsCard()">Advanced settings</p>
  288. </div>
  289. </div>
  290. <div v-if="page == 'tagPeople'" class="w-100 h-100 p-3">
  291. <p class="text-center lead text-muted mb-0 py-5">This feature is not available yet.</p>
  292. </div>
  293. <div v-if="page == 'addLocation'" class="w-100 h-100 p-3">
  294. <p class="mb-0">Add Location</p>
  295. <autocomplete
  296. :search="locationSearch"
  297. placeholder="Search locations ..."
  298. aria-label="Search locations ..."
  299. :get-result-value="getResultValue"
  300. @submit="onSubmitLocation"
  301. >
  302. </autocomplete>
  303. </div>
  304. <div v-if="page == 'advancedSettings'" class="w-100 h-100">
  305. <div class="list-group list-group-flush">
  306. <div class="list-group-item d-flex justify-content-between">
  307. <div>
  308. <div class="text-dark ">Turn off commenting</div>
  309. <p class="text-muted small mb-0">Disables comments for this post, you can change this later.</p>
  310. </div>
  311. <div>
  312. <div class="custom-control custom-switch" style="z-index: 9999;">
  313. <input type="checkbox" class="custom-control-input" id="asdisablecomments" v-model="commentsDisabled">
  314. <label class="custom-control-label" for="asdisablecomments"></label>
  315. </div>
  316. </div>
  317. </div>
  318. <a href="#" class="list-group-item" @click.prevent="showMediaDescriptionsCard()">
  319. <div class="d-flex justify-content-between align-items-center">
  320. <div>
  321. <div class="text-dark">Media Descriptions</div>
  322. <p class="text-muted small mb-0">Describe your photos for people with visual impairments.</p>
  323. </div>
  324. <div>
  325. <i class="fas fa-chevron-right fa-lg text-lighter"></i>
  326. </div>
  327. </div>
  328. </a>
  329. <!-- <a href="#" class="list-group-item" @click.prevent="showAddToCollectionsCard()">
  330. <div class="d-flex justify-content-between align-items-center">
  331. <div>
  332. <div class="text-dark">Add to Collection</div>
  333. <p class="text-muted small mb-0">Add this post to a collection.</p>
  334. </div>
  335. <div>
  336. <i class="fas fa-chevron-right fa-lg text-lighter"></i>
  337. </div>
  338. </div>
  339. </a>
  340. <a href="#" class="list-group-item" @click.prevent="page = 'schedulePost'">
  341. <div class="d-flex justify-content-between align-items-center">
  342. <div>
  343. <div class="text-dark">Schedule</div>
  344. <p class="text-muted small mb-0">Schedule post for a future date.</p>
  345. </div>
  346. <div>
  347. <i class="fas fa-chevron-right fa-lg text-lighter"></i>
  348. </div>
  349. </div>
  350. </a>
  351. <a href="#" class="list-group-item" @click.prevent="page = 'mediaMetadata'">
  352. <div class="d-flex justify-content-between align-items-center">
  353. <div>
  354. <div class="text-dark">Metadata</div>
  355. <p class="text-muted small mb-0">Manage media exif and metadata.</p>
  356. </div>
  357. <div>
  358. <i class="fas fa-chevron-right fa-lg text-lighter"></i>
  359. </div>
  360. </div>
  361. </a> -->
  362. </div>
  363. </div>
  364. <div v-if="page == 'visibility'" class="w-100 h-100">
  365. <div class="list-group list-group-flush">
  366. <div :class="'list-group-item lead cursor-pointer ' + [visibility == 'public'?'text-primary':'']" @click="toggleVisibility('public')">Public</div>
  367. <div :class="'list-group-item lead cursor-pointer ' + [visibility == 'unlisted'?'text-primary':'']" @click="toggleVisibility('unlisted')">Unlisted</div>
  368. <div :class="'list-group-item lead cursor-pointer ' + [visibility == 'private'?'text-primary':'']" @click="toggleVisibility('private')">Followers Only</div>
  369. </div>
  370. </div>
  371. <div v-if="page == 'altText'" class="w-100 h-100 p-3">
  372. <div v-for="(m, index) in media">
  373. <div class="media">
  374. <img :src="m.preview_url" class="mr-3" width="50px" height="50px">
  375. <div class="media-body">
  376. <textarea class="form-control" v-model="m.alt" placeholder="Add a media description here..."></textarea>
  377. <p class="help-text small text-right text-muted mb-0">{{m.alt ? m.alt.length : 0}}/140</p>
  378. </div>
  379. </div>
  380. <hr>
  381. </div>
  382. <p class="d-flex justify-content-between mb-0">
  383. <button type="button" @click="goBack()" class="btn btn-link text-muted font-weight-bold text-decoration-none">Cancel</button>
  384. <button type="button" @click="goBack()" class="btn btn-primary font-weight-bold">Save</button>
  385. </p>
  386. </div>
  387. <div v-if="page == 'addToCollection'" class="w-100 h-100 p-3">
  388. <div class="list-group mb-3">
  389. <div class="list-group-item cursor-pointer compose-action border" @click="goBack()">
  390. <div class="media">
  391. <img src="" class="mr-3" alt="" width="50px" height="50px">
  392. <div class="media-body">
  393. <h5 class="mt-0">collection title</h5>
  394. <p class="mb-0 text-muted small">3 Photos - Created 2h ago</p>
  395. </div>
  396. </div>
  397. </div>
  398. </div>
  399. <p class="d-flex justify-content-between mb-0">
  400. <button type="button" @click="goBack()" class="btn btn-link text-muted font-weight-bold text-decoration-none">Cancel</button>
  401. <button type="button" @click="goBack()" class="btn btn-primary font-weight-bold">Save</button>
  402. </p>
  403. </div>
  404. <div v-if="page == 'schedulePost'" class="w-100 h-100 p-3">
  405. <p class="text-center lead text-muted mb-0 py-5">This feature is not available yet.</p>
  406. </div>
  407. <div v-if="page == 'mediaMetadata'" class="w-100 h-100 p-3">
  408. <p class="text-center lead text-muted mb-0 py-5">This feature is not available yet.</p>
  409. </div>
  410. <div v-if="page == 'addToStory'" class="w-100 h-100 p-3">
  411. <p class="text-center lead text-muted mb-0 py-5">This feature is not available yet.</p>
  412. </div>
  413. <div v-if="page == 'editMedia'" class="w-100 h-100 p-3">
  414. <div class="media">
  415. <img :src="media[carouselCursor].preview_url" class="mr-3" width="50px" height="50px">
  416. <div class="media-body">
  417. <div class="form-group">
  418. <label class="font-weight-bold text-muted small">Media Description</label>
  419. <textarea class="form-control" v-model="media[carouselCursor].alt" placeholder="Add a media description here..."></textarea>
  420. <p class="help-text small text-muted mb-0 d-flex justify-content-between">
  421. <span>Describe your photo for people with visual impairments.</span>
  422. <span>{{media[carouselCursor].alt ? media[carouselCursor].alt.length : 0}}/140</span>
  423. </p>
  424. </div>
  425. <div class="form-group">
  426. <label class="font-weight-bold text-muted small">License</label>
  427. <input type="text" class="form-control" v-model="media[carouselCursor].license" placeholder="All Rights Reserved (Default license)">
  428. <p class="help-text small text-muted mb-0 d-flex justify-content-between">
  429. <span></span>
  430. <span>{{media[carouselCursor].license ? media[carouselCursor].license.length : 0}}/140</span>
  431. </p>
  432. </div>
  433. </div>
  434. </div>
  435. <hr>
  436. <p class="d-flex justify-content-between mb-0">
  437. <button type="button" @click="goBack()" class="btn btn-link text-muted font-weight-bold text-decoration-none">Cancel</button>
  438. <button type="button" @click="goBack()" class="btn btn-primary font-weight-bold">Save</button>
  439. </p>
  440. </div>
  441. </div>
  442. <!-- card-footers -->
  443. <div v-if="page == 'cropPhoto'" class="card-footer bg-white d-flex justify-content-between">
  444. <div>
  445. <button type="button" class="btn btn-outline-secondary" @click="rotate"><i class="fas fa-undo"></i></button>
  446. </div>
  447. <div>
  448. <div class="d-inline-block button-group">
  449. <button :class="'btn font-weight-bold ' + [cropper.aspectRatio == 16/9 ? 'btn-primary':'btn-light']" @click.prevent="changeAspect(16/9)">16:9</button>
  450. <button :class="'btn font-weight-bold ' + [cropper.aspectRatio == 4/3 ? 'btn-primary':'btn-light']" @click.prevent="changeAspect(4/3)">4:3</button>
  451. <button :class="'btn font-weight-bold ' + [cropper.aspectRatio == 3/2 ? 'btn-primary':'btn-light']" @click.prevent="changeAspect(3/2)">3:2</button>
  452. <button :class="'btn font-weight-bold ' + [cropper.aspectRatio == 1 ? 'btn-primary':'btn-light']" @click.prevent="changeAspect(1)">1:1</button>
  453. <button :class="'btn font-weight-bold ' + [cropper.aspectRatio == 2/3 ? 'btn-primary':'btn-light']" @click.prevent="changeAspect(2/3)">2:3</button>
  454. </div>
  455. </div>
  456. </div>
  457. </div>
  458. </div>
  459. </div>
  460. </div>
  461. </template>
  462. <style type="text/css" scoped>
  463. .media-drawer-filters {
  464. overflow-x: scroll;
  465. flex-wrap:unset;
  466. }
  467. .media-drawer-filters::-webkit-scrollbar {
  468. width: 0px;
  469. background: transparent;
  470. }
  471. .media-drawer-filters .nav-link {
  472. min-width:100px;
  473. padding-top: 1rem;
  474. padding-bottom: 1rem;
  475. }
  476. .media-drawer-filters .active {
  477. color: #fff;
  478. font-weight: bold;
  479. }
  480. @media (hover: none) and (pointer: coarse) {
  481. .media-drawer-filters::-webkit-scrollbar {
  482. display: none;
  483. }
  484. }
  485. .no-focus {
  486. border-color: none;
  487. outline: 0;
  488. box-shadow: none;
  489. }
  490. a.list-group-item {
  491. text-decoration: none;
  492. }
  493. a.list-group-item:hover {
  494. text-decoration: none;
  495. background-color: #f8f9fa !important;
  496. }
  497. .compose-action:hover {
  498. cursor: pointer;
  499. background-color: #f8f9fa !important;
  500. }
  501. </style>
  502. <script type="text/javascript">
  503. import VueCropper from 'vue-cropperjs';
  504. import 'cropperjs/dist/cropper.css';
  505. import Autocomplete from '@trevoreyre/autocomplete-vue'
  506. import '@trevoreyre/autocomplete-vue/dist/style.css'
  507. export default {
  508. components: {
  509. VueCropper,
  510. Autocomplete
  511. },
  512. data() {
  513. return {
  514. config: window.App.config,
  515. pageLoading: false,
  516. profile: {},
  517. composeText: '',
  518. composeTextLength: 0,
  519. nsfw: false,
  520. filters: [],
  521. ids: [],
  522. media: [],
  523. carouselCursor: 0,
  524. uploading: false,
  525. uploadProgress: 100,
  526. composeType: false,
  527. page: 1,
  528. composeState: 'publish',
  529. visibility: 'public',
  530. visibilityTag: 'Public',
  531. nsfw: false,
  532. place: false,
  533. commentsDisabled: false,
  534. pageTitle: '',
  535. cropper: {
  536. aspectRatio: 1,
  537. viewMode: 1,
  538. zoomable: true,
  539. zoom: 0
  540. },
  541. taggedUsernames: false,
  542. namedPages: [
  543. 'cropPhoto',
  544. 'tagPeople',
  545. 'addLocation',
  546. 'advancedSettings',
  547. 'visibility',
  548. 'altText',
  549. 'addToCollection',
  550. 'schedulePost',
  551. 'mediaMetadata',
  552. 'addToStory',
  553. 'editMedia',
  554. 'cameraRoll'
  555. ],
  556. cameraRollMedia: []
  557. }
  558. },
  559. beforeMount() {
  560. this.fetchProfile();
  561. if(this.config.uploader.media_types.includes('video/mp4') == false) {
  562. this.composeType = 'post'
  563. }
  564. this.filters = window.App.util.filters;
  565. },
  566. mounted() {
  567. this.mediaWatcher();
  568. },
  569. updated() {
  570. if(this.page == 2) {
  571. $('[data-toggle="tooltip"]').tooltip();
  572. }
  573. },
  574. methods: {
  575. fetchProfile() {
  576. axios.get('/api/pixelfed/v1/accounts/verify_credentials').then(res => {
  577. this.profile = res.data;
  578. window.pixelfed.currentUser = res.data;
  579. if(res.data.locked == true) {
  580. this.visibility = 'private';
  581. this.visibilityTag = 'Followers Only';
  582. }
  583. }).catch(err => {
  584. });
  585. },
  586. addMedia(event) {
  587. let el = $(event.target);
  588. el.attr('disabled', '');
  589. let fi = $('.file-input[name="media"]');
  590. fi.trigger('click');
  591. el.blur();
  592. el.removeAttr('disabled');
  593. },
  594. mediaWatcher() {
  595. let self = this;
  596. $(document).on('change', '#pf-dz', function(e) {
  597. self.mediaUpload();
  598. });
  599. },
  600. mediaUpload() {
  601. let self = this;
  602. self.uploading = true;
  603. let io = document.querySelector('#pf-dz');
  604. Array.prototype.forEach.call(io.files, function(io, i) {
  605. if(self.media && self.media.length + i >= self.config.uploader.album_limit) {
  606. swal('Error', 'You can only upload ' + self.config.uploader.album_limit + ' photos per album', 'error');
  607. self.uploading = false;
  608. self.page = 2;
  609. return;
  610. }
  611. let type = io.type;
  612. let acceptedMimes = self.config.uploader.media_types.split(',');
  613. let validated = $.inArray(type, acceptedMimes);
  614. if(validated == -1) {
  615. 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');
  616. self.uploading = false;
  617. self.page = 2;
  618. return;
  619. }
  620. let form = new FormData();
  621. form.append('file', io);
  622. let xhrConfig = {
  623. onUploadProgress: function(e) {
  624. let progress = Math.round( (e.loaded * 100) / e.total );
  625. self.uploadProgress = progress;
  626. }
  627. };
  628. axios.post('/api/pixelfed/v1/media', form, xhrConfig)
  629. .then(function(e) {
  630. self.uploadProgress = 100;
  631. self.ids.push(e.data.id);
  632. self.media.push(e.data);
  633. self.uploading = false;
  634. setTimeout(function() {
  635. self.page = 2;
  636. }, 300);
  637. }).catch(function(e) {
  638. self.uploading = false;
  639. io.value = null;
  640. swal('Oops, something went wrong!', 'An unexpected error occurred.', 'error');
  641. self.page = 2;
  642. });
  643. io.value = null;
  644. self.uploadProgress = 0;
  645. });
  646. },
  647. toggleFilter(e, filter) {
  648. this.media[this.carouselCursor].filter_class = filter;
  649. },
  650. deleteMedia() {
  651. if(window.confirm('Are you sure you want to delete this media?') == false) {
  652. return;
  653. }
  654. let id = this.media[this.carouselCursor].id;
  655. axios.delete('/api/pixelfed/v1/media', {
  656. params: {
  657. id: id
  658. }
  659. }).then(res => {
  660. this.ids.splice(this.carouselCursor, 1);
  661. this.media.splice(this.carouselCursor, 1);
  662. if(this.media.length == 0) {
  663. this.ids = [];
  664. this.media = [];
  665. this.carouselCursor = 0;
  666. } else {
  667. this.carouselCursor = 0;
  668. }
  669. }).catch(err => {
  670. swal('Whoops!', 'An error occured when attempting to delete this, please try again', 'error');
  671. });
  672. },
  673. compose() {
  674. let state = this.composeState;
  675. if(this.uploadProgress != 100 || this.ids.length == 0) {
  676. return;
  677. }
  678. if(this.composeText.length > this.config.uploader.max_caption_length) {
  679. swal('Error', 'Caption is too long', 'error');
  680. return;
  681. }
  682. switch(state) {
  683. case 'publish' :
  684. if(this.media.length == 0) {
  685. swal('Whoops!', 'You need to add media before you can save this!', 'warning');
  686. return;
  687. }
  688. if(this.composeText == 'Add optional caption...') {
  689. this.composeText = '';
  690. }
  691. let data = {
  692. media: this.media,
  693. caption: this.composeText,
  694. visibility: this.visibility,
  695. cw: this.nsfw,
  696. comments_disabled: this.commentsDisabled,
  697. place: this.place
  698. };
  699. axios.post('/api/local/status/compose', data)
  700. .then(res => {
  701. let data = res.data;
  702. window.location.href = data;
  703. }).catch(err => {
  704. let msg = err.response.data.message ? err.response.data.message : 'An unexpected error occured.'
  705. swal('Oops, something went wrong!', msg, 'error');
  706. });
  707. return;
  708. break;
  709. case 'delete' :
  710. this.ids = [];
  711. this.media = [];
  712. this.carouselCursor = 0;
  713. this.composeText = '';
  714. this.composeTextLength = 0;
  715. $('#composeModal').modal('hide');
  716. return;
  717. break;
  718. }
  719. },
  720. closeModal() {
  721. this.composeType = '';
  722. $('#composeModal').modal('hide');
  723. },
  724. goBack() {
  725. this.pageTitle = '';
  726. switch(this.page) {
  727. case 'cropPhoto':
  728. case 'editMedia':
  729. this.page = 2;
  730. break;
  731. default:
  732. this.namedPages.indexOf(this.page) != -1 ? this.page = 3 : this.page--;
  733. break;
  734. }
  735. },
  736. nextPage() {
  737. this.pageTitle = '';
  738. switch(this.page) {
  739. case 1:
  740. this.page = 2;
  741. break;
  742. case 'cropPhoto':
  743. this.pageLoading = true;
  744. let self = this;
  745. this.$refs.cropper.getCroppedCanvas({
  746. maxWidth: 4096,
  747. maxHeight: 4096,
  748. fillColor: '#fff',
  749. imageSmoothingEnabled: false,
  750. imageSmoothingQuality: 'high',
  751. }).toBlob(function(blob) {
  752. let data = new FormData();
  753. data.append('file', blob);
  754. let url = '/api/local/compose/media/update/' + self.ids[self.carouselCursor];
  755. axios.post(url, data).then(res => {
  756. self.media[self.carouselCursor].url = res.data.url;
  757. self.pageLoading = false;
  758. self.page = 2;
  759. }).catch(err => {
  760. });
  761. });
  762. break;
  763. case 2:
  764. case 3:
  765. this.page++;
  766. break;
  767. }
  768. },
  769. rotate() {
  770. this.$refs.cropper.rotate(90);
  771. },
  772. changeAspect(ratio) {
  773. this.cropper.aspectRatio = ratio;
  774. this.$refs.cropper.setAspectRatio(ratio);
  775. },
  776. showTagCard() {
  777. this.pageTitle = 'Tag People';
  778. this.page = 'tagPeople';
  779. },
  780. showLocationCard() {
  781. this.pageTitle = 'Add Location';
  782. this.page = 'addLocation';
  783. },
  784. showAdvancedSettingsCard() {
  785. this.pageTitle = 'Advanced Settings';
  786. this.page = 'advancedSettings';
  787. },
  788. locationSearch(input) {
  789. if (input.length < 1) { return []; };
  790. let results = [];
  791. return axios.get('/api/local/compose/location/search', {
  792. params: {
  793. q: input
  794. }
  795. }).then(res => {
  796. return res.data;
  797. });
  798. },
  799. getResultValue(result) {
  800. return result.name + ', ' + result.country
  801. },
  802. onSubmitLocation(result) {
  803. this.place = result;
  804. this.pageTitle = '';
  805. this.page = 3;
  806. return;
  807. },
  808. showVisibilityCard() {
  809. this.pageTitle = 'Post Visibility';
  810. this.page = 'visibility';
  811. },
  812. showAddToStoryCard() {
  813. this.pageTitle = 'Add to Story';
  814. this.page = 'addToStory';
  815. },
  816. showCropPhotoCard() {
  817. this.pageTitle = 'Edit Photo';
  818. this.page = 'cropPhoto';
  819. },
  820. toggleVisibility(state) {
  821. let tags = {
  822. public: 'Public',
  823. private: 'Followers Only',
  824. unlisted: 'Unlisted'
  825. }
  826. this.visibility = state;
  827. this.visibilityTag = tags[state];
  828. this.pageTitle = '';
  829. this.page = 3;
  830. },
  831. showMediaDescriptionsCard() {
  832. this.pageTitle = 'Media Descriptions';
  833. this.page = 'altText';
  834. },
  835. showAddToCollectionsCard() {
  836. this.pageTitle = 'Add to Collection';
  837. this.page = 'addToCollection';
  838. },
  839. showSchedulePostCard() {
  840. this.pageTitle = 'Schedule Post';
  841. this.page = 'schedulePost';
  842. },
  843. showEditMediaCard() {
  844. this.pageTitle = 'Edit Media';
  845. this.page = 'editMedia';
  846. },
  847. fetchCameraRollDrafts() {
  848. axios.get('/api/pixelfed/local/drafts')
  849. .then(res => {
  850. this.cameraRollMedia = res.data;
  851. });
  852. },
  853. }
  854. }
  855. </script>