ian-cox / Kirby-Structure-Tabs

Tabbed Fields for Structured Content
39 stars 4 forks source link

Alternative: using field option instead of field #2

Open xu-chris opened 9 years ago

xu-chris commented 9 years ago

As I wrote I've played a bit around with your awesome tabs. I've produced this blueprint snippet:

  events:
    label: Events
    type: eventlist
    fields:

      play:
        label: Aufführung
        type: structuretab
      play-item:
        label: Stück
        type: select
        options: query
        query:
          page: repertoire
          value: '{{uri}}'
          text: '{{title}}'
      play-informations:
        label: Weitere Spielplan-Informationen
        type: textarea
        size: small
      play-startdate:
        label: Von (Datum)
        type: date
        format: DD.MM.YYYY
        width: 1/2
        required: true
      play-starttime:
        label: Von (Zeit)
        type: time
        interval: 30
        default: 20:00
        width: 1/2
        required: true
      play-availability:
        label: Kartenbestand
        type: select
        default: InStock
        width: 1/2
        options:
          KartenVorhanden: Karten vorhanden
          FälltAus: Fällt aus
          NurAbendkasse: Nur Abendkasse
          NurOnlone: Nur Online
          Ausgebucht: Ausgebucht
          Frei: Freier Eintritt

      guest:
        label: Gastspiel
        type: structuretab
      guest-title:
        label: Stücktitel
        type: text
        help: Alternativ bei Gastspiel
      guest-informations:
        label: Weitere Spielplan-Informationen
        type: textarea
        size: small
      guest-startdate:
        label: Von (Datum)
        type: date
        format: DD.MM.YYYY
        width: 1/2
        required: true
      guest-starttime:
        label: Von (Zeit)
        type: time
        interval: 30
        default: 20:00
        width: 1/2
        required: true
      guest-enddate:
        label: Bis (Datum)
        type: date
        format: DD.MM.YYYY
        width: 1/2
        help: optional
      guest-endtime:
        label: Bis (Zeit)
        type: time
        interval: 30
        width: 1/2
        help: optional
      guest-dateattributes:
        label: Event-Merkmal
        type: tags
        separator: ", "
        lowercase: false
        width: 1/2
        data:
          - Premiere
          - B-Premiere
          - Deutsche Erstaufführung
          - Deutschsprachige Erstaufführung
          - öffentliche Probe
          - On Tour
          - Publikumsgespräch
          - Uraufführung
          - Voraufführung
          - Wiederaufnahme
          - Sondertermin für Gruppen
          - Sondertermin für KiTas
          - Sondertermin für Schulen
          - Zusatztermin
          - zum letzten Mal
          - zum letzten Mal in dieser Spielzeit
      guest-availability:
        label: Kartenbestand
        type: select
        default: InStock
        width: 1/2
        options:
          KartenVorhanden: Karten vorhanden
          FälltAus: Fällt aus
          NurAbendkasse: Nur Abendkasse
          NurOnlone: Nur Online
          Ausgebucht: Ausgebucht
          Frei: Freier Eintritt

      event:
        label: Sonstiges Event (z.B. TdoT)
        type: structuretab
      event-title:
        label: Event-Titel
        type: text
      event-informations:
        label: Weitere Spielplan-Informationen
        type: textarea
        size: small
      event-startdate:
        label: Von (Datum)
        type: date
        format: DD.MM.YYYY
        width: 1/2
        required: true
      event-starttime:
        label: Von (Zeit)
        type: time
        interval: 30
        default: 20:00
        width: 1/2
        required: true
      event-enddate:
        label: Bis (Datum)
        type: date
        format: DD.MM.YYYY
        width: 1/2
        help: optional
      event-endtime:
        label: Bis (Zeit)
        type: time
        interval: 30
        width: 1/2
        help: optional
      event-availability:
        label: Kartenbestand
        type: select
        default: InStock
        width: 1/2
        options:
          KartenVorhanden: Karten vorhanden
          FälltAus: Fällt aus
          NurAbendkasse: Nur Abendkasse
          NurOnlone: Nur Online
          Ausgebucht: Ausgebucht
          Frei: Freier Eintritt

      holidays:
        label: Ferien
        type: structuretab
      holidays-title:
        label: Pause-Titel
        type: text
        help: Alternativ bei Gastspiel
      holidays-informations:
        label: Weitere Spielplan-Informationen
        type: textarea
        size: small
      holidays-startdate:
        label: Von (Datum)
        type: date
        format: DD.MM.YYYY
        width: 1/2
        required: true
      holidays-starttime:
        label: Von (Zeit)
        type: time
        interval: 30
        default: 20:00
        width: 1/2
        required: true
      holidays-enddate:
        label: Bis (Datum)
        type: date
        format: DD.MM.YYYY
        width: 1/2
        help: optional
      holidays-endtime:
        label: Bis (Zeit)
        type: time
        interval: 30
        width: 1/2
        help: optional

I'm using the tabs to make my forms more easy and simple. As you can see I've produced multiple startdate and title fields and it feels wrong to use your tab plugin like this.

My naive version of this would be this:

events:
    label: Events
    type: eventlist
    fields:
      item:
        label: Stück
        type: select
        options: query
        width: 1/2
        tabs: Aufführung
        query:
          page: repertoire
          value: '{{uri}}'
          text: '{{title}}'
      title:
        label: Stücktitel
        type: text
        width: 1/2
        tabs: 
          - Gastspiel
          - Event
          - Ferien
        help: Alternativ bei Gastspiel
.
.
.

(..and so on)

As you see I would use a field option called tabs to specify in which tab I would like to see this item. And with this you could specify one or multiple tabs with dashes. If you want to use two fields in the same tab content you have to write the same tab name into this field option.

I don't know if this is possible but maybe this is something you would like to make. Of course the checkbox function of the tabs is still important. Maybe this could be combined with a invisible field which gets filled with the active field? Dunno..

ian-cox commented 9 years ago

Thanks for posting your blueprint, saves me some testing time for sure!

ian-cox commented 9 years ago

and yes, I was thinking about a native version as well but I think I'd have to modify the Base field which gets extended into everything else... That might require messing with the core.

xu-chris commented 9 years ago

Of course! I have full respect for your talent! I couldn't do it better ;-)

I've played a bit with the structure field. It's possible to simply extend it to rewrite it's functions. Just do this:

<?php

class EventlistField extends StructureField {

 . . . do awesome stuff here . . .

}

I think the same is also possible with the base field. The worse thing about this is that you maybe have to copy some code out of the initial file to modify the function you want to. It's not the best solution but maybe @bastianallgeier may help you?

ian-cox commented 9 years ago

From what I know, that definitely sounds possible! I wish my understanding of OOPHP was better. If anyone wants to help out, I'm more than happy to look at pull requests.

The plugin is based on the checkbox field with a few slight modifications. The majority of the work is actually presentational code which is being done with with jQuery and CSS.