1
0

ComposeModal.vue 33 KB

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