gallery.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615
  1. var GAL = function(config) {
  2. config = config || {};
  3. GAL.superclass.constructor.call(this,config);
  4. };
  5. Ext.extend(GAL,Ext.Component,{
  6. page:{},window:{},grid:{},tree:{},panel:{},combo:{},config: {},view: {}
  7. });
  8. Ext.reg('gallery',GAL);
  9. GAL = new GAL();
  10. GAL.window.CreateAlbum = function(config) {
  11. config = config || {};
  12. this.ident = config.ident || 'gcalb'+Ext.id();
  13. Ext.applyIf(config,{
  14. title: _('gallery.album_create')
  15. ,id: this.ident
  16. // ,height: 150
  17. ,width: 600
  18. ,url: GAL.config.connector_url
  19. ,action: 'mgr/album/create'
  20. ,fields: [{
  21. xtype: 'hidden'
  22. ,name: 'parent'
  23. },{
  24. layout: 'column'
  25. ,border: false
  26. ,defaults: {
  27. layout: 'form'
  28. ,labelAlign: 'top'
  29. ,anchor: '100%'
  30. ,border: false
  31. ,labelSeparator: ''
  32. }
  33. ,items: [{
  34. columnWidth: .5
  35. ,items: [{
  36. xtype: config.record['parent'] == 0 ? 'hidden' : 'statictextfield'
  37. ,fieldLabel: _('gallery.parent')
  38. ,name: 'parent_name'
  39. ,id: this.ident+'-parent-name'
  40. ,anchor: '100%'
  41. },{
  42. xtype: 'textfield'
  43. ,fieldLabel: _('name')
  44. ,name: 'name'
  45. ,id: this.ident+'-name'
  46. ,anchor: '100%'
  47. },{
  48. xtype: 'textarea'
  49. ,fieldLabel: _('description')
  50. ,name: 'description'
  51. ,id: this.ident+'-description'
  52. ,anchor: '100%'
  53. }]
  54. },{
  55. columnWidth: .5
  56. ,items: [{
  57. xtype: 'textfield'
  58. ,fieldLabel: _('gallery.year')
  59. ,name: 'year'
  60. ,anchor: '100%'
  61. ,allowBlank: true
  62. },{
  63. xtype: 'checkbox'
  64. ,boxLabel: _('gallery.active')
  65. ,description: MODx.expandHelp ? '' : _('gallery.active_desc')
  66. ,name: 'active'
  67. ,id: this.ident+'-active'
  68. ,hideLabel: true
  69. ,checked: true
  70. ,inputValue: 1
  71. },{
  72. xtype: MODx.expandHelp ? 'label' : 'hidden'
  73. ,forId: this.ident+'-active'
  74. ,text: _('gallery.active_desc')
  75. ,cls: 'desc-under'
  76. },{
  77. xtype: 'checkbox'
  78. ,boxLabel: _('gallery.prominent')
  79. ,description: MODx.expandHelp ? '' : _('gallery.prominent_desc')
  80. ,name: 'prominent'
  81. ,id: this.ident+'-prominent'
  82. ,hideLabel: true
  83. ,checked: true
  84. ,inputValue: 1
  85. },{
  86. xtype: MODx.expandHelp ? 'label' : 'hidden'
  87. ,forId: this.ident+'-prominent'
  88. ,text: _('gallery.prominent_desc')
  89. ,cls: 'desc-under'
  90. }]
  91. }]
  92. }]
  93. });
  94. GAL.window.CreateAlbum.superclass.constructor.call(this,config);
  95. };
  96. Ext.extend(GAL.window.CreateAlbum,MODx.Window);
  97. Ext.reg('gal-window-album-create',GAL.window.CreateAlbum);
  98. GAL.window.UpdateItem = function(config) {
  99. config = config || {};
  100. this.ident = config.ident || 'gupdit'+Ext.id();
  101. Ext.applyIf(config,{
  102. title: _('gallery.item_update')
  103. ,id: this.ident
  104. ,closeAction: 'close'
  105. // ,height: 150
  106. // ,width: '55%'
  107. ,width: 600
  108. ,url: GAL.config.connector_url
  109. ,action: 'mgr/item/update'
  110. ,fileUpload: true
  111. ,fields: [{
  112. layout: 'column'
  113. ,border: false
  114. ,defaults: {
  115. layout: 'form'
  116. ,labelAlign: 'top'
  117. ,anchor: '100%'
  118. ,border: false
  119. ,labelSeparator: ''
  120. }
  121. ,items: [{
  122. columnWidth: .5
  123. ,items: [{
  124. xtype: 'textfield'
  125. ,fieldLabel: _('name')
  126. ,name: 'name'
  127. ,id: this.ident+'-name'
  128. ,anchor: '100%'
  129. },{
  130. xtype: 'textarea'
  131. ,fieldLabel: _('description')
  132. ,name: 'description'
  133. ,id: this.ident+'-description'
  134. ,anchor: '100%'
  135. },{
  136. xtype: 'textfield'
  137. ,fieldLabel: _('gallery.item_url')
  138. ,description: MODx.expandHelp ? '' : _('gallery.item_url_desc')
  139. ,name: 'url'
  140. ,id: this.ident+'-item-url'
  141. ,anchor: '100%'
  142. },{
  143. xtype: MODx.expandHelp ? 'label' : 'hidden'
  144. ,forId: this.ident+'-item-url'
  145. ,text: _('gallery.item_url_desc')
  146. ,cls: 'desc-under'
  147. },{
  148. xtype: 'textfield'
  149. ,fieldLabel: _('gallery.tags')
  150. ,description: MODx.expandHelp ? '' : _('gallery.comma_separated_list')
  151. ,name: 'tags'
  152. ,id: this.ident+'-tags'
  153. ,anchor: '100%'
  154. },{
  155. xtype: MODx.expandHelp ? 'label' : 'hidden'
  156. ,forId: this.ident+'-tags'
  157. ,text: _('gallery.comma_separated_list')
  158. ,cls: 'desc-under'
  159. }]
  160. },{
  161. columnWidth: .5
  162. ,items: [{
  163. xtype: 'hidden'
  164. ,name: 'thumbnail'
  165. },{
  166. xtype: 'hidden'
  167. ,name: 'image'
  168. },{
  169. html: ''
  170. ,id: this.ident+'-preview'
  171. },{
  172. xtype: 'statictextfield'
  173. ,name: 'id'
  174. ,fieldLabel: _('id')
  175. ,submitValue: true
  176. ,anchor: '100%'
  177. },{
  178. xtype: 'checkbox'
  179. ,boxLabel: _('gallery.active')
  180. ,description: MODx.expandHelp ? '' : _('gallery.item_active_desc')
  181. ,name: 'active'
  182. ,id: this.ident+'-active'
  183. ,hideLabel: true
  184. ,checked: true
  185. ,inputValue: 1
  186. },{
  187. xtype: MODx.expandHelp ? 'label' : 'hidden'
  188. ,forId: this.ident+'-active'
  189. ,text: _('gallery.item_active_desc')
  190. ,cls: 'desc-under'
  191. }]
  192. }]
  193. }]
  194. });
  195. GAL.window.UpdateItem.superclass.constructor.call(this,config);
  196. this.on('activate',function(w,e) {
  197. if (typeof Tiny != 'undefined') { MODx.loadRTE(this.ident + '-description'); }
  198. var d = this.fp.getForm().getValues();
  199. if (d && d.image) {
  200. var p = Ext.getCmp(this.ident+'-preview');
  201. var u = d.image+'&h=200&w=200&zc=1&q=100&f=png';
  202. p.update('<div class="gal-item-update-preview"><img src="'+u+'" alt="" onclick="Ext.getCmp(\'gal-album-items-view\').showScreenshot(\''+d.id+'\'); return false;" /></div>');
  203. }
  204. },this);
  205. };
  206. Ext.extend(GAL.window.UpdateItem,MODx.Window);
  207. Ext.reg('gal-window-item-update',GAL.window.UpdateItem);
  208. GAL.window.UploadItem = function(config) {
  209. config = config || {};
  210. this.ident = config.ident || 'gupit'+Ext.id();
  211. Ext.applyIf(config,{
  212. title: _('gallery.item_upload')
  213. ,id: this.ident
  214. // ,height: 150
  215. // ,width: '55%'
  216. ,width: 600
  217. // ,minWidth: 650
  218. ,url: GAL.config.connector_url
  219. ,action: 'mgr/item/upload'
  220. ,fileUpload: true
  221. ,fields: [{
  222. xtype: 'hidden'
  223. ,name: 'album'
  224. },{
  225. layout: 'column'
  226. ,border: false
  227. ,defaults: {
  228. layout: 'form'
  229. ,labelAlign: 'top'
  230. ,anchor: '100%'
  231. ,border: false
  232. ,cls: (MODx.config.connector_url) ? '' : 'main-wrapper' // check for 2.3
  233. ,labelSeparator: ''
  234. }
  235. ,items: [{
  236. columnWidth: .5
  237. ,items: [{
  238. xtype: 'textfield'
  239. ,fieldLabel: _('name')
  240. ,name: 'name'
  241. ,id: this.ident+'-name'
  242. ,anchor: '100%'
  243. },{
  244. xtype: 'textarea'
  245. ,fieldLabel: _('description')
  246. ,name: 'description'
  247. ,id: this.ident+'-description'
  248. ,anchor: '100%'
  249. },{
  250. xtype: 'textfield'
  251. ,fieldLabel: _('gallery.item_url')
  252. ,description: _('gallery.item_url_desc')
  253. ,name: 'url'
  254. ,id: this.ident+'-item-url'
  255. ,anchor: '100%'
  256. },{
  257. xtype: MODx.expandHelp ? 'label' : 'hidden'
  258. ,forId: this.ident+'-item-url'
  259. ,text: _('gallery.item_url_desc')
  260. ,cls: 'desc-under'
  261. }]
  262. },{
  263. columnWidth: .5
  264. ,items: [{
  265. xtype: (MODx.config.connector_url) ? 'fileuploadfield' : 'textfield' // check for 2.3
  266. ,inputType: (MODx.config.connector_url) ? 'text' : 'file' // check for 2.3
  267. ,fieldLabel: _('gallery.file')
  268. ,description: MODx.expandHelp ? '' : _('gallery.item_upload_file_desc')
  269. ,name: 'file'
  270. ,id: this.ident+'-file'
  271. ,anchor: '100%'
  272. },{
  273. xtype: MODx.expandHelp ? 'label' : 'hidden'
  274. ,forId: this.ident+'-file'
  275. ,text: _('gallery.item_upload_file_desc')
  276. ,cls: 'desc-under'
  277. },{
  278. xtype: 'textfield'
  279. ,fieldLabel: _('gallery.tags')
  280. ,description: MODx.expandHelp ? '' : _('gallery.comma_separated_list')
  281. ,name: 'tags'
  282. ,id: this.ident+'-tags'
  283. ,anchor: '100%'
  284. },{
  285. xtype: MODx.expandHelp ? 'label' : 'hidden'
  286. ,forId: this.ident+'-tags'
  287. ,text: _('gallery.comma_separated_list')
  288. ,cls: 'desc-under'
  289. },{
  290. xtype: 'checkbox'
  291. ,boxLabel: _('gallery.active')
  292. ,name: 'active'
  293. ,description: ''
  294. ,id: this.ident+'-active'
  295. ,hideLabel: true
  296. ,checked: true
  297. ,inputValue: 1
  298. },{
  299. xtype: MODx.expandHelp ? 'label' : 'hidden'
  300. ,forId: this.ident+'-active'
  301. ,text: _('gallery.item_active_desc')
  302. ,cls: 'desc-under'
  303. }]
  304. }]
  305. }]
  306. });
  307. GAL.window.UploadItem.superclass.constructor.call(this,config);
  308. this.on('activate',function() {
  309. if (typeof Tiny != 'undefined') { MODx.loadRTE(this.ident + '-description'); }
  310. });
  311. };
  312. Ext.extend(GAL.window.UploadItem,MODx.Window);
  313. Ext.reg('gal-window-item-upload',GAL.window.UploadItem);
  314. GAL.window.UploadCover = function(config) {
  315. config = config || {};
  316. this.ident = config.ident || 'gupit'+Ext.id();
  317. Ext.applyIf(config,{
  318. title: _('gallery.cover_upload')
  319. ,id: this.ident
  320. // ,height: 150
  321. ,height: 300 // account for the preview thumbnail that is rendered after the window is opened
  322. // ,width: 350
  323. // ,minWidth: 350
  324. ,saveBtnText:_('gallery.upload_cover')
  325. ,url: GAL.config.connector_url
  326. ,action: 'mgr/album/uploadcover'
  327. ,fileUpload: true
  328. ,fields: [{
  329. xtype: 'hidden'
  330. ,name: 'albumid'
  331. },{
  332. layout: 'column'
  333. ,border: false
  334. ,defaults: {
  335. layout: 'form'
  336. ,labelAlign: 'top'
  337. ,border: false
  338. ,cls: (MODx.config.connector_url) ? '' : 'main-wrapper' // check for 2.3
  339. ,labelSeparator: ''
  340. }
  341. ,items: [{
  342. columnWidth: 1
  343. ,items: [{
  344. xtype:'hidden'
  345. ,name:'id'
  346. },{
  347. xtype: (MODx.config.connector_url) ? 'fileuploadfield' : 'textfield' // check for 2.3
  348. ,inputType: (MODx.config.connector_url) ? 'text' : 'file' // check for 2.3
  349. ,fieldLabel: _('gallery.file')
  350. ,description: MODx.expandHelp ? '' : _('gallery.item_upload_file_desc')
  351. ,name: 'file'
  352. ,id: this.ident+'-file'
  353. ,anchor: '100%'
  354. },{
  355. xtype:'panel'
  356. ,fieldLabel: _('gallery.current_cover')
  357. ,html: ''
  358. ,id: this.ident+'-preview'
  359. }]
  360. }]
  361. }]
  362. });
  363. GAL.window.UploadCover.superclass.constructor.call(this,config);
  364. };
  365. Ext.extend(GAL.window.UploadCover,MODx.Window);
  366. Ext.reg('gal-window-cover-update',GAL.window.UploadCover);
  367. GAL.window.UploadMultiItems = function(config) {
  368. config = config || {};
  369. this.ident = config.ident || 'gupmuit'+Ext.id();
  370. Ext.applyIf(config,{
  371. title: _('gallery.multi_item_upload')
  372. ,id: this.ident
  373. ,height: 350
  374. // ,width: 475
  375. ,fields: [{
  376. xtype: 'hidden'
  377. ,name: 'album'
  378. },{
  379. layout: 'column'
  380. ,border: false
  381. ,defaults: {
  382. layout: 'form'
  383. ,labelAlign: 'top'
  384. ,anchor: '100%'
  385. ,border: false
  386. ,labelSeparator: ''
  387. }
  388. ,items: [{
  389. columnWidth: .5
  390. ,items: [{
  391. xtype: 'textfield'
  392. ,fieldLabel: _('gallery.tags')
  393. ,description: MODx.expandHelp ? '' : _('gallery.comma_separated_list')
  394. ,name: 'tags'
  395. ,id: this.ident+'-tags'
  396. ,anchor: '100%'
  397. },{
  398. xtype: MODx.expandHelp ? 'label' : 'hidden'
  399. ,forId: this.ident+'-tags'
  400. ,text: _('gallery.comma_separated_list')
  401. ,cls: 'desc-under'
  402. }]
  403. },{
  404. columnWidth: .5
  405. ,items: [{
  406. xtype: 'checkbox'
  407. ,boxLabel: _('gallery.active')
  408. ,hideLabel: true
  409. ,name: 'active'
  410. ,description: ''
  411. ,id: this.ident+'-active'
  412. ,checked: true
  413. ,inputValue: 1
  414. },{
  415. xtype: MODx.expandHelp ? 'label' : 'hidden'
  416. ,forId: this.ident+'-active'
  417. ,text: _('gallery.item_active_desc')
  418. ,cls: 'desc-under'
  419. }]
  420. }]
  421. },{
  422. html: '<div id="file-upload" />'+_('gallery.loading_ellipsis')+'</div>'
  423. ,id: 'file-upload-field'
  424. ,xtype: 'panel'
  425. }]
  426. ,buttons: [{
  427. text: _('done')
  428. ,scope: this
  429. ,handler: function() { this.hide(); }
  430. }]
  431. ,keys: [] // Prevent enter triggering the window submit
  432. });
  433. GAL.window.UploadMultiItems.superclass.constructor.call(this,config);
  434. this.on('show',this.setup,this)
  435. };
  436. Ext.extend(GAL.window.UploadMultiItems,MODx.Window,{
  437. setup: function() {
  438. if (typeof GAL.uploader == 'undefined') {
  439. GAL.uploader = new qq.FileUploader({
  440. element: document.getElementById('file-upload')
  441. ,action: GAL.config.connector_url
  442. ,params: {
  443. action: 'mgr/item/ajaxupload'
  444. ,album: this.config.album
  445. ,HTTP_MODAUTH: MODx.siteId
  446. }
  447. ,onComplete: function() {
  448. GAL.uploader.win.fireEvent('success');
  449. }
  450. ,onSubmit: function() {
  451. var f = GAL.uploader.win.fp.getForm();
  452. var data = {
  453. active: f.findField('active').getValue() ? 1 : 0
  454. ,tags: f.findField('tags').getValue()
  455. };
  456. var p = this.params;
  457. Ext.apply(p,data);
  458. GAL.uploader.setParams(p);
  459. }
  460. });
  461. GAL.uploader.win = this;
  462. }
  463. }
  464. });
  465. Ext.reg('gal-window-multi-item-upload',GAL.window.UploadMultiItems);
  466. GAL.window.BatchUpload = function(config) {
  467. config = config || {};
  468. this.ident = config.ident || 'gupbu'+Ext.id();
  469. Ext.applyIf(config,{
  470. title: _('gallery.batch_upload')
  471. ,id: this.ident
  472. // ,height: 150
  473. // ,width: 600
  474. ,url: GAL.config.connector_url
  475. ,action: 'mgr/item/batchupload'
  476. ,fileUpload: true
  477. ,fields: [{
  478. xtype: 'hidden'
  479. ,name: 'album'
  480. },{
  481. xtype: 'textfield'
  482. ,fieldLabel: _('gallery.directory')
  483. ,description: MODx.expandHelp ? '' : _('gallery.batch_upload_intro')
  484. ,name: 'directory'
  485. ,id: this.ident+'-directory'
  486. ,anchor: '100%'
  487. ,value: MODx.config['gallery.default_batch_upload_path'] || '{assets_path}images/'
  488. },{
  489. xtype: MODx.expandHelp ? 'label' : 'hidden'
  490. ,forId: this.ident+'-directory'
  491. ,text: _('gallery.batch_upload_intro')
  492. ,cls: 'desc-under'
  493. },{
  494. xtype: 'textfield'
  495. ,fieldLabel: _('gallery.tags')
  496. ,description: MODx.expandHelp ? '' : _('gallery.batch_upload_tags')
  497. ,name: 'tags'
  498. ,id: this.ident+'-tags'
  499. ,anchor: '100%'
  500. },{
  501. xtype: MODx.expandHelp ? 'label' : 'hidden'
  502. ,forId: this.ident+'-tags'
  503. ,text: _('gallery.batch_upload_tags')
  504. ,cls: 'desc-under'
  505. },{
  506. xtype: 'checkbox'
  507. ,boxLabel: _('gallery.active')
  508. ,description: MODx.expandHelp ? '' : _('gallery.item_active_desc')
  509. ,name: 'active'
  510. ,id: this.ident+'-active'
  511. ,hideLabel: true
  512. ,checked: true
  513. ,inputValue: 1
  514. },{
  515. xtype: MODx.expandHelp ? 'label' : 'hidden'
  516. ,forId: this.ident+'-active'
  517. ,text: _('gallery.item_active_desc')
  518. ,cls: 'desc-under'
  519. }]
  520. });
  521. GAL.window.BatchUpload.superclass.constructor.call(this,config);
  522. };
  523. Ext.extend(GAL.window.BatchUpload,MODx.Window);
  524. Ext.reg('gal-window-batch-upload',GAL.window.BatchUpload);
  525. GAL.window.ZipUpload = function(config) {
  526. config = config || {};
  527. this.ident = config.ident || 'gupbu'+Ext.id();
  528. Ext.applyIf(config,{
  529. title: _('gallery.zip_upload')
  530. ,id: this.ident
  531. // ,height: 150
  532. // ,width: 600
  533. ,url: GAL.config.connector_url
  534. ,action: 'mgr/item/zipupload'
  535. ,fileUpload: true
  536. ,fields: [{
  537. xtype: 'hidden'
  538. ,name: 'album'
  539. },{
  540. xtype: (MODx.config.connector_url) ? 'fileuploadfield' : 'textfield' // check for 2.3
  541. ,inputType: (MODx.config.connector_url) ? 'text' : 'file' // check for 2.3
  542. ,fieldLabel: _('gallery.zip_file')
  543. ,description: MODx.expandHelp ? '' : _('gallery.zip_upload_intro')
  544. ,name: 'zip'
  545. ,id: this.ident+'-zip'
  546. ,anchor: '100%'
  547. },{
  548. xtype: MODx.expandHelp ? 'label' : 'hidden'
  549. ,forId: this.ident+'-zip'
  550. ,text: _('gallery.zip_upload_intro')
  551. ,cls: 'desc-under'
  552. },{
  553. xtype: 'textfield'
  554. ,fieldLabel: _('gallery.tags')
  555. ,description: MODx.expandHelp ? '' : _('gallery.batch_upload_tags')
  556. ,name: 'tags'
  557. ,id: this.ident+'-tags'
  558. ,anchor: '100%'
  559. },{
  560. xtype: MODx.expandHelp ? 'label' : 'hidden'
  561. ,forId: this.ident+'-tags'
  562. ,text: _('gallery.batch_upload_tags')
  563. ,cls: 'desc-under'
  564. },{
  565. xtype: 'checkbox'
  566. ,boxLabel: _('gallery.active')
  567. ,description: MODx.expandHelp ? '' : _('gallery.item_active_desc')
  568. ,name: 'active'
  569. ,id: this.ident+'-active'
  570. ,hideLabel: true
  571. ,checked: true
  572. ,inputValue: 1
  573. },{
  574. xtype: MODx.expandHelp ? 'label' : 'hidden'
  575. ,forId: this.ident+'-active'
  576. ,text: _('gallery.item_active_desc')
  577. ,cls: 'desc-under'
  578. }]
  579. });
  580. GAL.window.ZipUpload.superclass.constructor.call(this,config);
  581. };
  582. Ext.extend(GAL.window.ZipUpload,MODx.Window);
  583. Ext.reg('gal-window-zip-upload',GAL.window.ZipUpload);