#*
 * Aipo is a groupware program developed by Aimluck,Inc.
 * Copyright (C) 2004-2011 Aimluck,Inc.
 * http://www.aipo.com
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *#

## ---------------------------------------------------------------------------

#ALjavascript("javascript/aipo/schedule/form.js")
#ALjavascript("javascript/aipo/todo/form.js")
<script language="JavaScript" type="text/javascript">
//<![CDATA[

    dojo.require("aipo.calendar.weekly");
    dojo.require("aipo.widget.DropdownMemberFacilitypicker");

    ptConfig['$!portlet.ID'] = { group:"schedule", thisUrl:"$!jslink.getPortletById($!portlet.ID)", jsonUrl:"$!jslink.getPortletById($!portlet.ID).addQueryData('template','ScheduleWeeklyJSONScreen')", formUrl: '$!jslink.getPortletById($!portlet.ID).addQueryData('template','ScheduleFormScreen')', detailUrl: '$!jslink.getPortletById($!portlet.ID).addQueryData('template','ScheduleDetailScreen')', rowHeight:18, scheduleDivDaySum:7, tmpIndex:-1, distance:3, timeStart:$!time_start, timeEnd:$!time_end, timeInterval:$!time_interval, contentHeight: ($!time_end - $!time_start)*(60/$!time_interval)*18, contentScrollTop: $!time_start*(60/$!time_interval)*18, initUrl:'$!utils.escapeXML($!jslink.getPortletById($!portlet.ID).addQueryData("template","ScheduleScreen"))', reloadFunction:aipo.reloadPage };
	aipo.schedule.login_id = "$current_user_id";
	aipo.schedule.login_name = "$current_user_ln";
    aipo.schedule.login_aliasname = "$current_user";
//]]>
</script>

<script language="JavaScript" type="text/javascript">
//<![CDATA[

    var portletId = '$!portlet.ID';
    var initCalendar = initCalendar || {};
    initCalendar['$!portlet.ID'] = function(isAjax) {

    ptConfig['$!portlet.ID'].isScroll = false;

    aipo.schedule.login_id = "$current_user_id";
    aipo.schedule.login_name = "$current_user_ln";
    aipo.schedule.login_aliasname = "$current_user";
    var portletId = '$!portlet.ID';
    dojo.style("termScheduleDivAdd_"+portletId,'opacity', 0);
    dojo.style("scheduleDivAdd00_"+portletId,'opacity', 0);
    dojo.style("scheduleDivAdd01_"+portletId,'opacity', 0);
    dojo.style("scheduleDivAdd02_"+portletId,'opacity', 0);
    dojo.style("scheduleDivAdd03_"+portletId,'opacity', 0);
    dojo.style("scheduleDivAdd04_"+portletId,'opacity', 0);
    dojo.style("scheduleDivAdd05_"+portletId,'opacity', 0);
    dojo.style("scheduleDivAdd06_"+portletId,'opacity', 0);
    dojo.style(dojo.byId('weeklyScrollPane_$!portlet.ID'), 'height', ($!time_end - $!time_start)*(60/$!time_interval)*18 + 'px');

    var mpHTML = document.getElementById("memberpicker-$!portlet.ID");
    if(mpHTML){
       var params = {
            widgetId: "member_to-$!portlet.ID",
            iconURL: "themes/$!theme/images/icon/icon_member.gif",
            iconAlt: "参加者選択",
            selectId: "member_to-$!portlet.ID" ,
            inputId: "member_to_input-$!portlet.ID",
            buttonAddId: "button_member_add-$!portlet.ID",
            buttonRemoveId: "button_member_remove-$!portlet.ID",
            memberFromId: "tmp_member_from-$!portlet.ID" ,
            memberToId: "tmp_member_to-$!portlet.ID" ,
            memberFromUrl: "$!jslink.getPortletById($!portlet.ID).addQueryData('template','UserFacilityLiteJSONScreen').addQueryData('mode','group').addQueryData('groupname','LoginUser')",
            memberFromOptionKey: "name",
            memberFromOptionValue: "aliasName",
            groupSelectId: "tmp_group-$!portlet.ID",
            groupSelectOptionKey: "groupId",
            groupSelectOptionValue: "name",
            memberGroupUrl: "$!jslink.getPortletById($!portlet.ID).addQueryData('template','UserGroupLiteJSONScreen')",
            changeGroupUrl: "$!jslink.getPortletById($!portlet.ID).addQueryData('template','UserFacilityLiteJSONScreen').addQueryData('mode','group')" ,
            tmpPortretId: "$!portlet.ID"
       };
       var mp = new aipo.widget.DropdownMemberFacilitypicker(params , mpHTML);
	}

	var mpicker = dijit.byId("memberpicker-$!portlet.ID");
    if(mpicker){
        var select = dojo.byId('init_memberlist-$!portlet.ID');
        var i;
        var s_o = select.options;
        for(i = 0 ; i < s_o.length; i ++ ) {
            mpicker.addOptionSync(s_o[i].value,s_o[i].text,true);
        }
    }
    var i;
    for(i =0; i < ptConfig['$!portlet.ID'].scheduleDivDaySum; i++) {
      tmpDraggable = new aipo.calendar.WeeklyScheduleAddDraggable('scheduleDivAdd0'+i+'_$!portlet.ID' , {idx: i});
      tmpDraggable.portletId = '$!portlet.ID';
      tmpDraggable.index = i;
    };

    tmpDraggable = new aipo.calendar.WeeklyTermScheduleAddDraggable('termScheduleDivAdd_$!portlet.ID',  {idx: 0});
    tmpDraggable.portletId = '$!portlet.ID';

    aipo.calendar.populateWeeklySchedule('$!portlet.ID');


  };

//]]>
</script>
#if($!hasMinimumAuthority)
#parse("/portlets/html/ja/ajax-schedule.vm")
#else
#parse("/portlets/html/PermissionError.vm")
#end
