file.js 3.4 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. var App = require('app');
  19. App.FileController = Ember.ObjectController.extend({
  20. needs:['files'],
  21. actions:{
  22. download:function (option) {
  23. if (this.get('content.readAccess')) {
  24. this.store.linkFor([this.get('content')],option).then(function (link) {
  25. window.location.href = link;
  26. },Em.run.bind(this,this.sendAlert));
  27. }
  28. },
  29. showChmod:function () {
  30. this.send('showChmodModal',this.get('content'));
  31. },
  32. rename:function (opt,name) {
  33. var file = this.get('content'),
  34. path = file.get('path'),
  35. newPath;
  36. if (name === file.get('name') || Em.isEmpty(name)) {
  37. return this.set('isRenaming',!Em.isEmpty(name));
  38. }
  39. newPath = path.substring(0,path.lastIndexOf('/')+1)+name;
  40. this.store.move(file,newPath)
  41. .then(Em.run.bind(this,this.set,'isRenaming',false),Em.run.bind(this,this.sendAlert));
  42. },
  43. editName:function () {
  44. this.set('isRenaming',true);
  45. },
  46. open:function (file) {
  47. if (!this.get('content.readAccess')) {
  48. return false;
  49. }
  50. if (this.get('content.isDirectory')) {
  51. return this.transitionToRoute('files',{queryParams: {path: this.get('content.id')}});
  52. } else{
  53. return this.send('download');
  54. }
  55. },
  56. deleteFile:function (deleteForever) {
  57. if (this.get('dirInfo.writeAccess')) {
  58. this.store
  59. .remove(this.get('content'),!deleteForever)
  60. .then(null,Em.run.bind(this,this.deleteErrorCallback,this.get('content')));
  61. } else {
  62. this.send('showAlert',{message:'Permission denied'});
  63. }
  64. }
  65. },
  66. selected:false,
  67. isRenaming:false,
  68. isMovingToTrash:false,
  69. chmodVisible:false,
  70. targetContextMenu:null,
  71. isPermissionsDirty:function () {
  72. var file = this.get('content');
  73. var diff = file.changedAttributes();
  74. return !!diff.permission;
  75. }.property('content.permission'),
  76. isMoving:function () {
  77. var movingFile = this.get('parentController.movingFile.path');
  78. var thisFile = this.get('content.id');
  79. return movingFile === thisFile;
  80. }.property('parentController.movingFile'),
  81. setSelected:function (controller,observer) {
  82. this.set('selected',this.get(observer));
  83. }.observes('content.selected'),
  84. renameSuccessCallback:function (record,error) {
  85. record.rollback();
  86. this.sendAlert(error);
  87. },
  88. dirInfo: Em.computed.alias('controllers.files.content.meta'),
  89. deleteErrorCallback:function (record,error) {
  90. this.get('parentController.model').pushRecord(record);
  91. this.send('showAlert',error);
  92. },
  93. sendAlert:function (error) {
  94. this.send('showAlert',error);
  95. }
  96. });