file.js 3.5 KB

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