<?xml version="1.0"?>
<configure xmlns="http://namespaces.zope.org/zope"
           xmlns:i18n="http://namespaces.zope.org/i18n"
           i18n_domain="schooltool">

  <include file="security.zcml" />

  <!-- Application hook -->
  <adapter
      for="schooltool.app.interfaces.ISchoolToolApplication"
      factory=".TimetableInit"
      name="schooltool.timetables"
      />

  <!-- Subscribers -->

   <adapter
      factory="schooltool.timetable.TimetableModifiedSubscriber"
      name="validate_timetable_modified" />

   <adapter
      factory="schooltool.timetable.TimetableAddedSubscriber"
      name="validate_timetable_modified" />

  <subscriber
      for=".interfaces.IHaveTimetables"
      provides=".interfaces.ITimetableSource"
      factory="schooltool.timetable.source.MembershipTimetableSource"
      permission="zope.Public"
      />

  <subscriber
      for=".interfaces.IHaveTimetables"
      provides=".interfaces.ITimetableSource"
      factory="schooltool.timetable.source.InstructionTimetableSource"
      permission="zope.Public"
      />

  <subscriber
      for=".interfaces.IOwnTimetables"
      provides=".interfaces.ITimetableSource"
      factory="schooltool.timetable.source.OwnedTimetableSource"
      permission="zope.Public"
      />

  <adapter
      for=".interfaces.ITimetableSchemaContainer"
      factory="schooltool.app.app.SimpleNameChooser"
      provides="zope.container.interfaces.INameChooser" />

  <adapter
      factory=".TimetablesAdapter"
      trusted="true"
      permission="zope.Public" />

  <class class=".CompositeTimetables">
    <allow interface=".interfaces.ICompositeTimetables" />
  </class>

  <adapter
      factory=".CompositeTimetables"
      trusted="true"
      permission="zope.Public" />

  <utility
      provides=".interfaces.ITimetableModelFactory"
      name="SequentialDaysTimetableModel"
      component="schooltool.timetable.model.SequentialDaysTimetableModel"
      />

  <utility
      provides=".interfaces.ITimetableModelFactory"
      name="SequentialDayIdBasedTimetableModel"
      component="schooltool.timetable.model.SequentialDayIdBasedTimetableModel"
      />

  <utility
      provides=".interfaces.ITimetableModelFactory"
      name="WeeklyTimetableModel"
      component="schooltool.timetable.model.WeeklyTimetableModel"
      />

  <class class=".TimetableActivity">
    <allow interface=".interfaces.ITimetableActivity" />
  </class>

  <class class=".model.TimetableCalendarEvent">
    <!-- TTCalendarEvent does not have a __parent__, so fine-grained
         security declarations won't work. -->
    <allow interface=".interfaces.ITimetableCalendarEvent" />
  </class>

  <class class=".model.PersistentTimetableCalendarEvent">
    <allow interface=".interfaces.ITimetableCalendarEvent" />
    <require
       permission="schooltool.edit"
       set_schema=".interfaces.ITimetableCalendarEvent" />
  </class>

  <class class=".TimetableDict">
    <require permission="schooltool.edit"
             interface="zope.container.interfaces.IWriteContainer" />
    <require permission="schooltool.view"
             interface="zope.container.interfaces.IReadContainer" />
  </class>

  <adapter
      factory=".getTermForTimetableDict" />

  <adapter
      factory=".getTermForTimetable" />

  <adapter
      for=".interfaces.ITimetableDict"
      factory=".TimetableNameChooser"
      provides="zope.container.interfaces.INameChooser" />

  <interface
      interface=".interfaces.ITimetableSchemaContainer"
      type="zope.app.content.interfaces.IContentType"
      />

  <class class=".schema.TimetableSchemaContainer">
    <require permission="schooltool.edit"
             interface="zope.container.interfaces.IWriteContainer"
             set_attributes="default_id" />
    <require permission="zope.View"
             interface="zope.container.interfaces.IReadContainer"
             attributes="getDefault default_id" />
  </class>

  <interface
      interface=".interfaces.ITimetableSchemaContainerContainer"
      type="zope.app.content.interfaces.IContentType"
      />

  <class class=".schema.TimetableSchemaContainerContainer">
    <require permission="schooltool.edit"
             interface="zope.container.interfaces.IWriteContainer"
             set_attributes="default_id" />
    <require permission="zope.View"
             interface="zope.container.interfaces.IReadContainer"
             attributes="getDefault default_id" />
  </class>

  <class class=".Timetable">
    <allow interface=".interfaces.ITimetable" />
    <require permission="schooltool.edit"
             interface=".interfaces.ITimetableWrite"
             set_schema=".interfaces.ITimetable" />
  </class>

  <class class=".TimetableDay">
    <allow interface=".interfaces.ITimetableDay" />
    <require permission="schooltool.edit"
             interface=".interfaces.ITimetableDayWrite"
             set_schema=".interfaces.ITimetableDay" />
  </class>

  <interface
      interface=".interfaces.ITimetableSchema"
      type="zope.app.content.interfaces.IContentType"
      />

  <class class=".schema.TimetableSchema">
    <allow interface=".interfaces.ITimetableSchema" />
    <require permission="schooltool.edit"
             interface=".interfaces.ITimetableSchemaWrite"
             set_schema=".interfaces.ITimetableSchema" />
  </class>

  <class class=".schema.TimetableSchemaDay">
    <allow interface=".interfaces.ITimetableSchemaDay" />
  </class>

  <class class=".SchooldayTemplate">
    <allow interface=".interfaces.ISchooldayTemplate" />
    <require permission="schooltool.edit"
             interface=".interfaces.ISchooldayTemplateWrite"
             set_schema=".interfaces.ISchooldayTemplate" />
  </class>

  <class class=".model.SequentialDaysTimetableModel">
    <allow interface=".interfaces.IWeekdayBasedTimetableModel" />
  </class>

  <class class=".model.SequentialDayIdBasedTimetableModel">
    <allow interface=".interfaces.IDayIdBasedTimetableModel" />
  </class>

  <class class=".model.WeeklyTimetableModel">
    <allow interface=".interfaces.IWeekdayBasedTimetableModel" />
  </class>

  <class class=".SchooldaySlot">
    <allow interface=".interfaces.ISchooldaySlot" />
  </class>

  <!-- sample data -->
  <configure
      xmlns:zcml="http://namespaces.zope.org/zcml"
      zcml:condition="have devmode">

    <utility
        factory=".sampledata.SampleTimetableSchema"
        provides="schooltool.sampledata.interfaces.ISampleDataPlugin"
        name="ttschema"
        />

  </configure>

  <include package=".browser" />

  <subscriber
      for="schooltool.timetable.interfaces.ITimetableActivityAddedEvent"
      handler=".model.addEventsToCalendar" />

  <subscriber
      for=".interfaces.ITimetableSchema
           zope.lifecycleevent.interfaces.IObjectRemovedEvent"
      handler=".schema.clearTimetablesOnDeletion" />

  <subscriber
      for="schooltool.timetable.interfaces.ITimetableActivityRemovedEvent"
      handler=".model.removeEventsFromCalendar" />

  <subscriber
      for="schooltool.timetable.interfaces.ITimetableReplacedEvent"
      handler=".model.handleTimetableReplacedEvent" />

  <adapter
      factory=".schema.getTimetableSchemaContainer" />
  <adapter
      factory=".schema.getTimetableSchemaContainerForApp" />
  <adapter
      factory=".schema.getSchoolYearForTimetableSchemaContainer" />
  <adapter
      factory=".schema.getSchoolYearForTTschema" />

</configure>
