[gen] Calendar field: allow automatic check/uncheck of validation checkboxes within calendars (month and timeline views).
This commit is contained in:
		
							parent
							
								
									9b9853e570
								
							
						
					
					
						commit
						a4a9acfcfb
					
				
					 11 changed files with 82 additions and 7 deletions
				
			
		| 
						 | 
				
			
			@ -212,7 +212,8 @@ class Calendar(Field):
 | 
			
		|||
             var2="events=field.getOtherEventsAt(zobj, date, other, \
 | 
			
		||||
                     allEventNames, render, colors)"
 | 
			
		||||
             style=":field.getCellStyle(zobj, date, render, \
 | 
			
		||||
                        events)">::field.getTimelineCell(date, other, events, mayValidate)</td>
 | 
			
		||||
                      events)">::field.getTimelineCell(date, other, events, \
 | 
			
		||||
                                                   mayValidate, ajaxHookId)</td>
 | 
			
		||||
        </x>
 | 
			
		||||
        <td class="tlRight">::tlName</td>
 | 
			
		||||
       </tr>
 | 
			
		||||
| 
						 | 
				
			
			@ -289,8 +290,7 @@ class Calendar(Field):
 | 
			
		|||
         <input type="checkbox" name="deleteNext_cb" id=":cbId"
 | 
			
		||||
                onClick=":'toggleCheckbox(%s, %s)' % (q(cbId), q(hdId))"/>
 | 
			
		||||
         <input type="hidden" id=":hdId" name="deleteNext"/>
 | 
			
		||||
         <label lfor=":cbId"
 | 
			
		||||
                style="text-transform: none">:_('del_next_events')</label>
 | 
			
		||||
         <label lfor=":cbId" class="simpleLabel">:_('del_next_events')</label>
 | 
			
		||||
       </div>
 | 
			
		||||
       <input type="button" value=":_('yes')"
 | 
			
		||||
              onClick=":'triggerCalendarEvent(%s, %s)' % \
 | 
			
		||||
| 
						 | 
				
			
			@ -357,7 +357,8 @@ class Calendar(Field):
 | 
			
		|||
           <input type="checkbox" checked="checked" class="smallbox"
 | 
			
		||||
               if="mayValidate and (event.eventType in field.validation.schema)"
 | 
			
		||||
               id=":'%s_%s_%s' % (date.strftime('%Y%m%d'), event.eventType, \
 | 
			
		||||
                                  event.timeslot)"/>
 | 
			
		||||
                                  event.timeslot)"
 | 
			
		||||
               onclick=":'onCheckCbCell(this,%s)' % q(ajaxHookId)"/>
 | 
			
		||||
           <x>::event.getName(allEventNames)</x>
 | 
			
		||||
           <!-- Icon for delete this particular event -->
 | 
			
		||||
            <img if="mayDelete and not single" class="clickable"
 | 
			
		||||
