add-show.js 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835
  1. /**
  2. *
  3. * Schedule Dialog creation methods.
  4. *
  5. */
  6. function openAddShowForm() {
  7. if($("#add-show-form").length == 1) {
  8. if( ($("#add-show-form").css('display')=='none')) {
  9. $("#add-show-form").show();
  10. /*
  11. var windowWidth = $(window).width();
  12. // margin on showform are 16 px on each side
  13. var calendarWidth = 100-(($("#schedule-add-show").width() + (16 * 4))/windowWidth*100);
  14. var widthPercent = parseInt(calendarWidth)+"%";
  15. $("#schedule_calendar").css("width", widthPercent);
  16. // 200 px for top dashboard and 50 for padding on main content
  17. // this calculation was copied from schedule.js line 326
  18. var mainHeight = document.documentElement.clientHeight - 200 - 50;
  19. $('#schedule_calendar').fullCalendar('option', 'contentHeight', mainHeight);
  20. */
  21. windowResize();
  22. }
  23. $("#schedule-show-what").show(0, function(){
  24. $add_show_name = $("#add_show_name");
  25. $add_show_name.focus();
  26. $add_show_name.select();
  27. });
  28. }
  29. }
  30. function makeAddShowButton(){
  31. $('.fc-header-left')
  32. .append('<span class="fc-header-space"></span>')
  33. .append('<span class="fc-button"><a href="#" class="add-button"><span class="add-icon"></span>'+$.i18n._("Show")+'</a></span>')
  34. .find('span.fc-button:last > a')
  35. .click(function(){
  36. openAddShowForm();
  37. removeAddShowButton();
  38. });
  39. }
  40. function removeAddShowButton(){
  41. var aTag = $('.fc-header-left')
  42. .find("span.fc-button:last > a");
  43. var span = aTag.parent();
  44. span.prev().remove();
  45. span.remove();
  46. }
  47. //$el is DOM element #add-show-form
  48. //form is the new form contents to append to $el
  49. function redrawAddShowForm($el, form) {
  50. //need to clean up the color picker.
  51. $el.find("#schedule-show-style input").each(function(i, el){
  52. var $input = $(this),
  53. colId = $input.data("colorpickerId");
  54. $("#"+colId).remove();
  55. $input.removeData();
  56. });
  57. $el.empty().append(form);
  58. setAddShowEvents($el);
  59. }
  60. function closeAddShowForm(event) {
  61. event.stopPropagation();
  62. event.preventDefault();
  63. var $el = $("#add-show-form");
  64. $el.hide();
  65. windowResize();
  66. $.get(baseUrl+"Schedule/get-form", {format:"json"}, function(json) {
  67. redrawAddShowForm($el, json.form);
  68. });
  69. makeAddShowButton();
  70. }
  71. //dateText mm-dd-yy
  72. function startDpSelect(dateText, inst) {
  73. var time, date;
  74. time = dateText.split("-");
  75. date = new Date(time[0], time[1] - 1, time[2]);
  76. if (inst.input)
  77. inst.input.trigger('input');
  78. }
  79. function endDpSelect(dateText, inst) {
  80. var time, date;
  81. time = dateText.split("-");
  82. date = new Date(time[0], time[1] - 1, time[2]);
  83. if (inst.input)
  84. inst.input.trigger('input');
  85. }
  86. function createDateInput(el, onSelect) {
  87. var date;
  88. el.datepicker({
  89. minDate: adjustDateToServerDate(new Date(), timezoneOffset),
  90. onSelect: onSelect,
  91. dateFormat: 'yy-mm-dd',
  92. //i18n_months, i18n_days_short are in common.js
  93. monthNames: i18n_months,
  94. dayNamesMin: i18n_days_short,
  95. closeText: $.i18n._('Close'),
  96. //showButtonPanel: true,
  97. firstDay: calendarPref.weekStart
  98. });
  99. }
  100. function autoSelect(event, ui) {
  101. $("#add_show_hosts-"+ui.item.index).attr("checked", "checked");
  102. event.preventDefault();
  103. }
  104. function findHosts(request, callback) {
  105. var search, url;
  106. url = baseUrl+"User/get-hosts";
  107. search = request.term;
  108. var noResult = new Array();
  109. noResult[0] = new Array();
  110. noResult[0]['value'] = $("#add_show_hosts_autocomplete").val();
  111. noResult[0]['label'] = $.i18n._("No result found");
  112. noResult[0]['index'] = null;
  113. $.post(url,
  114. {format: "json", term: search},
  115. function(json) {
  116. if(json.hosts.length<1){
  117. callback(noResult);
  118. }else{
  119. callback(json.hosts);
  120. }
  121. });
  122. }
  123. function beginEditShow(data){
  124. if (data.show_error == true){
  125. alertShowErrorAndReload();
  126. return false;
  127. }
  128. redrawAddShowForm($("#add-show-form"), data.newForm);
  129. removeAddShowButton();
  130. openAddShowForm();
  131. }
  132. function onStartTimeSelect(){
  133. $("#add_show_start_time").trigger('input');
  134. }
  135. function onEndTimeSelect(){
  136. $("#add_show_end_time").trigger('input');
  137. }
  138. function padZeroes(number, length)
  139. {
  140. var str = '' + number;
  141. while (str.length < length) {str = '0' + str;}
  142. return str;
  143. }
  144. function hashCode(str) { // java String#hashCode
  145. var hash = 0;
  146. for (var i = 0; i < str.length; i++) {
  147. hash = str.charCodeAt(i) + ((hash << 5) - hash);
  148. }
  149. return hash;
  150. }
  151. function intToRGB(i){
  152. return (padZeroes(((i>>16)&0xFF).toString(16), 2) +
  153. padZeroes(((i>>8)&0xFF).toString(16), 2)+
  154. padZeroes((i&0xFF).toString(16), 2)
  155. );
  156. }
  157. function stringToColor(s)
  158. {
  159. return intToRGB(hashCode(s));
  160. }
  161. function getContrastYIQ(hexcolor){
  162. var r = parseInt(hexcolor.substr(0,2),16);
  163. var g = parseInt(hexcolor.substr(2,2),16);
  164. var b = parseInt(hexcolor.substr(4,2),16);
  165. var yiq = ((r*299)+(g*587)+(b*114))/1000;
  166. return (yiq >= 128) ? '000000' : 'ffffff';
  167. }
  168. function setAddShowEvents(form) {
  169. //var form = $("#add-show-form");
  170. form.find("h3").click(function(){
  171. $(this).next().toggle();
  172. });
  173. if(!form.find("#add_show_repeats").attr('checked')) {
  174. form.find("#schedule-show-when > fieldset:last").hide();
  175. $("#add_show_rebroadcast_relative").hide();
  176. }
  177. else {
  178. $("#add_show_rebroadcast_absolute").hide();
  179. }
  180. if(!form.find("#add_show_record").attr('checked')) {
  181. form.find("#add_show_rebroadcast").hide();
  182. }
  183. if(!form.find("#add_show_rebroadcast").attr('checked')) {
  184. form.find("#schedule-record-rebroadcast > fieldset:not(:first-child)").hide();
  185. }
  186. form.find("#add_show_repeats").click(function(){
  187. $(this).blur();
  188. form.find("#schedule-show-when > fieldset:last").toggle();
  189. var checkBoxSelected = false;
  190. var days = form.find("#add_show_day_check-element input").each( function() {
  191. var currentCheckBox = $(this).attr("checked");
  192. if (currentCheckBox && currentCheckBox == "checked"){
  193. checkBoxSelected = true;
  194. }
  195. });
  196. if (!checkBoxSelected){
  197. var d = getDateFromString(form.find("#add_show_start_date").attr("value"));
  198. if ( d != null)
  199. form.find("#add_show_day_check-"+d.getDay()).attr('checked', true);
  200. }
  201. //must switch rebroadcast displays
  202. if(form.find("#add_show_rebroadcast").attr('checked')) {
  203. if($(this).attr('checked')){
  204. form.find("#add_show_rebroadcast_absolute").hide();
  205. form.find("#add_show_rebroadcast_relative").show();
  206. }
  207. else {
  208. form.find("#add_show_rebroadcast_absolute").show();
  209. form.find("#add_show_rebroadcast_relative").hide();
  210. }
  211. }
  212. });
  213. form.find("#add_show_linked").click(function(){
  214. if ($(this).attr("readonly")) {
  215. if ($("#show-link-readonly-warning").length === 0) {
  216. $(this).parent().after("<ul id='show-link-readonly-warning' class='errors'><li>"+$.i18n._("Warning: You cannot change this field while the show is currently playing")+"</li></ul>");
  217. }
  218. return false;
  219. }
  220. //only display the warning message if a show is being edited
  221. if ($(".button-bar.bottom").find(".ui-button-text").text() === "Update show") {
  222. if ($(this).attr("checked") && $("#show-link-warning").length === 0) {
  223. $(this).parent().after("<ul id='show-link-warning' class='errors'><li>"+$.i18n._("Warning: All other repetitions of this show will have their contents replaced to match the show you selected 'Edit Show' with.")+"</li></ul>");
  224. }
  225. if (!$(this).attr("checked") && $("#show-link-warning").length !== 0) {
  226. $("#show-link-warning").remove();
  227. }
  228. }
  229. });
  230. form.find("#add_show_linked-label").before("<span class='show_linking_help_icon'></span>");
  231. form.find("#add_show_record").click(function(){
  232. $(this).blur();
  233. form.find("#add_show_rebroadcast").toggle();
  234. if (form.find("#add_show_record").attr("checked")) {
  235. form.find("#add_show_linked").attr("checked", false).attr("disabled", true);
  236. } else {
  237. form.find("#add_show_linked").attr("disabled", false);
  238. }
  239. //uncheck rebroadcast checkbox
  240. form.find("#add_show_rebroadcast").attr('checked', false);
  241. //hide rebroadcast options
  242. form.find("#schedule-record-rebroadcast > fieldset:not(:first-child)").hide();
  243. });
  244. form.find("#add_show_rebroadcast").click(function(){
  245. $(this).blur();
  246. if(form.find("#add_show_record").attr('checked')){
  247. if($(this).attr('checked') && !form.find("#add_show_repeats").attr('checked')) {
  248. form.find("#add_show_rebroadcast_absolute").show();
  249. }
  250. else if($(this).attr('checked') && form.find("#add_show_repeats").attr('checked')) {
  251. form.find("#add_show_rebroadcast_relative").show();
  252. }
  253. else {
  254. form.find("#schedule-record-rebroadcast > fieldset:not(:first-child)").hide();
  255. }
  256. }
  257. });
  258. // in case user is creating a new show, there will be
  259. // no show_id so we have to store the default timezone
  260. // to be able to do the conversion when the timezone
  261. // setting changes
  262. var currentTimezone = form.find("#add_show_timezone").val();
  263. form.find("#add_show_timezone").change(function(){
  264. var startDateField = form.find("#add_show_start_date"),
  265. startTimeField = form.find("#add_show_start_time"),
  266. endDateField = form.find("#add_show_end_date_no_repeat"),
  267. endTimeField = form.find("#add_show_end_time"),
  268. newTimezone = form.find("#add_show_timezone").val();
  269. $.post(baseUrl+"Schedule/localize-start-end-time",
  270. {format: "json",
  271. startDate: startDateField.val(),
  272. startTime: startTimeField.val(),
  273. endDate: endDateField.val(),
  274. endTime: endTimeField.val(),
  275. newTimezone: newTimezone,
  276. oldTimezone: currentTimezone}, function(json){
  277. startDateField.val(json.start.date);
  278. startTimeField.val(json.start.time);
  279. endDateField.val(json.end.date);
  280. endTimeField.val(json.end.time);
  281. // Change the timezone now that we've updated the times
  282. currentTimezone = newTimezone;
  283. });
  284. });
  285. form.find("#add_show_repeat_type").change(function(){
  286. toggleRepeatDays();
  287. toggleMonthlyRepeatType();
  288. });
  289. toggleMonthlyRepeatType();
  290. toggleRepeatDays();
  291. function toggleRepeatDays() {
  292. if(form.find("#add_show_repeat_type").val() == 2 || form.find("#add_show_repeat_type").val() == 3) {
  293. form.find("#add_show_day_check-label, #add_show_day_check-element").hide();
  294. //form.find("#add_show_monthly_repeat_type-label, #add_show_monthly_repeat_type-element").show();
  295. }
  296. else {
  297. form.find("#add_show_day_check-label, #add_show_day_check-element").show();
  298. //form.find("#add_show_monthly_repeat_type-label, #add_show_monthly_repeat_type-element").hide();
  299. }
  300. }
  301. function toggleMonthlyRepeatType() {
  302. if (form.find("#add_show_repeat_type").val() == 2) {
  303. form.find("#add_show_monthly_repeat_type-label, #add_show_monthly_repeat_type-element").show();
  304. } else {
  305. form.find("#add_show_monthly_repeat_type-label, #add_show_monthly_repeat_type-element").hide();
  306. }
  307. }
  308. form.find("#add_show_day_check-label").addClass("block-display");
  309. form.find("#add_show_day_check-element").addClass("block-display clearfix");
  310. form.find("#add_show_day_check-element label").addClass("wrapp-label");
  311. form.find("#add_show_day_check-element br").remove();
  312. form.find(".show_timezone_help_icon").qtip({
  313. content: {
  314. text: $.i18n._("Timezone is set to the station timezone by default. Shows in the calendar will be displayed in your local time defined by the " +
  315. "Interface Timezone in your user settings.")
  316. },
  317. hide: {
  318. delay: 500,
  319. fixed: true
  320. },
  321. style: {
  322. border: {
  323. width: 0,
  324. radius: 4
  325. },
  326. classes: "ui-tooltip-dark ui-tooltip-rounded"
  327. },
  328. position: {
  329. my: "left bottom",
  330. at: "right center"
  331. }
  332. });
  333. form.find(".airtime_auth_help_icon").qtip({
  334. content: {
  335. text: $.i18n._("This follows the same security pattern for the shows: only users assigned to the show can connect.")
  336. },
  337. hide: {
  338. delay: 500,
  339. fixed: true
  340. },
  341. style: {
  342. border: {
  343. width: 0,
  344. radius: 4
  345. },
  346. classes: "ui-tooltip-dark ui-tooltip-rounded"
  347. },
  348. position: {
  349. my: "left bottom",
  350. at: "right center"
  351. }
  352. });
  353. form.find(".custom_auth_help_icon").qtip({
  354. content: {
  355. text: $.i18n._("Specify custom authentication which will work only for this show.")
  356. },
  357. hide: {
  358. delay: 500,
  359. fixed: true
  360. },
  361. style: {
  362. border: {
  363. width: 0,
  364. radius: 4
  365. },
  366. classes: "ui-tooltip-dark ui-tooltip-rounded"
  367. },
  368. position: {
  369. my: "left bottom",
  370. at: "right center"
  371. }
  372. });
  373. form.find(".stream_username_help_icon").qtip({
  374. content: {
  375. text: $.i18n._("If your live streaming client does not ask for a username, this field should be 'source'.")
  376. },
  377. hide: {
  378. delay: 500,
  379. fixed: true
  380. },
  381. style: {
  382. border: {
  383. width: 0,
  384. radius: 4
  385. },
  386. classes: "ui-tooltip-dark ui-tooltip-rounded"
  387. },
  388. position: {
  389. my: "left bottom",
  390. at: "right center"
  391. }
  392. });
  393. form.find(".show_linking_help_icon").qtip({
  394. content: {
  395. text: $.i18n._("By linking your repeating shows any media items scheduled in any repeat show will also get scheduled in the other repeat shows")
  396. },
  397. hide: {
  398. delay: 500,
  399. fixed: true
  400. },
  401. style: {
  402. border: {
  403. width: 0,
  404. radius: 4
  405. },
  406. classes: "ui-tooltip-dark ui-tooltip-rounded"
  407. },
  408. position: {
  409. my: "left bottom",
  410. at: "right center"
  411. }
  412. });
  413. function endDateVisibility(){
  414. if(form.find("#add_show_no_end").is(':checked')){
  415. form.find("#add_show_end_date").hide();
  416. } else {
  417. form.find("#add_show_end_date").show();
  418. }
  419. }
  420. endDateVisibility();
  421. form.find("#add_show_no_end").click(endDateVisibility);
  422. createDateInput(form.find("#add_show_start_date"), startDpSelect);
  423. createDateInput(form.find("#add_show_end_date_no_repeat"), endDpSelect);
  424. createDateInput(form.find("#add_show_end_date"), endDpSelect);
  425. $("#add_show_start_time").timepicker({
  426. amPmText: ['', ''],
  427. defaultTime: '00:00',
  428. onSelect: onStartTimeSelect,
  429. hourText: $.i18n._("Hour"),
  430. minuteText: $.i18n._("Minute")
  431. });
  432. $("#add_show_end_time").timepicker({
  433. amPmText: ['', ''],
  434. onSelect: onEndTimeSelect,
  435. hourText: $.i18n._("Hour"),
  436. minuteText: $.i18n._("Minute")
  437. });
  438. form.find('input[name^="add_show_rebroadcast_date_absolute"]').datepicker({
  439. minDate: adjustDateToServerDate(new Date(), timezoneOffset),
  440. dateFormat: 'yy-mm-dd',
  441. //i18n_months, i18n_days_short are in common.js
  442. monthNames: i18n_months,
  443. dayNamesMin: i18n_days_short,
  444. closeText: 'Close',
  445. showButtonPanel: true,
  446. firstDay: calendarPref.weekStart
  447. });
  448. form.find('input[name^="add_show_rebroadcast_time"]').timepicker({
  449. amPmText: ['', ''],
  450. defaultTime: '',
  451. closeButtonText: $.i18n._("Done"),
  452. hourText: $.i18n._("Hour"),
  453. minuteText: $.i18n._("Minute")
  454. });
  455. form.find(".add_absolute_rebroadcast_day").click(function(){
  456. var li = $(this).parent().find("ul.formrow-repeat > li:visible:last").next();
  457. li.show();
  458. li = li.next();
  459. if(li.length === 0) {
  460. $(this).hide();
  461. }
  462. });
  463. form.find('a[id^="remove_rebroadcast"]').click(function(){
  464. var list = $(this).parent().parent();
  465. var li_num = $(this).parent().index();
  466. var num = list.find("li").length;
  467. var count = num - li_num;
  468. var curr = $(this).parent();
  469. var next = curr.next();
  470. for(var i=0; i<=count; i++) {
  471. var date = next.find('[name^="add_show_rebroadcast_date"]').val();
  472. curr.find('[name^="add_show_rebroadcast_date"]').val(date);
  473. var time = next.find('[name^="add_show_rebroadcast_time"]').val();
  474. curr.find('[name^="add_show_rebroadcast_time"]').val(time);
  475. curr = next;
  476. next = curr.next();
  477. }
  478. list.find("li:visible:last")
  479. .find('[name^="add_show_rebroadcast_date"]')
  480. .val('')
  481. .end()
  482. .find('[name^="add_show_rebroadcast_time"]')
  483. .val('')
  484. .end()
  485. .hide();
  486. list.next().show();
  487. });
  488. form.find("#add_show_hosts_autocomplete").autocomplete({
  489. source: findHosts,
  490. select: autoSelect,
  491. delay: 200
  492. });
  493. form.find("#add_show_hosts_autocomplete").keypress(function(e){
  494. if( e.which == 13 ){
  495. return false;
  496. }
  497. })
  498. form.find("#schedule-show-style input").ColorPicker({
  499. onChange: function (hsb, hex, rgb, el) {
  500. $(el).val(hex);
  501. },
  502. onSubmit: function(hsb, hex, rgb, el) {
  503. $(el).val(hex);
  504. $(el).ColorPickerHide();
  505. },
  506. onBeforeShow: function () {
  507. $(this).ColorPickerSetColor(this.value);
  508. }
  509. });
  510. form.find("#add-show-close").click(closeAddShowForm);
  511. form.find(".add-show-submit").click(function(event) {
  512. event.preventDefault();
  513. var addShowButton = $(this);
  514. $('#schedule-add-show').block({
  515. message: null,
  516. applyPlatformOpacityRules: false
  517. });
  518. //when editing a show, the record option is disabled
  519. //we have to enable it to get the correct value when
  520. //we call serializeArray()
  521. if (form.find("#add_show_record").attr("disabled", true)) {
  522. form.find("#add_show_record").attr("disabled", false);
  523. }
  524. var startDateDisabled = false,
  525. startTimeDisabled = false;
  526. // Similarly, we need to re-enable start date and time if they're disabled
  527. if (form.find("#add_show_start_date").prop("disabled") === true) {
  528. form.find("#add_show_start_date").attr("disabled", false);
  529. startDateDisabled = true;
  530. }
  531. if (form.find("#add_show_start_time").prop("disabled") === true) {
  532. form.find("#add_show_start_time").attr("disabled", false);
  533. startTimeDisabled = true;
  534. }
  535. var data = $("form").serializeArray();
  536. // We need to notify the application if date and time were disabled
  537. data.push({name: 'start_date_disabled', value: startDateDisabled});
  538. data.push({name: 'start_time_disabled', value: startTimeDisabled});
  539. var hosts = $('#add_show_hosts-element input').map(function() {
  540. if($(this).attr("checked")) {
  541. return $(this).val();
  542. }
  543. }).get();
  544. var days = $('#add_show_day_check-element input').map(function() {
  545. if($(this).attr("checked")) {
  546. return $(this).val();
  547. }
  548. }).get();
  549. var start_date = $("#add_show_start_date").val();
  550. var end_date = $("#add_show_end_date").val();
  551. var action = baseUrl+"Schedule/"+String(addShowButton.attr("data-action"));
  552. $.post(action, {format: "json", data: data, hosts: hosts, days: days}, function(json){
  553. $('#schedule-add-show').unblock();
  554. var $addShowForm = $("#add-show-form");
  555. if (json.form) {
  556. redrawAddShowForm($addShowForm, json.form);
  557. $("#add_show_end_date").val(end_date);
  558. $("#add_show_start_date").val(start_date);
  559. showErrorSections();
  560. }
  561. else if (json.edit) {
  562. $("#schedule_calendar").removeAttr("style")
  563. .fullCalendar('render');
  564. $addShowForm.hide();
  565. $.get(baseUrl+"Schedule/get-form", {format:"json"}, function(json){
  566. redrawAddShowForm($addShowForm, json.form);
  567. });
  568. makeAddShowButton();
  569. }
  570. else {
  571. redrawAddShowForm($addShowForm, json.newForm);
  572. scheduleRefetchEvents(json);
  573. }
  574. });
  575. });
  576. var regDate = new RegExp(/^[0-9]{4}-[0-1][0-9]-[0-3][0-9]$/);
  577. var regTime = new RegExp(/^[0-2][0-9]:[0-5][0-9]$/);
  578. // when start date/time changes, set end date/time to start date/time+1 hr
  579. $('#add_show_start_date, #add_show_start_time').bind('input', 'change', function(){
  580. var startDateString = $('#add_show_start_date').val();
  581. var startTimeString = $('#add_show_start_time').val();
  582. if(regDate.test(startDateString) && regTime.test(startTimeString)){
  583. var startDate = startDateString.split('-');
  584. var startTime = startTimeString.split(':');
  585. var startDateTime = new Date(startDate[0], parseInt(startDate[1], 10)-1, startDate[2], startTime[0], startTime[1], 0, 0);
  586. var endDateString = $('#add_show_end_date_no_repeat').val();
  587. var endTimeString = $('#add_show_end_time').val()
  588. var endDate = endDateString.split('-');
  589. var endTime = endTimeString.split(':');
  590. var endDateTime = new Date(endDate[0], parseInt(endDate[1], 10)-1, endDate[2], endTime[0], endTime[1], 0, 0);
  591. if(startDateTime.getTime() >= endDateTime.getTime()){
  592. var duration = $('#add_show_duration').val();
  593. // parse duration
  594. var time = 0;
  595. var info = duration.split(' ');
  596. var h = parseInt(info[0], 10);
  597. time += h * 60 * 60* 1000;
  598. if(info.length >1 && $.trim(info[1]) !== ''){
  599. var m = parseInt(info[1], 10);
  600. time += m * 60 * 1000;
  601. }
  602. endDateTime = new Date(startDateTime.getTime() + time);
  603. }
  604. var endDateFormat = endDateTime.getFullYear() + '-' + pad(endDateTime.getMonth()+1,2) + '-' + pad(endDateTime.getDate(),2);
  605. var endTimeFormat = pad(endDateTime.getHours(),2) + ':' + pad(endDateTime.getMinutes(),2);
  606. $('#add_show_end_date_no_repeat').val(endDateFormat);
  607. $('#add_show_end_time').val(endTimeFormat);
  608. // calculate duration
  609. var startDateTimeString = startDateString + " " + startTimeString;
  610. var endDateTimeString = $('#add_show_end_date_no_repeat').val() + " " + $('#add_show_end_time').val();
  611. var timezone = $("#add_show_timezone").val();
  612. calculateDuration(startDateTimeString, endDateTimeString, timezone);
  613. }
  614. });
  615. // when end date/time changes, check if the changed date is in past of start date/time
  616. $('#add_show_end_date_no_repeat, #add_show_end_time').bind('input', 'change', function(){
  617. var endDateString = $('#add_show_end_date_no_repeat').val();
  618. var endTimeString = $('#add_show_end_time').val()
  619. if(regDate.test(endDateString) && regTime.test(endTimeString)){
  620. var startDateString = $('#add_show_start_date').val();
  621. var startTimeString = $('#add_show_start_time').val();
  622. var startDate = startDateString.split('-');
  623. var startTime = startTimeString.split(':');
  624. var startDateTime = new Date(startDate[0], parseInt(startDate[1], 10)-1, startDate[2], startTime[0], startTime[1], 0, 0);
  625. var endDate = endDateString.split('-');
  626. var endTime = endTimeString.split(':');
  627. var endDateTime = new Date(endDate[0], parseInt(endDate[1], 10)-1, endDate[2], endTime[0], endTime[1], 0, 0);
  628. if(startDateTime.getTime() > endDateTime.getTime()){
  629. $('#add_show_end_date_no_repeat').css('background-color', '#F49C9C');
  630. $('#add_show_end_time').css('background-color', '#F49C9C');
  631. }else{
  632. $('#add_show_end_date_no_repeat').css('background-color', '');
  633. $('#add_show_end_time').css('background-color', '');
  634. }
  635. // calculate duration
  636. var startDateTimeString = startDateString + " " + startTimeString;
  637. var endDateTimeString = endDateString + " " + endTimeString;
  638. var timezone = $("#add_show_timezone").val();
  639. calculateDuration(startDateTimeString, endDateTimeString, timezone);
  640. }
  641. });
  642. if($('#cb_custom_auth').attr('checked')){
  643. $('#custom_auth_div').show()
  644. }else{
  645. $('#custom_auth_div').hide()
  646. }
  647. $('#cb_custom_auth').change(function(){
  648. if($(this).attr('checked')){
  649. $('#custom_auth_div').show()
  650. }else{
  651. $('#custom_auth_div').hide()
  652. }
  653. })
  654. function calculateDuration(startDateTime, endDateTime, timezone){
  655. var loadingIcon = $('#icon-loader-small');
  656. loadingIcon.show();
  657. $.post(
  658. baseUrl+"Schedule/calculate-duration",
  659. {startTime: startDateTime, endTime: endDateTime, timezone: timezone},
  660. function(data) {
  661. $('#add_show_duration').val(JSON.parse(data));
  662. loadingIcon.hide();
  663. });
  664. }
  665. var bgColorEle = $("#add_show_background_color");
  666. var textColorEle = $("#add_show_color");
  667. $('#add_show_name').bind('input', 'change', function(){
  668. var colorCode = stringToColor($(this).val());
  669. bgColorEle.val(colorCode);
  670. textColorEle.val(getContrastYIQ(colorCode));
  671. });
  672. }
  673. function showErrorSections() {
  674. if($("#schedule-show-what .errors").length > 0) {
  675. $("#schedule-show-what").show();
  676. }
  677. if($("#schedule-show-when .errors").length > 0) {
  678. $("#schedule-show-when").show();
  679. }
  680. if($("#schedule-show-who .errors").length > 0) {
  681. $("#schedule-show-who").show();
  682. }
  683. if($("#schedule-show-style .errors").length > 0) {
  684. $("#schedule-show-style").show();
  685. }
  686. if($("#add_show_rebroadcast_absolute .errors").length > 0) {
  687. $("#schedule-record-rebroadcast").show();
  688. $("#add_show_rebroadcast_absolute").show();
  689. }
  690. if($("#live-stream-override .errors").length > 0) {
  691. $("#live-stream-override").show();
  692. }
  693. if($("#add_show_rebroadcast_relative .errors").length > 0) {
  694. $("#schedule-record-rebroadcast").show();
  695. $("#add_show_rebroadcast_relative").show();
  696. }
  697. }
  698. $(document).ready(function() {
  699. setAddShowEvents($("#add-show-form"));
  700. });
  701. //Alert the error and reload the page
  702. //this function is used to resolve concurrency issue
  703. function alertShowErrorAndReload(){
  704. alert($.i18n._("The show instance doesn't exist anymore!"));
  705. window.location.reload();
  706. }