addShow.html 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362
  1. <style>
  2. body {font-family: 'Arial Normal', 'Arial'; font-size: 13px; margin: 0px; padding: 0px;}
  3. /*自定义的layer样式*/
  4. .plusForm .content div{margin-bottom: 0px;}
  5. .plusForm div.btn {padding: 0px; }
  6. #filePicker>.webuploader-pick{background: none; color: #000000; padding: 0px; height: 34px; line-height: 34px; width: 98px; border: none;}
  7. #filePicker input{height: 34px;}
  8. .require{color:#f60000; display: inline-block; }
  9. .plusForm .content input.uploadFile,textarea{text-indent: 4px; margin-bottom: 0px;}
  10. .plusForm .content select{width: 150px; margin-bottom: 4px; line-height:24px; height: 24px; }
  11. .plusForm .content .form-box{ margin-bottom: 16px;}
  12. .plusForm .content .form-title{margin-bottom: 4px;}
  13. .plusForm .content .select-group{width: 31.8%; float: left; margin-bottom: 4px;}
  14. .select-group .form-title{font-size: 12px;color: #999;}
  15. </style>
  16. <div class="plusForm">
  17. <div>
  18. <div class="title">Add Show</div>
  19. <div class="close"><a href="javascript:;"><img src="<%=public_path%>/img/close-btn.png" alt=""/></a></div>
  20. </div>
  21. <div class="content">
  22. <div class="form-box">
  23. <div class="form-title"><div class="require">*</div> Show title:</div>
  24. <input id="title" class="uploadFile" name="title" maxlength="30" placeholder="30 characters limited" style="width:100%; height: 24px;">
  25. </div>
  26. <div class="form-box">
  27. <div class="form-title"><div class="require">*</div> Show type:</div>
  28. <select name="type" style="width:220px;">
  29. <option selected="" value="1">Singing</option>
  30. <option value="2">Dancing</option>
  31. <option value="3">Playing instrument</option>
  32. <option value="4">Cooking</option>
  33. <option value="5">Talk show</option>
  34. <option value="6">Sports</option>
  35. <option value="7">Outdoor activities</option>
  36. <option value="8">Painting</option>
  37. <option value="9">Others</option>
  38. </select>
  39. </div>
  40. <div class="form-box">
  41. <div class="form-title"><div class="require">*</div> Show description <label>(48 - 140 characters.)</label></div>
  42. <textarea name="introduction" maxlength="140" placeholder="" style="width: 488px; height:100px; resize: none;"></textarea>
  43. <div class="tips" style="float: right;"><label id="descriptionNumber" style="color: red;">0</label> / 140</div>
  44. <div class="clear"></div>
  45. </div>
  46. <div class="form-box">
  47. <div class="form-title"><div class="require">*</div> Start time:</div>
  48. <div class="select-group">
  49. <div class="form-title">Date</div>
  50. <select id="date" name="date">
  51. </select>
  52. </div>
  53. <div class="select-group">
  54. <div class="form-title">Hour</div>
  55. <select id="hour" name="hour">
  56. </select>
  57. </div>
  58. <div class="select-group">
  59. <div class="form-title">Minute</div>
  60. <select id="min" name="min">
  61. </select>
  62. </div>
  63. <div class="select-group">
  64. <div class="form-title"><div class="require">*</div> Duration</div>
  65. <select name="duration">
  66. <option value="10" selected="selected">10 minutes</option>
  67. <option value="15">15 minutes</option>
  68. <option value="20">20 minutes</option>
  69. </select>
  70. </div>
  71. <div style="clear:both;"></div>
  72. </div>
  73. <div class="form-box">
  74. <div>Show cover <label>(PNG, JPEG and JPG format only, less than 6MB. Image size must be between 640 * 640 pixel and 6000 * 6000 pixel.)</label></div>
  75. <input class="uploadFile" id="uploadFile" disabled="disabled" style="background: none;" placeholder=""/>
  76. <div class="fileUpload btn btn-primary" style="margin-bottom: 2px; height: 34px; line-height: 34px;">
  77. <div id="filePicker">Browse photo</div>
  78. <input type="hidden" name="img" value="">
  79. <input type="hidden" name="handle_id" value="">
  80. </div>
  81. </div>
  82. <button class="Submit cursor">Submit</button>
  83. <img id="text" src="">
  84. <p style="color: #666666; margin-top: 10px;">Note: If you don't show up at the show, a certain amount of coins will be deducted from your income.</p>
  85. </div>
  86. </div>
  87. <script>
  88. Date.prototype.format = function(fmt) {
  89. var o = {
  90. "M+" : this.getMonth()+1, //月份
  91. "d+" : this.getDate(), //日
  92. "h+" : this.getHours()%12 == 0 ? 12 : this.getHours()%12, //小时
  93. "H+" : this.getHours(), //小时
  94. "m+" : this.getMinutes(), //分
  95. "s+" : this.getSeconds(), //秒
  96. "q+" : Math.floor((this.getMonth()+3)/3), //季度
  97. "S" : this.getMilliseconds() //毫秒
  98. };
  99. var week = {
  100. "0" : "/u65e5",
  101. "1" : "/u4e00",
  102. "2" : "/u4e8c",
  103. "3" : "/u4e09",
  104. "4" : "/u56db",
  105. "5" : "/u4e94",
  106. "6" : "/u516d"
  107. };
  108. if(/(y+)/.test(fmt)){
  109. fmt=fmt.replace(RegExp.$1, (this.getFullYear()+"").substr(4 - RegExp.$1.length));
  110. }
  111. if(/(E+)/.test(fmt)){
  112. fmt=fmt.replace(RegExp.$1, ((RegExp.$1.length>1) ? (RegExp.$1.length>2 ? "/u661f/u671f" : "/u5468") : "")+week[this.getDay()+""]);
  113. }
  114. for(var k in o){
  115. if(new RegExp("("+ k +")").test(fmt)){
  116. fmt = fmt.replace(RegExp.$1, (RegExp.$1.length==1) ? (o[k]) : (("00"+ o[k]).substr((""+ o[k]).length)));
  117. }
  118. }
  119. return fmt;
  120. }
  121. Date.getDayOfMonth = function(y, Mm) {
  122. if (typeof y == 'undefined') { y = (new Date()).getFullYear(); }
  123. if (typeof Mm == 'undefined') { Mm = (new Date()).getMonth(); }
  124. var Feb = (y % 4 == 0) ? 29 : 28;
  125. var aM = new Array(31, Feb, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
  126. return aM[Mm];
  127. };
  128. Date.getLastMonth = function() {
  129. var dt = new Date();
  130. var y = (dt.getMonth() == 0) ? (dt.getFullYear() - 1) : dt.getFullYear();
  131. var m = (dt.getMonth() == 0) ? 11 : dt.getMonth() - 1;
  132. var preM = Date.getDayOfMonth(y,m);
  133. var d = (preM < dt.getDate()) ? preM : dt.getDate();
  134. var new_time = new Date(y,m,d).format("yyyy-MM-dd HH:mm:ss");
  135. return new_time;
  136. };
  137. var date_list = [];
  138. var date_hour_dic = {};
  139. var datehour_min_dic = {};
  140. $(function() {
  141. var time_list = [<%=time_list%>];
  142. for (var i = 0; i < time_list.length; i++) {
  143. var time = new Date();
  144. time.setTime(time_list[i]*1000);
  145. var date_str = time.format("yyyy-MM-dd");
  146. var datehour_str = time.format("yyyy-MM-dd HH");
  147. var min = time.format("yyyy-MM-dd HH:mm");
  148. if (date_str in date_hour_dic) {
  149. var value = date_hour_dic[date_str];
  150. value[datehour_str] = 1;
  151. } else {
  152. var value = {};
  153. value[datehour_str] = 1;
  154. date_hour_dic[date_str] = value;
  155. }
  156. if (datehour_str in datehour_min_dic) {
  157. var value = datehour_min_dic[datehour_str];
  158. value[min] = time_list[i];
  159. } else {
  160. var value = {};
  161. value[min] = time_list[i];
  162. datehour_min_dic[datehour_str] = value;
  163. }
  164. }
  165. filHourMinByDate = function(date) {
  166. $("#hour").empty();
  167. $("#min").empty();
  168. var fir_hour = "";
  169. var fir_date_value = date_hour_dic[date];
  170. for (var key in fir_date_value) {
  171. var hour = key.split(" ")[1];
  172. var option = $("<option>").val(key).text(hour);
  173. $("#hour").append(option);
  174. if (fir_hour == "") fir_hour = key;
  175. }
  176. var fir_hour_value = datehour_min_dic[fir_hour];
  177. for (var k in fir_hour_value) {
  178. var v = fir_hour_value[k];
  179. var min = k.split(" ")[1].split(":")[1];
  180. var option = $("<option>").val(v).text(min);
  181. $("#min").append(option);
  182. }
  183. }
  184. filMinByHour = function(hour) {
  185. $("#min").empty();
  186. var fir_hour_value = datehour_min_dic[hour];
  187. for (var k in fir_hour_value) {
  188. var v = fir_hour_value[k];
  189. var min = k.split(" ")[1].split(":")[1];
  190. var option = $("<option>").val(v).text(min);
  191. $("#min").append(option);
  192. }
  193. }
  194. var fir_date = "";
  195. for (var date in date_hour_dic) {
  196. var option = $("<option>").val(date).text(date);
  197. $("#date").append(option);
  198. if (fir_date == "") fir_date = date;
  199. }
  200. filHourMinByDate(fir_date);
  201. $("#date").change(function(){
  202. var sel = $(this).children('option:selected').val();
  203. filHourMinByDate(sel);
  204. });
  205. $("#hour").change(function(){
  206. var sel = $(this).children('option:selected').val();
  207. filMinByHour(sel);
  208. });
  209. $('textarea[name="introduction"]').on('input', function(){
  210. let description = $(this).val();
  211. $('#descriptionNumber').text(description.length);
  212. })
  213. var index = parent.layer.getFrameIndex(window.name);
  214. parent.layer.iframeAuto(index);
  215. $('.close').click(function(){
  216. parent.layer.close(index);
  217. })
  218. var change_status = 0;//防止多次点击
  219. $('.Submit').click(function() {
  220. if(change_status){
  221. return false;
  222. }
  223. change_status = 1;
  224. var title = $('input[name="title"]').val();
  225. var classify = $('select[name="type"]').val();
  226. var introduce = $('textarea[name="introduction"]').val();
  227. var cover = $('input[name="img"]').val();
  228. var handle_id = $('input[name="handle_id"]').val();
  229. var start_time = $('select[name="min"]').val();
  230. var duration = $('select[name="duration"]').val();
  231. title = $.trim(title);
  232. introduce = $.trim(introduce);
  233. if(!title){
  234. myParentAlert("Show title is required.");
  235. change_status = 0;
  236. return false;
  237. }
  238. if(title.length > 30){
  239. myParentAlert("Show title can not exceed 30 characters.");
  240. change_status = 0;
  241. return false;
  242. }
  243. if(introduce.length < 48){
  244. myParentAlert("Description must be at least 48 characters.");
  245. change_status = 0;
  246. return false;
  247. }
  248. if(introduce.length > 140){
  249. myParentAlert("Description can not exceed 140 characters.");
  250. change_status = 0;
  251. return false;
  252. }
  253. var anchorTimezoneLiveShow = new Date();
  254. $.post('/lady/v1/addProgram',
  255. {title:title,classify:classify,introduce:introduce,cover:cover,handle_id:handle_id,start_time:start_time,duration:duration,anchorTimezoneLiveShow:anchorTimezoneLiveShow.toString()},
  256. function(data){
  257. if(data.errno == 0) {
  258. Cookies.set('add_success_show', {status:1});
  259. parent.layer.close(index);
  260. parent.layer.msg('Submit successfully. Auditing soon');
  261. }else{
  262. myParentAlert(data.errmsg);
  263. change_status = 0;
  264. }
  265. })
  266. })
  267. //创建文件上传
  268. var uploader = WebUploader.create({
  269. auto: true,
  270. fileSingleSizeLimit: 1024*1024*6,//最大只能上传6M
  271. swf: '<%=public_path%>' + '/js/webuploader/Uploader.swf',
  272. server: '<%=server_host%>/api/?act=uploadShowCoverStepa',
  273. pick: '#filePicker',
  274. accept: {
  275. title: 'Images',
  276. extensions: 'jpg,jpeg,png',
  277. mimeTypes: 'image/jpg,image/jpeg,image/png'
  278. },
  279. compress: null
  280. });
  281. // 图片上传中
  282. var uploadProgress = 0;//防止重复提示
  283. var load = '';
  284. uploader.on( 'uploadProgress', function( file, percentage ) {
  285. if (!uploadProgress) {
  286. load = layer.load(2);
  287. }
  288. uploadProgress = 1//等于1表示不上传动作已经开启
  289. });
  290. //图片上传成功
  291. uploader.on( 'uploadSuccess', function( file, response) {
  292. if(response.errno != 0){
  293. myParentAlert("Image size must be between 640 * 640 pixel and 6000 * 6000 pixel.");
  294. }
  295. uploader.removeFile(file);//从队列中移除上传的文件,以便可以重复上传
  296. var data = response.data;
  297. if(response.errno == 0){
  298. $('#uploadFile').val(file.name);
  299. $('input[name="img"]').val(data.url.file);
  300. $('input[name="handle_id"]').val(response.handle_id);
  301. }
  302. uploadProgress =0;//重置开关
  303. layer.close(load);
  304. });
  305. //文件上传失败
  306. uploader.on( 'uploadError', function( file ) {
  307. myParentAlert("Failed to upload. Please try again.");
  308. uploadProgress = 0;//重置开关
  309. layer.close(load);
  310. });
  311. //错误提示
  312. uploader.on("error", function (type) {
  313. if(type == "Q_TYPE_DENIED"){
  314. myParentAlert("Invalid show cover. PNG, JPEG and JPG format only, less than 6MB.");
  315. }
  316. if(type == "F_EXCEED_SIZE"){
  317. myParentAlert("Invalid show cover. PNG, JPEG and JPG format only, less than 6MB.");
  318. }
  319. });
  320. })
  321. </script>