diff --git a/README.md b/README.md index 6694124..08d4259 100644 --- a/README.md +++ b/README.md @@ -124,10 +124,9 @@ xgcalendar **请求返回** ->{"events":[],"issort":true,"start":"\/Date(1261353600000)\/","end":"\/Date(1261958399000)\/","error":null} +>{"events":[],"start":"\/Date(1261353600000)\/","end":"\/Date(1261958399000)\/","error":null} `events`的结构同参数`eventItems`的结构, -`issort`是否已在服务端排序(请在服务端做好排序), `start`和`end`是本次请求的开始时间和结束时间,这里是date的json表示法 `error`是业务异常对象,可在服务端生成,结构为:`{ErrorCode:””,ErrorMsg:””}` 可在`onRequestDataError`中捕获,并做友好的提示。 @@ -198,4 +197,4 @@ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/README_EN.md b/README_EN.md index 1ce7d90..1eb7f9d 100644 --- a/README_EN.md +++ b/README_EN.md @@ -126,10 +126,9 @@ The server must compute the start date and end date, from the given showdate, vi **response data sample** ->{"events":[],"issort":true,"start":"\/Date(1261353600000)\/","end":"\/Date(1261958399000)\/","error":null} +>{"events":[],"start":"\/Date(1261353600000)\/","end":"\/Date(1261958399000)\/","error":null} `events`: Data format is identical to `eventItems`. -`issort`: Whether are sorted (please do that on the server side). `start` and `end`: Current view date range, json date format. `error`: An exception object can be generated by the server. Format is `{ErrorCode:””,ErrorMsg:””}`. It is handled by `onRequestDataError`. diff --git a/code/js/plugin/xgcalendar.js b/code/js/plugin/xgcalendar.js index 7b788d2..8894468 100644 --- a/code/js/plugin/xgcalendar.js +++ b/code/js/plugin/xgcalendar.js @@ -1130,7 +1130,7 @@ } } else { - responseData(data, data.start, data.end); + responseData(data); pushER(data.start, data.end); } if (option.onAfterRequestData && $.isFunction(option.onAfterRequestData)) { @@ -1169,90 +1169,37 @@ alert("url" + i18n.xgcalendar.i_undefined); } } - function responseData(data, start, end) { - var events; - if (data.issort == false) { - if (data.events && data.events.length > 0) { - events = data.sort(function(l, r) { return l[2] > r[2] ? -1 : 1; }); - } - else { - events = []; - } - } - else { - events = data.events; - } - ConcatEvents(events, start, end); + function responseData(data) { + ConcatEvents(data.events); render(); - } - function clearrepeat(events, start, end) { - var jl = events.length; - if (jl > 0) { - var es = events[0][2]; - var el = events[jl - 1][2]; - for (var i = 0, l = option.eventItems.length; i < l; i++) { - if (option.eventItems[i][2] > el || jl == 0) { - break; - } - if (option.eventItems[i][2] >= es) { - for (var j = 0; j < jl; j++) { - if (option.eventItems[i][0] == events[j][0] && option.eventItems[i][2] < start) { - events.splice(j, 1); //重复了移除 - jl--; - break; - } - } - } - } - } - } - function ConcatEvents(events, start, end) { - if (!events) { + function ConcatEvents(events) { + if (!events) events = []; - } - if (events) { - if (option.eventItems.length == 0) { - option.eventItems = events; - } - else { - //清理重复 - clearrepeat(events, start, end); - var l = events.length; - var sl = option.eventItems.length; - var sI = -1; - var eI = sl; - var s = start; - var e = end; - if (option.eventItems[0][2] > e) // 第一个的开始时间都要大于请求的最后一个的开始时间 - { - option.eventItems = events.concat(option.eventItems); - return; - } - if (option.eventItems[sl - 1][2] < s) // 最后一个的开始时间都要小于请求的第一个的开始时间 - { - option.eventItems = option.eventItems.concat(events); - return; - } - for (var i = 0; i < sl; i++) { - if (option.eventItems[i][2] >= s && sI < 0) { - sI = i; - //continue; - } - if (option.eventItems[i][2] > e) { - eI = i; - break; - } - } - var e1 = sI <= 0 ? [] : option.eventItems.slice(0, sI); - var e2 = eI == sl ? [] : option.eventItems.slice(eI); - option.eventItems = [].concat(e1, events, e2); - events = e1 = e2 = null; - } + events = [].concat(option.eventItems, events); + + // sort by start date, then by event id + events.sort(function(l, r) { + if (l[2] < r[2]) + return -1; + if (l[2] > r[2]) + return 1; + // here l[2] == r[2] + return l[0] < r[0] ? -1 : 1; + }); + + // remove duplicates + for (i=0; i eventList, DateTime startDate, DateTi events = eventList; start = startDate; end = endDate; - issort = true; } public JsonCalendarViewData(List eventList, DateTime startDate, DateTime endDate, bool isSort) { + /* obsolete function */ start = startDate; end = endDate; events = eventList; - issort = isSort; } public JsonCalendarViewData(JsonError jsonError) { @@ -28,6 +27,7 @@ public JsonCalendarViewData(JsonError jsonError) public List events { get; private set; } public bool issort { + /* obsolete */ get; private set; } diff --git a/example/aspnet/AzureCalendarMvcWeb/Views/Home/Test.aspx b/example/aspnet/AzureCalendarMvcWeb/Views/Home/Test.aspx index bfa7911..74557c7 100644 --- a/example/aspnet/AzureCalendarMvcWeb/Views/Home/Test.aspx +++ b/example/aspnet/AzureCalendarMvcWeb/Views/Home/Test.aspx @@ -12,7 +12,7 @@