diff --git a/shrine-webclient/src/main/html/js-i2b2/cells/plugins/MedCo/MedCo_ctrlr_Dates.js b/shrine-webclient/src/main/html/js-i2b2/cells/plugins/MedCo/MedCo_ctrlr_Dates.js index e22f1ac5e..548f3a921 100644 --- a/shrine-webclient/src/main/html/js-i2b2/cells/plugins/MedCo/MedCo_ctrlr_Dates.js +++ b/shrine-webclient/src/main/html/js-i2b2/cells/plugins/MedCo/MedCo_ctrlr_Dates.js @@ -1,285 +1,287 @@ /** * inspired from i2b2.CRC.ctrlr.dateConstraint */ i2b2.MedCo.QT.dateConstraint = {}; i2b2.MedCo.QT.dateConstraint.model = { // the date constraint popup has to be bound to a panel when called panel: null, }; i2b2.MedCo.QT.dateConstraint.ctrlr = { + // ================================================================================================== // init: function (panel) { panel = panel.model // creates a new model and ctrl wrapper and returns them (each panel has its own date model) // ----------- initialize the model ------------- panel.date.model = { defaultStartDate: '12/01/1979', // defaultEndDate: '01/01/2018', dateFrom: false, dateTo: false, }; // ----------- initialize the controller ------------- panel.date.ctrlr = { show: function(){ // bind the popup to a panel before showing it i2b2.MedCo.QT.dateConstraint.model.panel = panel; i2b2.MedCo.QT.dateConstraint.ctrlr.show() } }; }, + // ================================================================================================== // show: function () { var panel = i2b2.MedCo.QT.dateConstraint.model.panel; // show the popup filling it with the data of the given date model if (!i2b2.MedCo.QT.dateConstraint.view) { // ----------- initialize the view ------------- document.body.appendChild(htmlToElement( "<div id='MedCo-calendarDiv' style='z-index:1520; display:none;'></div>")) document.body.appendChild(htmlToElement( "<div id='MedCo-calendarDivMask' style='display:none; z-index:1510; position:absolute;' " + "onClick='i2b2.MedCo.QT.dateConstraint.ctrlr.hideCalendar()'></div>")) var handleSubmit = function () { - // todo - var a = panel - // var closure_pi = i2b2.CRC.ctrlr.dateConstraint.currentPanelIndex; - // // save the dates - // if (i2b2.CRC.ctrlr.dateConstraint.doProcessDates(closure_pi)) { - // // saved and validated, close modal form - // this.submit(); - // } + // save the dates + if (i2b2.MedCo.QT.dateConstraint.ctrlr.doProcessDates()) { + // saved and validated, close modal form + this.submit(); + } i2b2.MedCo.QT.dateConstraint.ctrlr.hideCalendar(); }; var handleCancel = function () { i2b2.MedCo.QT.dateConstraint.ctrlr.hideCalendar() this.cancel(); } i2b2.MedCo.QT.dateConstraint.view = new YAHOO.widget.SimpleDialog("MedCo-constraintDates", { width: "400px", fixedcenter: true, constraintoviewport: true, modal: true, zindex: 700, buttons: [{ text: "OK", isDefault: true, handler: handleSubmit }, { text: "Cancel", handler: handleCancel }] }); $('MedCo-constraintDates').show(); i2b2.MedCo.QT.dateConstraint.view.render(document.body); } i2b2.MedCo.QT.dateConstraint.view.show(); // load our panel data var DateRecord = new Object; if (panel.date.model.dateFrom) { $('MedCo-checkboxDateStart').checked = true; $('MedCo-constraintDateStart').disabled = false; DateRecord.Start = padNumber(panel.date.model.dateFrom.Month, 2) + '/' + padNumber(panel.date.model.dateFrom.Day, 2) + '/' + panel.date.model.dateFrom.Year; } else { $('MedCo-checkboxDateStart').checked = false; $('MedCo-constraintDateStart').disabled = true; DateRecord.Start = panel.date.model.defaultStartDate; } $('MedCo-constraintDateStart').value = DateRecord.Start; if (panel.date.model.dateTo) { $('MedCo-checkboxDateEnd').checked = true; $('MedCo-constraintDateEnd').disabled = false; DateRecord.End = padNumber(panel.date.model.dateTo.Month, 2) + '/' + padNumber(panel.date.model.dateTo.Day, 2) + '/' + panel.date.model.dateTo.Year; } else { $('MedCo-checkboxDateEnd').checked = false; $('MedCo-constraintDateEnd').disabled = true; var curdate = new Date(); DateRecord.End = padNumber(curdate.getMonth() + 1, 2) + '/' + padNumber(curdate.getDate(), 2) + '/' + curdate.getFullYear(); } $('MedCo-constraintDateEnd').value = DateRecord.End; }, + // ================================================================================================== // toggleDate: function () { if ($('MedCo-checkboxDateStart').checked) { $('MedCo-constraintDateStart').disabled = false; setTimeout("$('MedCo-constraintDateStart').select()", 150); } else { $('MedCo-constraintDateStart').disabled = true; } if ($('MedCo-checkboxDateEnd').checked) { $('MedCo-constraintDateEnd').disabled = false; setTimeout("$('MedCo-constraintDateEnd').select()", 150); } else { $('MedCo-constraintDateEnd').disabled = true; } }, + // ================================================================================================== // doShowCalendar: function (whichDate) { // save our date type on the calendar object for later use i2b2.MedCo.QT.dateConstraint.model.whichDate = whichDate; // create calendar if not already initialized if (!this.DateConstrainCal) { this.DateConstrainCal = new YAHOO.widget.Calendar("DateContstrainCal", "MedCo-calendarDiv"); this.DateConstrainCal.selectEvent.subscribe(this.dateSelected, this.DateConstrainCal, true); } this.DateConstrainCal.clear(); // process click if (whichDate == 'S') { if ($('MedCo-checkboxDateStart').checked == false) {return;} var currDateDiv = $('MedCo-dropDateStart') $("MedCo-constraintDateStart").select(); var sDateValue = $('MedCo-constraintDateStart').value; } else { if ($('MedCo-checkboxDateEnd').checked == false) {return;} var currDateDiv = $('MedCo-dropDateEnd') $("MedCo-constraintDateEnd").select(); var sDateValue = $('MedCo-constraintDateEnd').value; } var apos = Position.cumulativeOffset(currDateDiv); var calendarDiv = $("MedCo-calendarDiv") var cx = apos[0] - calendarDiv.getWidth() + currDateDiv.width - 7; var cy = apos[1] + currDateDiv.height - 35; calendarDiv.style.top = cy + 'px'; calendarDiv.style.left = cx + 'px'; var rxDate = /^\d{1,2}(\-|\/|\.)\d{1,2}\1\d{4}$/ if (rxDate.test(sDateValue)) { var aDate = sDateValue.split(/\//); this.DateConstrainCal.setMonth(aDate[0] - 1); this.DateConstrainCal.setYear(aDate[2]); } else { alert("Invalid Date Format, please use mm/dd/yyyy or select a date using the calendar."); } // display everything calendarDiv.show(); var w = window.innerWidth || (window.document.documentElement.clientWidth || window.document.body.clientWidth); var h = window.innerHeight || (window.document.documentElement.clientHeight || window.document.body.clientHeight); var calendarDivMask = $("MedCo-calendarDivMask") calendarDivMask.style.top = "0px"; calendarDivMask.style.left = "0px"; calendarDivMask.style.width = (w - 10) + "px"; calendarDivMask.style.height = (h - 10) + "px"; calendarDivMask.show(); this.DateConstrainCal.render(document.body); }, // ================================================================================================== // dateSelected: function (eventName, selectedDate) { if (i2b2.MedCo.QT.dateConstraint.model.whichDate=='S') { var tn = $('MedCo-constraintDateStart'); } else { var tn = $('MedCo-constraintDateEnd'); } var selectDate = selectedDate[0][0]; tn.value = selectDate[1]+'/'+selectDate[2]+'/'+selectDate[0]; i2b2.MedCo.QT.dateConstraint.ctrlr.hideCalendar(); }, // ================================================================================================== // hideCalendar: function () { $("MedCo-calendarDiv").hide(); $("MedCo-calendarDivMask").hide(); }, -} - -// // ================================================================================================== // -// doProcessDates: function(panelIndex) { -// // push the dates into the data model -// var sDateError = false; -// -// //^(0[1-9]|1[012])(\\|\-)(0[1-9]|[12][0-9]|3[01])(\\|\-)(19|20)\d\d$ -// ///^\d{1,2}(\-|\/|\.)\d{1,2}\1\d{4}$/ -// var rxDate = /^([1-9]|0[1-9]|1[012])(\/|\-)([1-9]|0[1-9]|[12][0-9]|3[01])(\/|\-)(19|20)\d\d$/; -// var DateRecord = {}; -// var startChecked = $('checkboxDateStart').checked; -// var endChecked = $('checkboxDateEnd').checked; -// var startDate, endDate; -// -// var dm = i2b2.CRC.model.queryCurrent.panels[i2b2.CRC.ctrlr.QT.temporalGroup][panelIndex]; -// this.currentPanelIndex = panelIndex; -// // start date -// if (startChecked) { -// DateRecord.Start = {}; -// startDate = $('constraintDateStart').value; -// if (rxDate.test(startDate)) { -// var aDate = startDate.split(/\//); -// DateRecord.Start.Month = padNumber(aDate[0],2); -// DateRecord.Start.Day = padNumber(aDate[1],2); -// DateRecord.Start.Year = aDate[2]; -// } else { -// sDateError = "Invalid Start Date\n"; -// } -// } -// // test the end date. -// if (endChecked) { -// DateRecord.End = {}; -// endDate = $('constraintDateEnd').value; -// if (rxDate.test(endDate)) { -// var aDate = endDate.split(/\//); -// DateRecord.End.Month = padNumber(aDate[0]); -// DateRecord.End.Day = padNumber(aDate[1]); -// DateRecord.End.Year = aDate[2]; -// } else { -// sDateError = "Invalid End Date\n"; -// } -// } -// -// //make sure dates are in proper order. -// if(startDate && endDate) { -// var start = new Date(startDate); -// var end = new Date(endDate); -// if(start.valueOf() >= end.valueOf()) { -// sDateError = "Invalid Date Range\n"; -// } -// } -// //must check -// //add an additional if statement that ensures start date is smaller than the end date. -// //if(sDate) -// // check for processing errors -// if (sDateError) { -// sDateError += "\nPlease use the following format: mm/dd/yyyy"; -// alert(sDateError); -// return false; -// } else { -// // attach the data to our panel data -// if (DateRecord.Start) { -// dm.dateFrom = DateRecord.Start; -// } else { -// delete dm.dateFrom; -// } -// if (DateRecord.End) { -// dm.dateTo = DateRecord.End; -// } else { -// delete dm.dateTo; -// } -// // clear the query name and set the query as having dirty data -// var QT = i2b2.CRC.ctrlr.QT; -// QT.doSetQueryName.call(QT,''); -// } -// // redraw buttons if needed -// var panelctrlFound = false; -// var pd = i2b2.CRC.ctrlr.QT; -// for (var i=0; i<pd.panelControllers.length; i++) { -// if (pd.panelControllers[i].panelCurrentIndex == panelIndex) { -// // found the controller for the panel requested -// panelctrlFound = pd.panelControllers[i]; -// break; -// } -// } -// if (panelctrlFound!==false) { panelctrlFound._redrawButtons(); } -// return true; -// } -// }; \ No newline at end of file + doProcessDates: function() { + var conc = document.getElementById(i2b2.MedCo.QT.dateConstraint.model.panel.model.conceptPanelId) + conc.appendChild($('constraintDateStart').value) + conc.appendChild($('constraintDateEnd').value) + return true + // // push the dates into the data model + // var sDateError = false; + // + // //^(0[1-9]|1[012])(\\|\-)(0[1-9]|[12][0-9]|3[01])(\\|\-)(19|20)\d\d$ + // ///^\d{1,2}(\-|\/|\.)\d{1,2}\1\d{4}$/ + // var rxDate = /^([1-9]|0[1-9]|1[012])(\/|\-)([1-9]|0[1-9]|[12][0-9]|3[01])(\/|\-)(19|20)\d\d$/; + // var DateRecord = {}; + // var startChecked = $('checkboxDateStart').checked; + // var endChecked = $('checkboxDateEnd').checked; + // var startDate, endDate; + // + // var dm = i2b2.CRC.model.queryCurrent.panels[i2b2.CRC.ctrlr.QT.temporalGroup][panelIndex]; + // this.currentPanelIndex = panelIndex; + // // start date + // if (startChecked) { + // DateRecord.Start = {}; + // startDate = $('constraintDateStart').value; + // if (rxDate.test(startDate)) { + // var aDate = startDate.split(/\//); + // DateRecord.Start.Month = padNumber(aDate[0],2); + // DateRecord.Start.Day = padNumber(aDate[1],2); + // DateRecord.Start.Year = aDate[2]; + // } else { + // sDateError = "Invalid Start Date\n"; + // } + // } + // // test the end date. + // if (endChecked) { + // DateRecord.End = {}; + // endDate = $('constraintDateEnd').value; + // if (rxDate.test(endDate)) { + // var aDate = endDate.split(/\//); + // DateRecord.End.Month = padNumber(aDate[0]); + // DateRecord.End.Day = padNumber(aDate[1]); + // DateRecord.End.Year = aDate[2]; + // } else { + // sDateError = "Invalid End Date\n"; + // } + // } + // + // //make sure dates are in proper order. + // if(startDate && endDate) { + // var start = new Date(startDate); + // var end = new Date(endDate); + // if(start.valueOf() >= end.valueOf()) { + // sDateError = "Invalid Date Range\n"; + // } + // } + // //must check + // //add an additional if statement that ensures start date is smaller than the end date. + // //if(sDate) + // // check for processing errors + // if (sDateError) { + // sDateError += "\nPlease use the following format: mm/dd/yyyy"; + // alert(sDateError); + // return false; + // } else { + // // attach the data to our panel data + // if (DateRecord.Start) { + // dm.dateFrom = DateRecord.Start; + // } else { + // delete dm.dateFrom; + // } + // if (DateRecord.End) { + // dm.dateTo = DateRecord.End; + // } else { + // delete dm.dateTo; + // } + // // clear the query name and set the query as having dirty data + // var QT = i2b2.CRC.ctrlr.QT; + // QT.doSetQueryName.call(QT,''); + // } + // // redraw buttons if needed + // var panelctrlFound = false; + // var pd = i2b2.CRC.ctrlr.QT; + // for (var i=0; i<pd.panelControllers.length; i++) { + // if (pd.panelControllers[i].panelCurrentIndex == panelIndex) { + // // found the controller for the panel requested + // panelctrlFound = pd.panelControllers[i]; + // break; + // } + // } + // if (panelctrlFound!==false) { panelctrlFound._redrawButtons(); } + // return true; + } +}; \ No newline at end of file