| 
						 | 
				
			
			@ -447,6 +448,9 @@ class Calendar(Field):
 | 
			
		|||
              var2="js='validateEvents(%s)' % q(ajaxHookId)"
 | 
			
		||||
              onclick=":'askConfirm(%s,%s,%s)' % (q('script'), q(js, False), \
 | 
			
		||||
                        q(_('validate_events_confirm')))"/>
 | 
			
		||||
       <input type="checkbox" checked="checked" id=":'%s_auto' % ajaxHookId"
 | 
			
		||||
              class="smallbox"/>
 | 
			
		||||
       <label lfor="selectAuto" class="simpleLabel">:_('select_auto')</label>
 | 
			
		||||
      </div>
 | 
			
		||||
      <x>:getattr(field, 'pxView%s' % render.capitalize())</x>
 | 
			
		||||
     </div>''')
 | 
			
		||||
| 
						 | 
				
			
			@ -683,7 +687,7 @@ class Calendar(Field):
 | 
			
		|||
            return '<a href="%s">%s</a>' % (other.obj.url, other.obj.title)
 | 
			
		||||
        return self.timelineName(self, other)
 | 
			
		||||
 | 
			
		||||
    def getTimelineCell(self, date, other, events, mayValidate):
 | 
			
		||||
    def getTimelineCell(self, date, other, events, mayValidate, hook):
 | 
			
		||||
        '''Gets the content of a cell in a timeline calendar'''
 | 
			
		||||
        if events and mayValidate:
 | 
			
		||||
            # If at least one event from p_events is in the validation schema,
 | 
			
		||||
| 
						 | 
				
			
			@ -694,7 +698,8 @@ class Calendar(Field):
 | 
			
		|||
                    cbId = '%s_%s_%s' % (other.obj.id, other.field.name,
 | 
			
		||||
                                         date.strftime('%Y%m%d'))
 | 
			
		||||
                    return '<input type="checkbox" checked="checked" ' \
 | 
			
		||||
                           'class="smallbox" id="%s"/>' % cbId
 | 
			
		||||
                           'class="smallbox" id="%s" onclick="onCheckCbCell' \
 | 
			
		||||
                           '(this,\'%s\')"/>' % (cbId, hook)
 | 
			
		||||
            return ''
 | 
			
		||||
        # When there are multiple events, a background image is already shown
 | 
			
		||||
        if not events or (len(events) > 1): return ''
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -195,6 +195,10 @@ msgstr ""
 | 
			
		|||
msgid "select_delesect"
 | 
			
		||||
msgstr ""
 | 
			
		||||
 | 
			
		||||
#. Default: "Automatic (de)selection"
 | 
			
		||||
msgid "select_auto"
 | 
			
		||||
msgstr ""
 | 
			
		||||
 | 
			
		||||
#. Default: "You must select at least one element."
 | 
			
		||||
msgid "no_elem_selected"
 | 
			
		||||
msgstr ""
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -195,6 +195,10 @@ msgstr ""
 | 
			
		|||
msgid "select_delesect"
 | 
			
		||||
msgstr ""
 | 
			
		||||
 | 
			
		||||
#. Default: "Automatic (de)selection"
 | 
			
		||||
msgid "select_auto"
 | 
			
		||||
msgstr ""
 | 
			
		||||
 | 
			
		||||
#. Default: "You must select at least one element."
 | 
			
		||||
msgid "no_elem_selected"
 | 
			
		||||
msgstr ""
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -195,6 +195,10 @@ msgstr "Dieser Wert wird in diesem Feld nicht akzeptiert."
 | 
			
		|||
msgid "select_delesect"
 | 
			
		||||
msgstr "Alle aus- oder abwählen"
 | 
			
		||||
 | 
			
		||||
#. Default: "Automatic (de)selection"
 | 
			
		||||
msgid "select_auto"
 | 
			
		||||
msgstr ""
 | 
			
		||||
 | 
			
		||||
#. Default: "You must select at least one element."
 | 
			
		||||
msgid "no_elem_selected"
 | 
			
		||||
msgstr "Sie müssen mindestens ein Element auswählen."
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -196,6 +196,10 @@ msgstr "The value is not among possible values for this field."
 | 
			
		|||
msgid "select_delesect"
 | 
			
		||||
msgstr "(Un)select all"
 | 
			
		||||
 | 
			
		||||
#. Default: "Automatic (de)selection"
 | 
			
		||||
msgid "select_auto"
 | 
			
		||||
msgstr "Automatic (de)selection"
 | 
			
		||||
 | 
			
		||||
#. Default: "You must select at least one element."
 | 
			
		||||
msgid "no_elem_selected"
 | 
			
		||||
msgstr "You must select at least one element."
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -195,6 +195,10 @@ msgstr "Este valor no es permitido para este campo."
 | 
			
		|||
msgid "select_delesect"
 | 
			
		||||
msgstr "(des)seleccionar todo"
 | 
			
		||||
 | 
			
		||||
#. Default: "Automatic (de)selection"
 | 
			
		||||
msgid "select_auto"
 | 
			
		||||
msgstr ""
 | 
			
		||||
 | 
			
		||||
#. Default: "You must select at least one element."
 | 
			
		||||
msgid "no_elem_selected"
 | 
			
		||||
msgstr "Debe elegir al menos un elemento."
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -196,6 +196,10 @@ msgstr "Cette valeur n'est pas permise pour ce champ."
 | 
			
		|||
msgid "select_delesect"
 | 
			
		||||
msgstr "Tout (dé)sélectionner"
 | 
			
		||||
 | 
			
		||||
#. Default: "Automatic (de)selection"
 | 
			
		||||
msgid "select_auto"
 | 
			
		||||
msgstr "(dé)sélection automatique"
 | 
			
		||||
 | 
			
		||||
#. Default: "You must select at least one element."
 | 
			
		||||
msgid "no_elem_selected"
 | 
			
		||||
msgstr "Vous devez choisir au moins un élément."
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -195,6 +195,10 @@ msgstr "Il valore digitato non è possibile per questo campo."
 | 
			
		|||
msgid "select_delesect"
 | 
			
		||||
msgstr "Eliminare tutte le selezioni"
 | 
			
		||||
 | 
			
		||||
#. Default: "Automatic (de)selection"
 | 
			
		||||
msgid "select_auto"
 | 
			
		||||
msgstr ""
 | 
			
		||||
 | 
			
		||||
#. Default: "You must select at least one element."
 | 
			
		||||
msgid "no_elem_selected"
 | 
			
		||||
msgstr "Deve selezionare almeno un elemento."
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -195,6 +195,10 @@ msgstr "Deze waarde wordt niet geaccepteerd voor dit veld."
 | 
			
		|||
msgid "select_delesect"
 | 
			
		||||
msgstr "Alles (de)selecteren"
 | 
			
		||||
 | 
			
		||||
#. Default: "Automatic (de)selection"
 | 
			
		||||
msgid "select_auto"
 | 
			
		||||
msgstr ""
 | 
			
		||||
 | 
			
		||||
#. Default: "You must select at least one element."
 | 
			
		||||
msgid "no_elem_selected"
 | 
			
		||||
msgstr "U moet minstens één element selecteren."
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -142,6 +142,7 @@ td.search { padding-top: 8px }
 | 
			
		|||
.cellDashed { border: 1px dashed grey !important }
 | 
			
		||||
.noStyle { border: 0 !important; padding: 0 !important; margin: 0 !important }
 | 
			
		||||
.noStyle td { border:0 !important; padding:0 !important; margin:0 !important }
 | 
			
		||||
.simpleLabel { text-transform: none }
 | 
			
		||||
.translationLabel { background-color: #EAEAEA; border-bottom: 1px dashed grey;
 | 
			
		||||
                    margin-top: 0.5em; margin-bottom: 0.5em }
 | 
			
		||||
.section1 { font-size: 120%; margin: 0.45em 0em 0.1em 0;
 | 
			
		||||
| 
						 | 
				
			
			@ -198,4 +199,4 @@ td.search { padding-top: 8px }
 | 
			
		|||
.highlight { background-color: yellow }
 | 
			
		||||
.globalActions { margin-bottom: 4px }
 | 
			
		||||
.objectActions { margin: 2px 0 }
 | 
			
		||||
.smallbox { margin: 0 }
 | 
			
		||||
.smallbox { margin: 0; vertical-align: middle }
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -124,3 +124,40 @@ function validateEvents(hookId) {
 | 
			
		|||
                'discarded': discarded, 'mode': 'POST'};
 | 
			
		||||
  askAjax(hookId, null, params);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Function for (un)-checking checkboxes automatically
 | 
			
		||||
function onCheckCbCell(cb, hook) {
 | 
			
		||||
  // Is automatic selection on/off?
 | 
			
		||||
  var auto = document.getElementById(hook + '_auto');
 | 
			
		||||
  if (!auto.checked) return;
 | 
			
		||||
  // Get the current render mode
 | 
			
		||||
  var render = document.getElementById(hook)['ajax'].params['render'];
 | 
			
		||||
  // Change the state of every successive checkbox
 | 
			
		||||
  var timeline = render == 'timeline'; // Else, render is "month"
 | 
			
		||||
  // From the checkbox id, extract the date and the remaining part
 | 
			
		||||
  var elems = cb.id.split('_');
 | 
			
		||||
  if (timeline) { var date = elems[2], part = elems[0] + '_' + elems[1] + '_'; }
 | 
			
		||||
  else          { var date = elems[0], part = '_' + elems[1] + '_' + elems[2]; }
 | 
			
		||||
  // Create a Date instance
 | 
			
		||||
  var year = parseInt(date.slice(0,4)), month = parseInt(date.slice(4,6))-1,
 | 
			
		||||
      day = parseInt(date.slice(6,8));
 | 
			
		||||
  var next = new Date(year, month, day);
 | 
			
		||||
  // Change the status of successive checkboxes if found
 | 
			
		||||
  var checked = cb.checked;
 | 
			
		||||
  var nextId = nextCb = null;
 | 
			
		||||
  while (true) {
 | 
			
		||||
      // Compute the date at the next day
 | 
			
		||||
      next.setDate(next.getDate() + 1);
 | 
			
		||||
      month = (next.getMonth() + 1).toString();
 | 
			
		||||
      if (month.length == 1) month = '0' + month;
 | 
			
		||||
      day = next.getDate().toString();
 | 
			
		||||
      if (day.length == 1) day = '0' + day;
 | 
			
		||||
      date = next.getFullYear().toString() + month + day;
 | 
			
		||||
      // Find the next checkbox
 | 
			
		||||
      if (timeline) nextId = part + date;
 | 
			
		||||
      else          nextId = date + part;
 | 
			
		||||
      nextCb = document.getElementById(nextId);
 | 
			
		||||
      if (!nextCb) break;
 | 
			
		||||
      nextCb.checked = checked;
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue