gcmsFiles.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. /**
  2. * [ONEMAP.M.gcmsFiles]
  3. * @return {[object]}
  4. */
  5. define([
  6. 'html!templates/gcms/gcmsFiles',
  7. 'vendorDir/handlebars/handlebars',
  8. 'css!styles/gcms/gcmsFiles'
  9. ],
  10. function(tpcLayout,Handlebars){
  11. //参数
  12. var modValue = {
  13. options:{}
  14. };
  15. //地图层
  16. //var _map = ONEMAP.M.mapHolder.map;
  17. /**
  18. * 模块初始化
  19. * @return {[type]} [description]
  20. */
  21. function init(options){
  22. modValue.options = {};
  23. for(var op in options){
  24. modValue.options[op] = options[op];
  25. }
  26. //获取内容数据
  27. getDetailData({callback:function(){
  28. showFiles();
  29. }});
  30. //订阅推送
  31. subscribe();
  32. }
  33. function getDetailData(options){
  34. ONEMAP.V.loading.load();
  35. $.ajax({
  36. url: onemapUrlConfig.gcmsServiceUrl+'/show/'+modValue.options['column_name']+'/'+modValue.options['article_id'],
  37. type:"GET",
  38. dataType: 'json'
  39. })
  40. .done(function(data) {
  41. ONEMAP.V.loading.loaded();
  42. if(data.code == 4){
  43. ONEMAP.C.noPermission('getDetailData');
  44. return false;
  45. }
  46. if(data.code == 3){
  47. ONEMAP.C.logout('getDetailData');
  48. }
  49. if(JSON.parse(data['data']['record'][modValue.options['field_name']]).length == 0){
  50. ONEMAP.C.publisher.publish({ type: 'warning', message: '没有文件数据' }, 'noteBar::add');
  51. remove();
  52. }else {
  53. ONEMAP.D.gcmsCurArticleData = data['data'];
  54. options.callback();
  55. }
  56. })
  57. .fail(function() {
  58. ONEMAP.V.loading.loaded();
  59. });
  60. }
  61. /**
  62. * 事件绑定
  63. * @return {[type]} [description]
  64. */
  65. function bindEvent(){
  66. $('#gcmsFilesModal .modal-header .close').bind('click', function() {
  67. remove();
  68. });
  69. $('#gcmsFilesModal .modal-header').dragmove($('#gcmsFilesModal'));
  70. var $box2 = $('#gcmsFilesModal').on('mousedown', '#coorForGcmsFilesModal', function(e) {
  71. var posix = {
  72. 'w': $box2.width(),
  73. 'h': $box2.height(),
  74. 'x': e.pageX,
  75. 'y': e.pageY
  76. };
  77. $.extend(document, {'move': true, 'call_down': function(e) {
  78. $box2.css({
  79. 'width': Math.max(30, e.pageX - posix.x + posix.w),
  80. 'height': Math.max(30, e.pageY - posix.y + posix.h)
  81. });
  82. var bodyHeight = Math.max(30, e.pageY - posix.y + posix.h )-75;
  83. $("#gcmsFilesModal .modal-body").css({height:bodyHeight});
  84. }});
  85. return false;
  86. });
  87. }
  88. function showFiles(){
  89. $('body').append(tpcLayout);
  90. bindEvent();
  91. if(map23DData.display.map2D){
  92. $('#gcmsFilesModal').removeClass('TD');
  93. }else{
  94. $('#gcmsFilesModal').addClass('TD');
  95. }
  96. $('#gcmsFilesModal').show();
  97. //显示列表
  98. $('#gcmsFilesList').empty();
  99. $(JSON.parse(ONEMAP.D.gcmsCurArticleData['record'][modValue.options['field_name']])).each(function(index, el) {
  100. $('<li><button vUrl="'+onemapUrlConfig.gcmsServiceUrl+'/file'+el+'" class="btn">文件['+(index+1)+']</button></li>').appendTo($('#gcmsFilesList'));
  101. });
  102. //$('#gcmsFilesList .btn:eq(0)').addClass('selected');
  103. $('#gcmsFilesList .btn').bind('click',function(){
  104. var filesFileUrl = $(this).attr('vUrl');
  105. window.open(filesFileUrl);
  106. });
  107. }
  108. /**
  109. * 界面布局重置
  110. * @type {Function}
  111. */
  112. function layoutResize(){
  113. }
  114. /**
  115. * 切换23D样式
  116. */
  117. function layoutResizeCSS(cid) {
  118. if (cid == '2d') {
  119. $('#gcmsFilesModal').removeClass('TD');
  120. } else {
  121. $('#gcmsFilesModal').addClass('TD');
  122. }
  123. }
  124. /**
  125. * 注册监听
  126. * @type {Function}
  127. */
  128. function subscribe(){
  129. ONEMAP.C.publisher.subscribe(remove,'gcmsArticleShowRemove');
  130. ONEMAP.C.publisher.subscribe(remove, 'cleanMap');
  131. ONEMAP.C.publisher.subscribe(layoutResizeCSS, 'change23D');
  132. }
  133. /**
  134. * 取消监听
  135. * @type {Function}
  136. */
  137. function unSubscribe() {}
  138. /**
  139. * 模块移除
  140. * @return {[type]} [description]
  141. */
  142. function remove(){
  143. $('#gcmsFilesModal').remove();
  144. unSubscribe();
  145. }
  146. return ONEMAP.M.gcmsFiles = {
  147. init:init,
  148. remove:remove
  149. }
  150. });