material.js 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623
  1. define(['underscore', 'jquery.wookmark', 'jquery.jplayer'], function(_){
  2. var material = {
  3. 'defaultoptions' : {
  4. callback : null,
  5. type : 'all',
  6. multiple : false,
  7. ignore : {
  8. 'basic' : false,
  9. 'wxcard' : true,
  10. 'image' : false,
  11. 'music' : false,
  12. 'news' : false,
  13. 'video' : false,
  14. 'voice' : false,
  15. 'keyword' : false,
  16. 'module' : false
  17. },
  18. others : {
  19. 'basic' : {
  20. 'typeVal' : ''
  21. },
  22. 'news' : {
  23. 'showwx' : true,
  24. 'showlocal' : true
  25. }
  26. }
  27. },
  28. 'init' : function(callback, options) {
  29. var $this = this;
  30. $this.options = $.extend({}, $this.defaultoptions, options);
  31. $this.options.callback = callback;
  32. $('#material-Modal').remove();
  33. $(document.body).append($this.buildHtml().mainDialog);
  34. $this.modalobj = $('#material-Modal');
  35. $this.modalobj.find('.modal-header .nav li a').click(function(){
  36. var type = $(this).data('type');
  37. switch(type) {
  38. case 'basic':
  39. $('#material-Modal').addClass('basic');
  40. break;
  41. case 'news':
  42. $('#material-Modal').addClass('news');
  43. break;
  44. case 'music':
  45. $('#material-Modal').addClass('music');
  46. break;
  47. case 'voice':
  48. $('#material-Modal').addClass('voice');
  49. break;
  50. case 'video':
  51. $('#material-Modal').addClass('video');
  52. break;
  53. case 'image':
  54. $('#material-Modal').addClass('image');
  55. break;
  56. case 'keyword':
  57. $('#material-Modal').addClass('keyword');
  58. break;
  59. case 'module':
  60. $('#material-Modal').addClass('module');
  61. break;
  62. }
  63. $this.localPage(type, 1);
  64. $(this).tab('show');
  65. return false;
  66. });
  67. if (!$(this).data('init')) {
  68. if($this.options.type && $this.options.type != 'all') {
  69. $this.modalobj.find('.modal-header .nav li.' + $this.options.type + ' a').trigger('click');
  70. } else {
  71. $this.modalobj.find('.modal-header .nav li.show:first a').trigger('click');
  72. }
  73. }
  74. $this.modalobj.modal('show');
  75. initSelectEmotion();
  76. return $this.modalobj;
  77. },
  78. //newsmodel: 微信素材wx和本地素材local
  79. 'localPage' : function(type, page, newsmodel) {
  80. var $this = this;
  81. var page = page || 1;
  82. $('.checkMedia').removeClass('checkedMedia');
  83. var $content = $this.modalobj.find('.material-content #' + type);
  84. $content.html('<div class="info text-center"><i class="fa fa-spinner fa-pulse fa-lg"></i> 数据加载中</div>');
  85. if(type == 'basic') {
  86. var Dialog = type + 'Dialog';
  87. $this.modalobj.find('#material-footer').show();
  88. $content.html(_.template($this.buildHtml()[Dialog]));
  89. $this.modalobj.find('.modal-footer .btn-primary').unbind('click').click(function(){
  90. var attachment = [];
  91. attachment.content = $('#basictext').val();
  92. $this.options.callback(attachment);
  93. $this.modalobj.modal('hide');
  94. });
  95. return false;
  96. }
  97. if(type == 'music') {
  98. var Dialog = type + 'Dialog';
  99. $this.modalobj.find('#material-footer').show();
  100. $content.html(_.template($this.buildHtml()[Dialog]));
  101. $this.modalobj.find('.modal-footer .btn-primary').unbind('click').click(function(){
  102. var attachment = [];
  103. attachment.title = $(':text[name="musicTitle"]').val();
  104. attachment.url = $(':text[name="musicUrl"]').val();
  105. attachment.HQUrl = $(':text[name="musicHQUrl"]').val();
  106. attachment.description = $(':text[name="musicDescription"]').val();
  107. $this.options.callback(attachment);
  108. $this.modalobj.modal('hide');
  109. });
  110. return false;
  111. }
  112. var url = './index.php?c=utility&a=material&do=list&type=' + type;
  113. if(type == 'wxcard') {
  114. url = './index.php?c=utility&a=coupon&do=wechat';
  115. }
  116. if(type == 'keyword') {
  117. url = './index.php?c=utility&a=keyword&do=keyword&type=all';
  118. }
  119. if(type == 'module') {
  120. url = './index.php?c=utility&a=modules&do=list';
  121. }
  122. if (type == 'news') {
  123. var newsmodel = newsmodel == 'local' ? 'local' : 'wx';
  124. url += newsmodel == 'local' ? '&newsmodel=local' : '&newsmodel=wx';
  125. }
  126. $.getJSON(url, {'page': page}, function(data){
  127. data = data.message.message;
  128. $this.modalobj.find('#material-list-pager').html('');
  129. if(!_.isEmpty(data.items)) {
  130. //$this.modalobj.find('#btn-select').show();
  131. $content.data('attachment', data.items);
  132. $content.empty();
  133. var Dialog = type + 'Dialog';
  134. $content.html(_.template($this.buildHtml()[Dialog])(data));
  135. if(type == 'news') {
  136. setTimeout(function(){
  137. $('.water').wookmark({
  138. align: 'center',
  139. autoResize: false,
  140. container: $('#news'),
  141. autoResize :true
  142. });
  143. }, 100);
  144. $this.modalobj.find('.material-content .newsmodel-type').unbind('click').click(function(){
  145. $(this).addClass('active').siblings().removeClass('active');
  146. $this.localPage(type, 1, $(this).data('type'));
  147. return false;
  148. });
  149. }
  150. $this.selectMedia();
  151. $this.playaudio();
  152. $this.modalobj.find('#material-list-pager').html(data.pager);
  153. $this.modalobj.find('#material-list-pager .pagination a').click(function(){
  154. $this.localPage(type, $(this).attr('page'), newsmodel);
  155. return false;
  156. });
  157. } else {
  158. if (type == 'news') {
  159. $('#news').html('<div role="tabpanel"><div class="tablepanel-top text-right"><button class="btn btn-primary" type="button"><a href="./index.php?c=platform&a=material-post&new_type=reply" target="_blank">图文编辑</a></button> <button class="btn btn-primary" type="button"><a href="./index.php?c=platform&a=material-post&new_type=link" target="_blank">跳转链接</a></button></div><div class="info text-center"><i class="wi wi-info-circle fa-lg"></i> 暂无数据</div></div>');
  160. } else {
  161. $content.html('<div class="info text-center"><i class="wi wi-info-circle fa-lg"></i> 暂无数据</div>');
  162. }
  163. }
  164. if (type == 'news') {
  165. $this.modalobj.find('.material-content .newsmodel-type').unbind('click').click(function(){
  166. $(this).addClass('active').siblings().removeClass('active');
  167. $this.localPage(type, 1, $(this).data('type'));
  168. return false;
  169. });
  170. }
  171. });
  172. $this.modalobj.find('#btn-select .btn-primary').unbind('click').click(function(){
  173. var attachment = [];
  174. $content.find('.checkedMedia').each(function(){
  175. if (type == 'module') {
  176. attachment.push($content.data('attachment')[$(this).data('name')]);
  177. } else {
  178. attachment.push($content.data('attachment')[$(this).data('attachid')]);
  179. }
  180. });
  181. $this.finish(attachment);
  182. });
  183. return false;
  184. },
  185. 'selectMedia' : function(){
  186. var $this = this;
  187. $this.modalobj.find('.checkMedia').unbind('click').click(function(){
  188. if(!$this.options.multiple) {
  189. $('.checkMedia').removeClass('checkedMedia');
  190. }
  191. $(this).addClass('checkedMedia');
  192. var type = $(this).data('type');
  193. if(type == 'news') {
  194. if(!$this.options.multiple) {
  195. $('#news .panel-group').removeClass('selected');
  196. }
  197. $(this).addClass('selected');
  198. } else if(type == 'image') {
  199. if(!$this.options.multiple) {
  200. $('#image div').removeClass('img-item-selected');
  201. }
  202. $(this).addClass('img-item-selected');
  203. } else {
  204. if(!$this.options.multiple) {
  205. $('.checkMedia').removeClass('btn-primary');
  206. }
  207. $(this).addClass('btn-primary');
  208. }
  209. if(!$this.options.multiple) {
  210. $this.modalobj.find('#btn-select .btn-primary').trigger('click');
  211. }
  212. });
  213. },
  214. 'playaudio' : function(){
  215. $("#voice, .panel").on('click', '.audio-player-play', function(){
  216. var src = $(this).data("attach");
  217. if(!src) {
  218. return;
  219. }
  220. if ($("#player")[0]) {
  221. var player = $("#player");
  222. } else {
  223. var player = $('<div id="player"></div>');
  224. $(document.body).append(player);
  225. }
  226. player.data('control', $(this));
  227. player.jPlayer({
  228. playing: function() {
  229. $(this).data('control').find("i").removeClass("fa-play").addClass("fa-stop");
  230. },
  231. pause: function (event) {
  232. $(this).data('control').find("i").removeClass("fa-stop").addClass("fa-play");
  233. },
  234. swfPath: "resource/components/jplayer",
  235. supplied: "mp3,wma,wav,amr",
  236. solution: "html, flash"
  237. });
  238. player.jPlayer("setMedia", {mp3: $(this).data("attach")}).jPlayer("play");
  239. if($(this).find("i").hasClass("fa-stop")) {
  240. player.jPlayer("stop");
  241. } else {
  242. $('.audio-msg').find('.fa-stop').removeClass("fa-stop").addClass("fa-play");
  243. player.jPlayer("setMedia", {mp3: $(this).data("attach")}).jPlayer("play");
  244. }
  245. });
  246. },
  247. 'finish' : function(attachment) {
  248. var $this = this;
  249. if($.isFunction($this.options.callback)) {
  250. if ($this.options.multiple == false) {
  251. $this.options.callback(attachment[0]);
  252. } else {
  253. $this.options.callback(attachment);
  254. }
  255. $this.modalobj.modal('hide');
  256. }
  257. },
  258. 'buildHtml' : function() {
  259. var dialog = {};
  260. dialog['mainDialog'] = '<div id="material-Modal" class="uploader-modal modal fade" tabindex="-1" role="dialog" aria-hidden="true">\n' +
  261. ' <div class="modal-dialog modal-lg">\n' +
  262. ' <div class="modal-content ">\n' +
  263. ' <div class="modal-header">\n' +
  264. ' <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>\n' +
  265. ' <h3>'+
  266. ' <ul role="tablist" class="nav nav-pills" style="font-size:14px; margin-top:-20px;">'+
  267. ' <li role="presentation" class="basic ' + (this.options.ignore.basic ? 'hide' : 'show') + '">'+
  268. ' <a data-toggle="tab" data-type="basic" role="tab" aria-controls="baisc" href="#basic">文字</a>'+
  269. ' </li>'+
  270. ' <li role="presentation" class="news ' + (this.options.ignore.news ? 'hide' : 'show') + '">'+
  271. ' <a data-toggle="tab" data-type="news" role="tab" aria-controls="news" href="#news">图文</a>'+
  272. ' </li>'+
  273. ' <li role="presentation" class="image ' + (this.options.ignore.image ? 'hide' : 'show') + '">'+
  274. ' <a data-toggle="tab" data-type="image" role="tab" aria-controls="image" href="#image">图片</a>'+
  275. ' </li>'+
  276. ' <li role="presentation" class="music ' + (this.options.ignore.music ? 'hide' : 'show') + '">'+
  277. ' <a data-toggle="tab" data-type="music" role="tab" aria-controls="music" href="#music">音乐</a>'+
  278. ' </li>'+
  279. ' <li role="presentation" class="voice ' + (this.options.ignore.voice ? 'hide' : 'show') + '">'+
  280. ' <a data-toggle="tab" data-type="voice" role="tab" aria-controls="voice" href="#voice">语音</a>'+
  281. ' </li>'+
  282. ' <li role="presentation" class="video ' + (this.options.ignore.video ? 'hide' : 'show') + '">'+
  283. ' <a data-toggle="tab" data-type="video" role="tab" aria-controls="video" href="#video">视频</a>'+
  284. ' </li>'+
  285. ' <li role="presentation" class="wxcard ' + (this.options.ignore.wxcard ? 'hide' : 'show') + '">'+
  286. ' <a data-toggle="tab" data-type="wxcard" role="tab" aria-controls="wxcard" href="#wxcard">微信卡券</a>'+
  287. ' </li>'+
  288. ' <li role="presentation" class="keyword ' + (this.options.ignore.keyword ? 'hide' : 'show') + '">'+
  289. ' <a data-toggle="tab" data-type="keyword" role="tab" aria-controls="keyword" href="#keyword">关键字</a>'+
  290. ' </li>'+
  291. ' <li role="presentation" class="module ' + (this.options.ignore.module ? 'hide' : 'show') + '">'+
  292. ' <a data-toggle="tab" data-type="module" role="tab" aria-controls="module" href="#module">模块</a>'+
  293. ' </li>'+
  294. ' </ul>'+
  295. ' </h3>'+
  296. ' </div>\n' +
  297. ' <div class="modal-body material-content clearfix">\n' +
  298. (this.options.ignore.news ? '' :
  299. ' <ul class="nav nav-pills nav-stacked">'+
  300. (this.options.others.news.showwx ?
  301. ' <li role="presentation" data-type="wx" class="newsmodel-type active">微信</li>' : '') +
  302. (this.options.others.news.showlocal ?
  303. ' <li role="presentation" data-type="local" class="newsmodel-type">服务器</li>' : '') +
  304. ' </ul>') +
  305. ' <div class="material-head">'+
  306. ' <a class="btn btn-primary active we7-margin-vertical-sm active pull-right ' + (this.options.ignore.image ? 'hide' : 'show') + '" href="./index.php?c=platform&a=material&type=image" target="_blank">上传图片</a>'+
  307. ' <a class="btn btn-primary active we7-margin-vertical-sm active pull-right ' + (this.options.ignore.voice ? 'hide' : 'show') + '" href="./index.php?c=platform&a=material&type=voice" target="_blank">新建语音</a>'+
  308. ' <a class="btn btn-primary active we7-margin-vertical-sm active pull-right ' + (this.options.ignore.video ? 'hide' : 'show') + '" href="./index.php?c=platform&a=material&type=video" target="_blank">新建视频</a>'+
  309. ' <a class="btn btn-primary active we7-margin-vertical-sm active pull-right ' + (this.options.ignore.wxcard ? 'hide' : 'show') + '" href="./index.php?c=activity&a=coupon&do=display" target="_blank">新建卡券</a>'+
  310. ' <a class="btn btn-primary active we7-margin-vertical-sm pull-right ' + (this.options.ignore.keyword ? 'hide' : 'show') + '" href="./index.php?c=platform&a=reply&do=post&m=keyword" target="_blank">新建关键字</a>'+
  311. ' </div>'+
  312. ' <div class="tab-content">'+
  313. ' <div id="basic" class="tab-pane" role="tabpanel"></div>'+
  314. ' <div id="news" class="tab-pane material clearfix" class="active" role="tabpanel" style="position:relative"></div>'+
  315. ' <div id="image" class="tab-pane history" role="tabpanel"></div>'+
  316. ' <div id="music" class="tab-pane history" role="tabpanel"></div>'+
  317. ' <div id="voice" class="tab-pane" role="tabpanel"></div>'+
  318. ' <div id="video" class="tab-pane" role="tabpanel"></div>'+
  319. ' <div id="wxcard" class="tab-pane" role="tabpanel"></div>'+
  320. ' <div id="keyword" class="tab-pane" role="tabpanel"></div>'+
  321. ' <div id="module" class="tab-pane history" role="tabpanel"></div>'+
  322. ' </div>' +
  323. ' <nav id="material-list-pager" class="text-right we7-margin-vertical we7-padding-right">\n' +
  324. ' </nav>\n' +
  325. ' </div>\n' +
  326. ' <div class="modal-footer" id="material-footer" style="display: none">\n' +
  327. ' <div id="btn-select">\n' +
  328. ' <span class="btn btn-default" data-dismiss="modal">取消</span>\n' +
  329. ' <span class="btn btn-primary">确认</span>\n' +
  330. ' </div>\n' +
  331. ' </div>\n'+
  332. ' </div>\n' +
  333. ' </div>\n' +
  334. '</div>';
  335. dialog['basicDialog'] = '<div class="help-block">'+
  336. ' 您还可以使用表情和链接。'+
  337. ' <a class="emotion-triggers" href="javascript:;"><i class="fa fa-github-alt"></i> 表情</a>'+
  338. ' <a class="emoji-triggers" href="javascript:;" onclick="initSelectEmoji()" title="添加表情"><i class="fa fa-github-alt"></i> Emoji</a>'+
  339. ' </div>'+
  340. ' <textarea id="basictext" cols="116" rows="10">'+ (this.options.others.basic.typeVal ? this.options.others.basic.typeVal : "") +'</textarea>';
  341. dialog['imageDialog'] = '<ul class="img-list clearfix">\n' +
  342. '<%var items = _.sortBy(items, function(item) {return -item.id;});%>' +
  343. '<%_.each(items, function(item) {%> \n' +
  344. '<div class="checkMedia" data-media="<%=item.media_id%>" data-type="image" data-attachid="<%=item.id%>">' +
  345. ' <li class="img-item" style="padding:5px">\n' +
  346. ' <div class="img-container" style="background-image: url(\'<%=item.attach%>\');">\n' +
  347. ' <div class="select-status"><span></span></div>\n' +
  348. ' </div>\n' +
  349. ' </li>\n' +
  350. '</div>\n' +
  351. '<%});%>\n' +
  352. '</ul>';
  353. dialog['musicDialog'] = '<div class="form-group">'+
  354. ' <div class="col-xs-2">音乐标题</div>'+
  355. ' <div class="col-xs-10 input-group">'+
  356. ' <input type="text" value="" name="musicTitle" class="form-control" placeholder="添加音乐消息的标题">'+
  357. ' </div>'+
  358. '</div>'+
  359. '<div class="form-group">'+
  360. ' <div class="col-xs-2">选择音乐</div>'+
  361. ' <div class="col-xs-10 input-group">'+
  362. ' <input type="text" value="" name="musicUrl" class="form-control audio-player-media" autocomplete="off">'+
  363. ' <span class="help-block">选择上传的音频文件或直接输入URL地址,常用格式:mp3</span>'+
  364. ' <span class="input-group-btn" style="vertical-align: top;">'+
  365. ' <button class="btn btn-default audio-player-play" type="button" style="display:none;"><i class="fa fa-play"></i></button>'+
  366. ' <button class="btn btn-default" type="button" onclick="showAudioDialog(this);">选择媒体文件</button>'+
  367. ' </span>'+
  368. ' </div>'+
  369. ' <div class="input-group audio-player"></div>'+
  370. '</div>'+
  371. '<div class="form-group">'+
  372. ' <div class="col-xs-2">高品质链接</div>'+
  373. ' <div class="col-xs-10 input-group">'+
  374. ' <input type="text" value="" name="musicHQUrl" class="form-control">'+
  375. ' <span class="help-block">没有高品质音乐链接,请留空。高质量音乐链接,WIFI环境优先使用该链接播放音乐</span>'+
  376. ' </div>'+
  377. '</div>'+
  378. '<div class="form-group">'+
  379. ' <div class="col-xs-2">描述</div>'+
  380. ' <div class="col-xs-10 input-group">'+
  381. ' <input type="text" value="" name="musicDescription" class="form-control">'+
  382. ' <span class="help-block">描述内容将出现在音乐名称下方,建议控制在20个汉字以内最佳</span>'+
  383. ' </div>'+
  384. '</div>';
  385. dialog['voiceDialog'] ='<table class="table table-hover we7-table" style="margin-bottom:0">'+
  386. ' <col width=""/>'+
  387. ' <col width="150px"/>'+
  388. ' <col width="180px"/>'+
  389. ' <thead class="navbar-inner">'+
  390. ' <tr>'+
  391. ' <th>标题</th>'+
  392. ' <th style="text-align:center">创建时间</th>'+
  393. ' <th style="text-align:center"></th>'+
  394. ' </tr>'+
  395. ' </thead>'+
  396. ' <tbody class="history-content">'+
  397. ' <%var items = _.sortBy(items, function(item) {return -item.createtime;});%>' +
  398. ' <%_.each(items, function(item) {%> \n' +
  399. ' <tr>'+
  400. ' <td><%=item.filename%></td>'+
  401. ' <td align="center"><%=item.createtime_cn%></td>'+
  402. ' <td align="center">'+
  403. ' <div class="btn-group">'+
  404. ' <a href="javascript:;" class="btn btn-default btn-sm audio-player-play audio-msg" data-attach="<%=item.attach%>"><i class="fa fa-play"></i></a>'+
  405. ' <a href="javascript:;" class="btn btn-default btn-sm checkMedia" data-media="<%=item.media_id%>" data-type="voice" data-attachid="<%=item.id%>">选取</a>'+
  406. ' </div>'+
  407. ' </td>'+
  408. ' </tr>'+
  409. ' <%});%>' +
  410. ' </tbody>'+
  411. ' </table>';
  412. dialog['videoDialog'] ='<table class="table table-hover we7-table" style="margin-bottom:0">'+
  413. ' <col width=""/>'+
  414. ' <col width="150px"/>'+
  415. ' <col width="180px"/>'+
  416. ' <thead class="navbar-inner">'+
  417. ' <tr>'+
  418. ' <th>标题</th>'+
  419. ' <th style="text-align:center">创建时间</th>'+
  420. ' <th style="text-align:center"></th>'+
  421. ' </tr>'+
  422. ' </thead>'+
  423. ' <tbody class="history-content">'+
  424. ' <%var items = _.sortBy(items, function(item) {return -item.createtime;});%>' +
  425. ' <%_.each(items, function(item) {%> \n' +
  426. ' <tr>'+
  427. ' <%if(item.tag.title) {var title = item.tag.title} else {var title =item.filename}%>'+
  428. ' <td><%=title%></td>'+
  429. ' <td align="center"><%=item.createtime_cn%></td>'+
  430. ' <td align="center">'+
  431. ' <div class="btn-group">'+
  432. ' <a href="javascript:;" class="btn btn-default btn-sm checkMedia" data-media="<%=item.media_id%>" data-type="video" data-attachid="<%=item.id%>">选取</a>'+
  433. ' </div>'+
  434. ' </td>'+
  435. ' </tr>'+
  436. ' <%});%>' +
  437. ' </tbody>'+
  438. ' </table>';
  439. dialog['wxcardDialog'] ='<table class="table table-hover we7-table">\n'+
  440. ' <thead>\n'+
  441. ' <tr>\n'+
  442. ' <th width="130" class="text-center">标题</th>\n'+
  443. ' <th class="text-center">类型</th>\n'+
  444. ' <th width="250" class="text-center">卡券有效期</th>\n'+
  445. ' <th class="text-center">库存/每人限领</th>\n'+
  446. ' <th class="text-center">操作</th>\n'+
  447. ' </tr>'+
  448. ' </thead>'+
  449. ' <tbody>'+
  450. ' <%var items = _.sortBy(items, function(item) {return -item.couponid;});%>' +
  451. ' <%_.each(items, function(item) {%> \n' +
  452. ' <tr title="<%=item.title%>">' +
  453. ' <td><%=item.title%></td>' +
  454. ' <td><%if(item.ctype == "discount") {%><span class="label label-success">折扣券</span><%} else if(item.ctype == "cash") {%><span class="label label-danger">代金券</span><%} else if(item.ctype == "gift") {%><span class="label label-danger">礼品券</span><%} else if(item.ctype == "groupon") {%><span class="label label-danger">团购券</span><%} else if(item.ctype == "general_coupon") {%><span class="label label-danger">优惠券</span><%}%></td>' +
  455. ' <td><%if(item.date_info.time_type == 1) {%><%=item.date_info.time_limit_start%> ~ <%=item.date_info.time_limit_end%><%} else {%>领取后<%=item.date_info.date_info%>天后生效,<%=item.date_info.limit%>天有效期<%}%></td>' +
  456. ' <td><%=item.quantity%>/<strong class="text-danger"><%=item.get_limit%></strong></td>' +
  457. ' <td><a href="javascript:;" class="btn btn-default btn-sm checkMedia" data-title="<%=item.title%>" data-type="wxcard" data-media="<%=item.card_id%>" data-attachid="<%=item.id%>">选取</a></td>' +
  458. ' </tr>' +
  459. ' <%});%>' +
  460. ' </tbody>'+
  461. ' </table>';
  462. dialog['newsDialog'] = '<div role="tabpanel">'+
  463. ' <div class="tablepanel-top text-right">'+
  464. ' <button class="btn btn-primary" type="button"><a href="./index.php?c=platform&a=material-post&new_type=reply" target="_blank">图文编辑</a></button>'+
  465. '<button class="btn btn-primary" style="margin-left:10px" type="button"><a href="./index.php?c=platform&a=material-post&new_type=link" target="_blank">跳转链接</a></button>'+
  466. ' </div>'+
  467. ' <div class="tablepanel-con">'+
  468. ' <div class="graphic-list material clearfix" style="position: relative;">'+
  469. ' <%var items = _.sortBy(items, function(item) {return -item.createtime;});%>' +
  470. ' <%_.each(items, function(item) {%> \n' +
  471. ' <div class="col-md-5 water">'+
  472. ' <div class="panel-group checkMedia" data-media="<%=item.media_id%>" data-type="news" data-attachid="<%=item.id%>">'+
  473. ' <%var index = 0;%>\n' +
  474. ' <%_.each(item.items, function(data) {%>\n' +
  475. ' <%index++;%>\n' +
  476. ' <div class="panel panel-default">'+
  477. ' <%if(index == 1) {%>\n' +
  478. ' <div class="panel-body">'+
  479. ' <div class="img">'+
  480. ' <i class="default">封面图片</i>'+
  481. ' <img src="<%=data.thumb_url%>" width="100%">'+
  482. ' <span class="text-left"><%=data.title%></span>'+
  483. ' </div>'+
  484. ' </div>'+
  485. ' <%} else {%>\n' +
  486. ' <div class="panel-body">'+
  487. ' <div class="text">'+
  488. ' <h4><%=data.title%></h4>'+
  489. ' </div>'+
  490. ' <div class="img">'+
  491. ' <img src="<%=data.thumb_url%>">'+
  492. ' <i class="default">缩略图</i>'+
  493. ' </div>'+
  494. ' </div>'+
  495. ' <%}%>\n' +
  496. ' </div>'+
  497. ' <%});%>'+
  498. ' <div class="mask"></div>'+
  499. ' <i class="fa fa-check"></i>'+
  500. ' </div>'+
  501. ' </div>'+
  502. ' <%});%>'+
  503. ' </div>'+
  504. ' </div>'+
  505. ' </div>';
  506. dialog['keywordDialog'] = '<div class="row">\n'+
  507. '<%_.each(items, function(item) {%>' +
  508. ' <div class="col-sm-2">'+
  509. ' <a href="javascript:;" class="checkMedia" data-media="<%=item.media_id%>" data-type="keyword" data-attachid="<%=item.id%>">'+
  510. ' <span>'+
  511. ' <%=item.content%>' +
  512. ' </span>'+
  513. ' </a>'+
  514. ' </div>'+
  515. '<%});%>'+
  516. '</div>';
  517. dialog['moduleDialog'] = '<ul class="img-list clearfix">\n' +
  518. '<%var items = _.sortBy(items, function(item) {return -item.id;});%>' +
  519. '<%_.each(items, function(item) {%> \n' +
  520. '<div class="checkMedia" data-name="<%=item.name%>" data-type="module">' +
  521. ' <li class="img-item" style="padding:5px">\n' +
  522. ' <div class="img-container">\n' +
  523. ' <img src="<%=item.icon%>" width="48px" height="48px">\n' +
  524. ' <div class="text-over"><%=item.title%></div>\n' +
  525. ' <div class="select-status"><span></span></div>\n' +
  526. ' </div>\n' +
  527. ' </li>\n' +
  528. '</div>\n' +
  529. '<%});%>\n' +
  530. '</ul>';
  531. return dialog;
  532. }
  533. };
  534. initSelectEmotion = function() {
  535. var $t = $('#basictext')[0];
  536. var textbox = $("#basictext").val();
  537. util.emotion($('.emotion-triggers'), $("#basictext"), function(txt, elm, target){
  538. if ($t.selectionStart || $t.selectionStart == '0') {
  539. var startPos = $t.selectionStart;
  540. var endPos = $t.selectionEnd;
  541. var scrollTop = $t.scrollTop;
  542. $("#basictext").val($t.value.substring(0, startPos) + txt + $t.value.substring(endPos, $t.value.length));
  543. $("#basictext").focus();
  544. $t.selectionStart = startPos + txt.length;
  545. $t.selectionEnd = startPos + txt.length;
  546. $t.scrollTop = scrollTop;
  547. }
  548. else {
  549. $("#basictext").val(textbox+txt);
  550. $("#basictext").focus();
  551. }
  552. });
  553. };
  554. initSelectEmoji = function() {
  555. var textbox = $("#basictext").val();
  556. util.emojiBrowser(function(emoji){
  557. var unshift = '[U+' + emoji.find("span").text() + ']';
  558. $("#basictext").val(textbox+unshift);
  559. });
  560. };
  561. showAudioDialog = function(elm, base64options, options) {
  562. var btn = $(elm);
  563. var ipt = btn.parent().prev().prev();
  564. var val = ipt.val();
  565. util.audio(val, function(url){
  566. if(url && url.attachment && url.url){
  567. btn.prev().show();
  568. ipt.val(url.attachment);
  569. ipt.attr("filename",url.filename);
  570. ipt.attr("url",url.url);
  571. setAudioPlayer();
  572. }
  573. if(url && url.media_id){
  574. ipt.val(url.media_id);
  575. }
  576. }, "" , {"direct": true, "multiple": false});
  577. };
  578. setAudioPlayer = function(){
  579. $(function(){
  580. $(".audio-player").each(function(){
  581. $(this).prev().find("button").eq(0).click(function(){
  582. var src = $(this).parent().prev().prev().val();
  583. if($(this).find("i").hasClass("fa-stop")) {
  584. $(this).parent().parent().next().jPlayer("stop");
  585. } else {
  586. if(src) {
  587. $(this).parent().parent().next().jPlayer("setMedia", {mp3: util.tomedia(src)}).jPlayer("play");
  588. }
  589. }
  590. });
  591. });
  592. $(".audio-player").jPlayer({
  593. playing: function() {
  594. $(this).prev().find("i").removeClass("fa-play").addClass("fa-stop");
  595. },
  596. pause: function (event) {
  597. $(this).prev().find("i").removeClass("fa-stop").addClass("fa-play");
  598. },
  599. swfPath: "resource/components/jplayer",
  600. supplied: "mp3"
  601. });
  602. $(".audio-player-media").each(function(){
  603. $(this).next().find(".audio-player-play").css("display", $(this).val() == "" ? "none" : "");
  604. });
  605. });
  606. };
  607. return material;
  608. });