LogCommend.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. MWF.xApplication.cms.Xform.widget = MWF.xApplication.cms.Xform.widget || {};
  2. MWF.xApplication.cms.Xform.widget.LogCommend = new Class({
  3. Implements: [Options, Events],
  4. Extends: MWF.widget.Common,
  5. options: {
  6. "style": "default",
  7. "mode" : "table",
  8. "documentId" : "",
  9. "textStyle" : ""
  10. },
  11. initialize: function (app, node, options) {
  12. this.setOptions(options);
  13. this.app = app;
  14. this.node = node;
  15. this.path = "../x_component_cms_Xform/widget/$Log/";
  16. this.cssPath = "../x_component_cms_Xform/widget/$Log/" + this.options.style + "/css.wcss";
  17. this._loadCss();
  18. MWF.xDesktop.requireApp("cms.Xform", "lp."+MWF.language, null, false);
  19. this.lp = MWF.xApplication.cms.Xform.LP;
  20. },
  21. load : function(){
  22. this.items = [];
  23. this.documents = {};
  24. this.isItemsLoaded = false;
  25. this.isItemLoadding = false;
  26. this.loadItemQueue = 0;
  27. this.currentPage = 1;
  28. this.count = 0;
  29. this.lineHeight = this.options.mode != "text" ? 32 : 25;
  30. this.countPerPage = 20;
  31. this.container = new Element("div",{styles:this.css.container}).inject( this.node );
  32. this.loadTitle();
  33. this.loadContent();
  34. this.loadElementList();
  35. this.loadBottom();
  36. },
  37. loadTitle : function(){
  38. this.titleNode = new Element("div", {"styles": this.css.titleNode, "text": this.lp.commendLogTitle}).inject(this.container);
  39. },
  40. loadTotal: function(){
  41. this.titleCountNode = new Element("div", {
  42. styles : this.css.titleCountNode,
  43. text : this.lp.commendCountText.replace("{count}", this.dataCount )
  44. }).inject(this.titleNode);
  45. },
  46. loadContent : function(){
  47. //this.contentContainerNode = new Element("div", {"styles": this.css.contentContainerNode }).inject(this.container);
  48. this.contentScrollNode = new Element("div", {"styles": this.css.contentScrollNode }).inject(this.container);
  49. this.contentScrollNode.setStyles({
  50. "width" : this.node.getSize().x-10,
  51. "margin-right" : "10px"
  52. });
  53. this.contentWrapNode = new Element("div", {"styles": this.css.contentWrapNode }).inject(this.contentScrollNode);
  54. this.setScroll();
  55. if( this.options.mode == "table" ){
  56. this.loadItemTitleTable();
  57. }
  58. },
  59. loadBottom: function(){
  60. var bottomNode = new Element("div",{
  61. "styles" : this.css.bottomNode
  62. }).inject( this.container );
  63. var resizeNode = new Element("div",{
  64. "styles" : this.css.bottomResizeNode,
  65. "text" : "◢"
  66. }).inject(bottomNode);
  67. var xLimit = this.contentScrollNode.getSize().x;
  68. this.contentScrollNode.makeResizable({
  69. "handle": resizeNode,
  70. "limit": {x:[xLimit, xLimit], y:[50, null]},
  71. "onDrag": function(){
  72. var y = this.contentScrollNode.getSize().y;
  73. if( y > ( this.lineHeight * this.countPerPage - 20 ) ){
  74. this.countPerPage = parseInt( y / this.lineHeight ) + 2
  75. }
  76. this.contentScrollNode.fireEvent("resize");
  77. }.bind(this),
  78. "onComplete": function(){
  79. this.scrollBar.checkScroll();
  80. this.loadElementList();
  81. }.bind(this)
  82. });
  83. },
  84. loadElementList : function( count ){
  85. if (!this.isItemsLoaded) {
  86. if (!this.isItemLoadding) {
  87. this.isItemLoadding = true;
  88. this._getCurrentPageData(function (json) {
  89. var length = this.dataCount = json.count; //|| json.data.length;
  90. if( !this.titleCountNode ){
  91. this.loadTotal();
  92. }
  93. if( this.items.length == 0 )this.setSize();
  94. if (length <= this.items.length) {
  95. this.isItemsLoaded = true;
  96. }
  97. if( json.data && typeOf( json.data )=="array" ){
  98. json.data.each(function (data ) {
  99. var key = data.id;
  100. if (!this.documents[key]) {
  101. var item = this._createDocument(data, this.items.length);
  102. this.items.push(item);
  103. this.documents[key] = item;
  104. }
  105. }.bind(this));
  106. }
  107. this.isItemLoadding = false;
  108. if (this.loadItemQueue > 0) {
  109. this.loadItemQueue--;
  110. this.loadElementList();
  111. }
  112. }.bind(this), count);
  113. } else {
  114. this.loadItemQueue++;
  115. }
  116. }
  117. },
  118. _getCurrentPageData : function(callback){
  119. o2.Actions.load("x_cms_assemble_control").DocumentCommendAction.listPaging(this.currentPage,this.countPerPage,{
  120. "documentId" : this.options.documentId
  121. },function(json){
  122. if (callback) callback(json);
  123. }.bind(this));
  124. },
  125. getAction: function(callback){
  126. if (!this.action){
  127. MWF.require("MWF.xDesktop.Actions.RestActions", function(){
  128. this.restAction = new MWF.xDesktop.Actions.RestActions("", "x_cms_assemble_control", "");
  129. this.restAction.getActions = function(actionCallback){
  130. this.actions = {
  131. "getReadCount" : {"uri":"/jaxrs/document/{docId}/view/count"},
  132. "listReadedLog": {"uri": "/jaxrs/commend/list/paging/{page}/size/{size}", "method":"POST"}
  133. };
  134. if (actionCallback) actionCallback();
  135. };
  136. if (callback) callback();
  137. }.bind(this));
  138. }else{
  139. if (callback) callback();
  140. }
  141. },
  142. setSize : function(){
  143. var lineHeight = this.lineHeight;
  144. var maxCount = this.options.mode == "text" ? 10 : 8;
  145. if( this.dataCount > maxCount ){
  146. var height = maxCount*lineHeight - 15;
  147. }else if( this.dataCount <= 1 ){
  148. var height = 1*lineHeight;
  149. }else{
  150. var height = this.dataCount*lineHeight;
  151. }
  152. if( this.options.mode != "text" )height = height + lineHeight;
  153. this.contentScrollNode.setStyle("height", height+"px");
  154. },
  155. setScroll: function(){
  156. MWF.require("MWF.widget.ScrollBar", function () {
  157. this.scrollBar = new MWF.widget.ScrollBar(this.contentScrollNode, {
  158. "indent": false,
  159. "style": "default",
  160. "where": "before",
  161. "distance": 60,
  162. "friction": 4,
  163. "axis": {"x": false, "y": true},
  164. "onScroll": function (y) {
  165. var scrollSize = this.contentScrollNode.getScrollSize();
  166. var clientSize = this.contentScrollNode.getSize();
  167. var scrollHeight = scrollSize.y - clientSize.y;
  168. if (y + 30 > scrollHeight ) {
  169. if (! this.isItemsLoaded) {
  170. this.currentPage ++;
  171. this.loadElementList();
  172. }
  173. }
  174. }.bind(this)
  175. });
  176. }.bind(this));
  177. },
  178. _createDocument: function( data ){
  179. var itemNode;
  180. if( this.options.mode == "text" ){
  181. if( this.options.textStyle ){
  182. itemNode = this.loadItemNodeText( data );
  183. }else{
  184. itemNode = this.loadItemNodeDefault( data );
  185. }
  186. }else{
  187. itemNode = this.loadItemNodeTable( data );
  188. }
  189. return {
  190. node : itemNode,
  191. data : data
  192. }
  193. },
  194. loadItemTitleTable: function(){
  195. var xSize = this.contentScrollNode.getSize().x;
  196. this.table = new Element("table", {
  197. "styles": this.css.logTable,
  198. "border": "0",
  199. "cellSpacing": "0",
  200. "cellpadding": "3px",
  201. "width": xSize - 10
  202. }).inject( this.contentWrapNode );
  203. this.tbody = new Element("tbody").inject( this.table );
  204. this.table.setStyles({
  205. "margin-left" : "8px"
  206. });
  207. var tr = new Element("tr").inject( this.tbody );
  208. tr.setStyles(this.css.logTableTitleTr);
  209. var td = new Element("td", { styles : this.css.logTableTitle }).inject( tr );
  210. td.set("text", this.lp.commendLogPerson);
  211. var td = new Element("td", { styles : this.css.logTableTitle }).inject( tr );
  212. td.set("text", this.lp.commendLogTime);
  213. },
  214. loadItemNodeTable: function(data){
  215. var tr = new Element("tr").inject( this.tbody );
  216. tr.setStyles(this.css.logTableContentTr);
  217. var td = new Element("td", { styles : this.css.logTableContent }).inject( tr );
  218. td.set("text", this.getShortName(data.commendPerson) || "");
  219. td = new Element("td", { styles : this.css.logTableContent }).inject( tr );
  220. td.set("text", data.createTime);
  221. },
  222. loadItemNodeText: function(data, textStyle){
  223. var itemNode = new Element("div",{ "styles" : this.css.defaultItemNode }).inject(this.contentWrapNode);
  224. var html = textStyle || this.options.textStyle;
  225. html = html.replace(/\{person\}/g, this.getShortName( data.commendPerson));
  226. html = html.replace(/\{date\}/g, data.createTime);
  227. itemNode.set("html", html);
  228. return itemNode;
  229. },
  230. loadItemNodeDefault: function( data ){
  231. //var itemNode = new Element("div",{ "styles" : this.css.defaultItemNode }).inject(this.contentWrapNode);
  232. //var personNode = new Element("div",{ styles : this.css.defaultItemPersonNode ,text : data.viewerName }).inject(itemNode);
  233. //if(data.viewerOrganization){
  234. // var departmentNode = new Element("div",{ styles : this.css.defaultItemDepartmentNode ,text : "("+data.viewerOrganization+")" }).inject(itemNode);
  235. //}
  236. //
  237. //new Element("div",{ styles : this.css.defaultItemTextNode , text : this.lp.at }).inject(itemNode);
  238. //var timeNode = new Element("div",{ styles : this.css.defaultItemTimeNode , text : data.lastViewTime }).inject(itemNode);
  239. //new Element("div",{ styles : this.css.defaultItemTextNode , text : this.lp.readdDocument }).inject(itemNode);
  240. //
  241. //new Element("div",{ styles : this.css.defaultItemTextNode , text : this.lp.historyRead }).inject(itemNode);
  242. //var countNode = new Element("div",{ styles : this.css.defaultItemCountNode ,text : data.viewCount }).inject(itemNode);
  243. //new Element("div",{ styles : this.css.defaultItemTextNode , text : this.lp.times }).inject(itemNode);
  244. return this.loadItemNodeText( data, this.lp.defaultCommendLogText );
  245. },
  246. getShortName : function( dn ){
  247. if( dn && dn.contains("@") ){
  248. return dn.split("@")[0];
  249. }else{
  250. return dn;
  251. }
  252. }
  253. });