Main.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  1. //MWF.xDesktop.requireApp("Minder", "Actions.RestActions", null, false);
  2. MWF.require("MWF.widget.Tree", null, false);
  3. MWF.xApplication.Minder.Main = new Class({
  4. Extends: MWF.xApplication.Common.Main,
  5. Implements: [Options, Events],
  6. options: {
  7. "style": "default",
  8. "name": "Minder",
  9. "icon": "icon.png",
  10. "width": "1200",
  11. "height": "700",
  12. "isResize": false,
  13. "title": MWF.xApplication.Minder.LP.title,
  14. "defaultAction" : "openMineExplorer"
  15. },
  16. onQueryLoad: function(){
  17. this.lp = MWF.xApplication.Minder.LP;
  18. this.restActions = MWF.Actions.get("x_mind_assemble_control"); //new MWF.xApplication.Minder.Actions.RestActions();
  19. },
  20. loadApplication: function(callback){
  21. this.createNode();
  22. this.loadApplicationContent();
  23. if (callback) callback();
  24. },
  25. createNode: function(){
  26. this.content.setStyle("overflow", "hidden");
  27. this.node = new Element("div", {
  28. "styles": {"width": "100%", "height": "100%", "overflow": "hidden"}
  29. }).inject(this.content);
  30. },
  31. loadApplicationContent: function() {
  32. this.naviNode = new Element("div.naviNode",{
  33. "styles" : this.css.naviNode
  34. }).inject(this.node);
  35. new Element("div.naviTopNode",{
  36. "styles" : this.css.naviTopNode
  37. }).inject(this.naviNode);
  38. this.contentNode = new Element("div.contentNode",{
  39. "styles" : this.css.contentNode
  40. }).inject(this.node);
  41. //this.histroy = new MWF.xApplication.Minder.History(this);
  42. this.resizeContent();
  43. this.resizeFun = this.resizeContent.bind( this );
  44. this.addEvent("resize", this.resizeFun);
  45. this.loadNavi();
  46. },
  47. loadNavi : function(){
  48. var naviJson = [
  49. {
  50. "title": "我的文件",
  51. "action": "openMineExplorer",
  52. "icon": "navi_mine"
  53. },
  54. {
  55. "title": "分享文件",
  56. "action": "openSharedExplorer",
  57. "icon": "navi_share"
  58. },
  59. {
  60. "title": "收到文件",
  61. "action": "openReceivedExplorer",
  62. "icon": "navi_receive"
  63. },
  64. {
  65. "title": "回收站",
  66. "action": "openRecycleExplorer",
  67. "icon": "navi_recycle"
  68. }
  69. // {
  70. // "title": "来自应用",
  71. // "action": "personConfig",
  72. // "icon": "navi_fromapp"
  73. // }
  74. ];
  75. naviJson.each( function( d ){
  76. this.createNaviNode( d );
  77. }.bind(this))
  78. },
  79. openMineExplorer: function(){
  80. MWF.xDesktop.requireApp("Minder", "MineExplorer", null, false);
  81. if(this.currentExplorer){
  82. this.currentExplorer.destroy();
  83. }
  84. var options = (this.status && this.status.explorerStatus ) ? this.status.explorerStatus : {};
  85. this.currentExplorer = new MWF.xApplication.Minder.MineExplorer( this.contentNode, this, options );
  86. this.currentExplorer.load();
  87. },
  88. openSharedExplorer: function(){
  89. MWF.xDesktop.requireApp("Minder", "SharedExplorer", null, false);
  90. if(this.currentExplorer){
  91. this.currentExplorer.destroy();
  92. }
  93. var options = (this.status && this.status.explorerStatus ) ? this.status.explorerStatus : {};
  94. this.currentExplorer = new MWF.xApplication.Minder.SharedExplorer( this.contentNode, this, options );
  95. this.currentExplorer.load();
  96. },
  97. openReceivedExplorer: function(){
  98. MWF.xDesktop.requireApp("Minder", "ReceivedExplorer", null, false);
  99. if(this.currentExplorer){
  100. this.currentExplorer.destroy();
  101. }
  102. var options = (this.status && this.status.explorerStatus ) ? this.status.explorerStatus : {};
  103. this.currentExplorer = new MWF.xApplication.Minder.ReceivedExplorer( this.contentNode, this, options );
  104. this.currentExplorer.load();
  105. },
  106. openRecycleExplorer: function(){
  107. MWF.xDesktop.requireApp("Minder", "RecycleBinExplorer", null, false);
  108. if(this.currentExplorer){
  109. this.currentExplorer.destroy();
  110. }
  111. var options = (this.status && this.status.explorerStatus ) ? this.status.explorerStatus : {};
  112. this.currentExplorer = new MWF.xApplication.Minder.RecycleBinExplorer( this.contentNode, this, options );
  113. this.currentExplorer.load();
  114. },
  115. createNaviNode : function( d ){
  116. var _self = this;
  117. var node = new Element("div",{
  118. text : d.title,
  119. styles : this.css.naviItemNode,
  120. events : {
  121. click : function( ev ){
  122. if( _self.currentAction == d.action )return;
  123. ev.target.setStyles( _self.css.naviItemNode_selected );
  124. if(_self.currentNaviItemNode)_self.currentNaviItemNode.setStyles( _self.css.naviItemNode );
  125. _self.currentNaviItemNode = ev.target;
  126. _self.currentAction = d.action;
  127. _self[ d.action ]();
  128. }
  129. }
  130. }).inject( this.naviNode );
  131. node.setStyle("background-image", "url("+this.path + this.options.style + "/icon/" + d.icon + ".png)" );
  132. if( this.status && this.status.action && this.status.action == d.action ){
  133. node.click();
  134. }else if( this.options.defaultAction == d.action ){
  135. node.click();
  136. }
  137. },
  138. recordStatus : function(){
  139. return {
  140. action : this.currentAction,
  141. explorerStatus : this.currentExplorer.recordStatus()
  142. }
  143. },
  144. resizeContent : function(){
  145. var size = this.content.getSize();
  146. this.naviNode.setStyle("height", size.y);
  147. },
  148. getDateDiff : function (publishTime) {
  149. if(!publishTime)return "";
  150. var dateTimeStamp = Date.parse(publishTime.replace(/-/gi, "/"));
  151. var minute = 1000 * 60;
  152. var hour = minute * 60;
  153. var day = hour * 24;
  154. var halfamonth = day * 15;
  155. var month = day * 30;
  156. var year = month * 12;
  157. var now = new Date().getTime();
  158. var diffValue = now - dateTimeStamp;
  159. if (diffValue < 0) {
  160. //若日期不符则弹出窗口告之
  161. //alert("结束日期不能小于开始日期!");
  162. }
  163. var yesterday = new Date().decrement('day', 1);
  164. var beforYesterday = new Date().decrement('day', 2);
  165. var yearC = diffValue / year;
  166. var monthC = diffValue / month;
  167. var weekC = diffValue / (7 * day);
  168. var dayC = diffValue / day;
  169. var hourC = diffValue / hour;
  170. var minC = diffValue / minute;
  171. if (yesterday.getFullYear() == dateTimeStamp.getFullYear() && yesterday.getMonth() == dateTimeStamp.getMonth() && yesterday.getDate() == dateTimeStamp.getDate()) {
  172. result = "昨天 " + dateTimeStamp.getHours() + ":" + dateTimeStamp.getMinutes();
  173. } else if (beforYesterday.getFullYear() == dateTimeStamp.getFullYear() && beforYesterday.getMonth() == dateTimeStamp.getMonth() && beforYesterday.getDate() == dateTimeStamp.getDate()) {
  174. result = "前天 " + dateTimeStamp.getHours() + ":" + dateTimeStamp.getMinutes();
  175. } else if (yearC > 1) {
  176. result = dateTimeStamp.getFullYear() + "-" + (dateTimeStamp.getMonth() + 1) + "-" + dateTimeStamp.getDate();
  177. } else if (monthC >= 1) {
  178. //result= parseInt(monthC) + "个月前";
  179. // s.getFullYear()+"年";
  180. result = dateTimeStamp.getFullYear() + "-" + (dateTimeStamp.getMonth() + 1) + "-" + dateTimeStamp.getDate();
  181. } else if (weekC >= 1) {
  182. result = parseInt(weekC) + "周前";
  183. } else if (dayC >= 1) {
  184. result = parseInt(dayC) + "天前";
  185. } else if (hourC >= 1) {
  186. result = parseInt(hourC) + "小时前";
  187. } else if (minC >= 1) {
  188. result = parseInt(minC) + "分钟前";
  189. } else
  190. result = "刚刚";
  191. return result;
  192. }
  193. });
  194. MWF.xApplication.Minder.History = new Class({
  195. initialize : function( app ){
  196. this.app = app;
  197. this.css = app.css;
  198. this.MAX_HISTORY = 100;
  199. this.lastSnap;
  200. this.patchLock;
  201. this.undoDiffs = [];
  202. this.redoDiffs = [];
  203. this.reset();
  204. this.app.addEvent('patchChange', this.changed.bind(this));
  205. },
  206. load : function( container ){
  207. if( this.node ){
  208. this.node.inject( container );
  209. }else{
  210. this.loadNode( container );
  211. }
  212. },
  213. loadNode : function( container ){
  214. this.node = new Element("div",{
  215. styles : this.css.historyNode
  216. }).inject( container );
  217. this.undoNode = new Element("div",{ styles : this.css.undoNode }).inject( this.node );
  218. this.redoNode = new Element("div",{ styles : this.css.redoNode }).inject( this.node );
  219. this.patchNode = new Element("div", { styles : this.css.patchNode }).inject( this.node );
  220. },
  221. reset: function () {
  222. this.undoDiffs = [];
  223. this.redoDiffs = [];
  224. this.lastSnap = "mine/root";
  225. },
  226. makeUndoDiff: function( snap ) {
  227. if (snap != this.lastSnap) {
  228. this.undoDiffs.push(snap);
  229. while (this.undoDiffs.length > this.MAX_HISTORY) {
  230. this.undoDiffs.shift();
  231. }
  232. this.lastSnap = snap;
  233. return true;
  234. }
  235. },
  236. makeRedoDiff:function( snap ) {
  237. this.redoDiffs.push( snap );
  238. },
  239. undo: function() {
  240. this.patchLock = true;
  241. var undoDiff = this.undoDiffs.pop();
  242. if (undoDiff) {
  243. this.app.applyPatches(undoDiff);
  244. this.makeRedoDiff( undoDiff );
  245. }
  246. this.patchLock = false;
  247. },
  248. redo: function() {
  249. this.patchLock = true;
  250. var redoDiff = this.redoDiffs.pop();
  251. if (redoDiff) {
  252. this.app.applyPatches(redoDiff);
  253. this.makeUndoDiff( redoDiff );
  254. }
  255. this.patchLock = false;
  256. },
  257. changed: function( snap ) {
  258. if (this.patchLock) return;
  259. if (this.makeUndoDiff( snap )) this.redoDiffs = [];
  260. },
  261. hasUndo: function() {
  262. return !!this.undoDiffs.length;
  263. },
  264. hasRedo: function() {
  265. return !!this.redoDiffs.length;
  266. }
  267. });