简体   繁体   English

无法从旧的jscalendar彻底升级到新的jscal2版本

[英]Unable to cleanly upgrade from old jscalendar to new jscal2 version

Why I need to upgrade 为什么我需要升级
I need to have the feature of disabling of navigating to dates past some date, so I am considering upgrading from jscalendar (http://www.dynarch.com/projects/calendar/old/) to jscal2 (http://www.dynarch.com/projects/calendar/) in my project. 我需要具有禁用导航到某个日期之后的日期的功能,所以我正在考虑从jscalendar(http://www.dynarch.com/projects/calendar/old/)升级到jscal2(http:// www。 dynarch.com/projects/calendar/)在我的项目中。 But in homepage and documentation of the new jscal2, following things are mentioned - 但是在主页和新jscal2的文档中,提到了以下内容 -

  • Note that this is a whole new product. 请注意,这是一个全新的产品。

  • Note that it is not compatible with our old calendar project. 请注意,它与我们的旧日历项目不兼容。

Problem 问题
So, I am confused, if an upgrade with minimal changes in my current project is possible and if so how exactly to do that. 所以,我很困惑,如果我当前项目中的变化很小,那么如果可能的话,那么究竟如何做到这一点。 I have already posted a comment in the site - http://www.dynarch.com/projects/calendar/discussion/ and waiting for some reply. 我已在网站上发表评论 - http://www.dynarch.com/projects/calendar/discussion/并等待一些回复。 In the meantime, I thought those who have used the product might be able to help, so here is my question. 与此同时,我认为那些使用过该产品的人可能会提供帮助,所以这是我的问题。

The existing code of my project uses jscalendar version 1.51 (I see there is this line written in the calendar.js file - calendar.js,v 1.51). 我的项目的现有代码使用jscalendar版本1.51(我看到有这行写在calendar.js文件中 - calendar.js,v 1.51)。 There are some lines of these helper code, which contains the function showCalendar() which calls var cal = new Calendar() , like this - 这些帮助程序代码有一些行,其中包含function showCalendar() ,它调用var cal = new Calendar() ,就像这样 -

function setActiveStyleSheet()
function selected()
function closeHandler()
function showCalendar(){
    ...
    //some lines of code
    ... 
    var cal = new Calendar(1, null, selected, closeHandler);
    ...
    //some lines of code
    ... 
}
....

Check the same here http://pastebin.com/QHAb0WdB 在这里查看相同的http://pastebin.com/QHAb0WdB

But I don't see that helper script in the new version's demos which I downloaded today. 但我在今天下载的新版本的演示中没有看到帮助脚本。 I tried by removing inclusion of all the js/css files of the old version, included files of the new version, but keeping only the same jscalendar.js, but it gives this js error - 我尝试删除包含旧版本的所有js / css文件,包含新版本的文件,但只保留相同的jscalendar.js,但它给出了这个js错误 -

_dynarch_popupCalendar is not defined
[Break On This Error] if (_dynarch_popupCalendar != null) { 

I guessed, I could restrict the past date by adding the onSelect param to the new Calendar initiation like this - 我猜,我可以通过将onSelect参数添加到新的Calendar启动来限制过去的日期,就像这样 -

onSelect: function() {
   var date = Calendar.intToDate(this.selection.get());
   LEFT_CAL.args.min = date; // setting minimum date, so as to not allow browsing past this date
   LEFT_CAL.redraw();
   this.hide();
}

But I did not try anything after modifying in the helper script failed. 但是在帮助程序脚本中修改失败后我没有尝试任何操作。

Please let me know if you have idea about the correct upgrading process. 如果您对正确的升级过程有所了解,请告诉我。 I am not sure what I am missing something. 我不确定我错过了什么。

I had thought it would be as simple as just changing inclusion of the js and may be css files and no change would be needed in code. 我曾经认为它只是简单地改变js的包含并且可能是css文件而且代码中不需要改变。 I would just need to set some more config parameters corresponding to disabling the dates as I desire. 我只需要根据需要设置一些更多的配置参数来禁用日期。

Update 更新
Making it simpler now!! 让它变得更简单!!

First of all a correction, this is not an upgrade, because the doc of jscal2 (the one which I want to use) says - 首先是修正,这不是升级,因为jscal2(我想使用的那个)的文档说 -

  • Note that this is a whole new product. 请注意,这是一个全新的产品。

  • Note that it is not compatible with our old calendar project. 请注意,它与我们的旧日历项目不兼容。

I understood that the minimum needed to invoke a calendar is - 我知道调用日历所需的最低限度是 -

Calendar.setup({
    cont          : "calendar-container"  // a cont or a trigger
});

All arguments are optional. 所有参数都是可选的。 However, you should provide one of cont (for inline calendars) or trigger for popup calendars, or else provide your own code to display a popup calendar. 但是,您应该提供cont(用于内联日历)或弹出日历的触发器之一,或者提供您自己的代码以显示弹出日历。 We'll see how this can be done later. 我们将看到以后如何做到这一点。

I think I need to write that code to display a popup calendar, like this - 我想我需要编写代码才能显示弹出日历,就像这样 -

function showCalendar(){
    ...
    //some lines of code
    ... 
    var cal = new Calendar();
    ...
    //some code to display the calendar, based on the details already being passed to this function - which button was clicked, where to attach the calendar, etc.
    ... 
}

But, I did not see any such code in the documentation. 但是,我没有在文档中看到任何此类代码。 I tried with this code, but does not work - 我尝试使用此代码,但不起作用 -

function trigger()
{

cal = new Calendar({
        inputField: "startdate",
        dateFormat: "%B %d, %Y",
        bottomBar: false,
        showTime:true
        }
});
cal.redraw(); //blind try - does not work, but it does not give any errors. But I 
don't see any other proper function to do this in the doc.  
}

Any idea guys? 伙计们好吗?

Thanks 谢谢

Bounty Started 赏金开始了
Have found a not-so-good, unoptimized solution, posted it in answer, but still looking for a proper solution. 找到了一个不太好的,未经优化的解决方案,将其发布在答案中,但仍在寻找合适的解决方案。

Answering myself, but still looking for a proper solution. 回答自己,但仍在寻找合适的解决方案。 I wrote this code to keep using the showCalendar() function after moving from jscalendar to jsCal2 - 我写了这段代码,以便在从jscalendar转移到jsCal2之后继续使用showCalendar()函数 -

var instance = null; //tracker of calendar instances

function showCalendar(id, format, showsTime, showsOtherMonths) 
{
    //some code here


    //create a dummy holder so as to place the calendar inside, so that I can use the "cont" attribute. (Have to use either cont or trigger. )
    if(instance!=null)
    {
        instance.hide();
        instance = null;
        $("table.DynarchCalendar-topCont").remove(); //I am having to kill the earlier calendar instance on every calendar display call, because otherwise multiple instances were getting created in DOM, causing confusion. 

        //get date in input field - since earlier instance is killed

    }


if($("div#container").length == 0)
    {
        $('body').append('<div id="container" style="position: absolute;">&nbsp;</div>');
    }


        cal = new Calendar({
                cont: "container",
                inputField: id,
                dateFormat: format,
                bottomBar: false,
                min: minDateLimit,
                showTime: showsTime,
                weekNumbers: true,
                selection : intDate,
                onSelect: function() {

                    //set selected value into attached input field
                    var selectedDate = this.selection.get();
                    date = Calendar.intToDate(selectedDate);
                    date = Calendar.printDate(date, format);
                    $('#'+id).val(date);

                    this.hide();
                },
                onBlur: function() { //clicking outside hide calendar
                    this.hide();
            }
        });

    cal.moveTo(intDate); //since new instance of calendar is being created everytime, need to move to the date 
    cal.popup(id,"Br");
    instance = cal;

    return false;
}

I tried a lot for some proper way to initiate a popup calendar from inside an inline onclick function (showcalendar() function here). 我尝试了一些正确的方法来从内联onclick函数(此处为showcalendar()函数)启动弹出日历。 But, in the documentation of new jscal2 calendar, the initiation of calendar supports only binding method, and no way to do the same from inside a function which is called from an inline onclick. 但是,在新的jscal2日历的文档中,日历的启动仅支持绑定方法,并且无法从内联onclick调用的函数内部执行相同的操作。 Here is the documentation - http://www.dynarch.com/projects/calendar/doc/ (check the trigger and cont parameters, one of which is mandatory). 这是文档 - http://www.dynarch.com/projects/calendar/doc/ (检查triggercont参数,其中一个是必需的)。 I applied some dirty fix to do the same and as a result had to write code to do some things which are otherwise automatically done by the plugin (eg display of selected date = date on input field, on display of calendar). 我应用了一些脏修复来做同样的事情,因此必须编写代码来做一些其他由插件自动完成的事情(例如显示所选日期=日期在输入字段上,日历显示)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM