Log.js 13 KB

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