ComposeModal.vue 33 KB

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