file.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /**
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. App.FileController = Ember.ObjectController.extend({
  19. init:function () {
  20. this.set('content.selected', false);
  21. this._super();
  22. },
  23. actions:{
  24. download:function (option) {
  25. this.store.linkFor([this.get('content')],option).then(function (link) {
  26. window.location.href = link;
  27. });
  28. },
  29. rename:function (opt,file) {
  30. var file = this.get('content'),
  31. self,path,name,newPath;
  32. if (opt === 'edit') {
  33. this.set('tmpName',file.get('title'));
  34. this.set('isRenaming',true);
  35. };
  36. if (opt === 'cancel') {
  37. this.set('tmpName','');
  38. this.set('isRenaming',false);
  39. };
  40. if (opt === 'confirm') {
  41. self = this;
  42. path = file.get('path');
  43. name = this.get('tmpName');
  44. if (Em.isEmpty(name)) {
  45. return false;
  46. }
  47. if (name === file.get('title')) {
  48. return self.set('isRenaming',false);
  49. }
  50. newPath = path.substring(0,path.lastIndexOf('/')+1)+name;
  51. this.store.move(file,newPath).then(function () {
  52. self.set('tmpName','');
  53. self.set('isRenaming',false);
  54. });
  55. };
  56. },
  57. open:function (file) {
  58. if (this.get('content.isDirectory')) {
  59. return this.transitionToRoute('files',{queryParams: {path: this.get('content.id')}});
  60. } else{
  61. return this.send('download');
  62. };
  63. },
  64. removeFile:function (opt) {
  65. if (opt=='ask') {
  66. this.toggleProperty('isRemoving');
  67. console.log('ask removeFile')
  68. return false;
  69. };
  70. if (opt == 'cancel' && !this.isDestroyed) {
  71. this.set('isRemoving',false);
  72. console.log('cancel removeFile')
  73. }
  74. if (opt == 'confirm') {
  75. this.set('isRemoving',false);
  76. this.store.remove(this.get('content'));
  77. }
  78. },
  79. deleteFile:function () {
  80. var file = this.get('content');
  81. this.store.remove(file);
  82. },
  83. },
  84. tmpName:'',
  85. selected:false,
  86. isRenaming:false,
  87. isRemoving:false,
  88. isMoving:function () {
  89. var movingFile = this.get('parentController.movingFile.path');
  90. var thisFile = this.get('content.id');
  91. return movingFile === thisFile;
  92. }.property('parentController.movingFile'),
  93. setSelected:function (controller,observer) {
  94. this.set('selected',this.get(observer))
  95. }.observes('content.selected')
  96. });