Exemplo n.º 1
0
    def move(self, pos, fieldset_index):
        """ AJAX method to change field position within its schema.
        The position is relative to the fieldset.
        """
        schema = IEditableSchema(self.schema)
        fieldname = self.field.__name__
        pos = int(pos)
        fieldset_index = int(fieldset_index)
        fieldset_index -= 1  # index 0 is default fieldset

        fieldsets = self.schema.queryTaggedValue(FIELDSETS_KEY, [])
        new_fieldset = fieldset_index >= 0 and fieldsets[fieldset_index] or None
        schema.changeFieldFieldset(fieldname, new_fieldset)

        ordered_field_ids = [info[0] for info in sortedFields(self.schema)]
        if new_fieldset:
            old_field_of_position = new_fieldset.fields[pos]
            new_absolute_position = ordered_field_ids.index(
                old_field_of_position)
        else:
            new_absolute_position = pos

        # if fieldset changed, update fieldsets
        schema.moveField(fieldname, new_absolute_position)

        notifyContainerModified(self.schema)
        notify(SchemaModifiedEvent(self.aq_parent.aq_parent))
Exemplo n.º 2
0
    def move(self, pos, fieldset_index):
        """ AJAX method to change field position within its schema.
        The position is relative to the fieldset.
        """
        schema = IEditableSchema(self.schema)
        fieldname = self.field.__name__
        pos = int(pos)
        fieldset_index = int(fieldset_index)
        fieldset_index -= 1  # index 0 is default fieldset

        fieldsets = self.schema.queryTaggedValue(FIELDSETS_KEY, [])
        new_fieldset = fieldset_index >= 0 and fieldsets[
            fieldset_index] or None
        schema.changeFieldFieldset(fieldname, new_fieldset)

        ordered_field_ids = [info[0] for info in sortedFields(self.schema)]
        if new_fieldset:
            old_field_of_position = new_fieldset.fields[pos]
            new_absolute_position = ordered_field_ids.index(
                old_field_of_position)
        else:
            new_absolute_position = pos

        # if fieldset changed, update fieldsets
        schema.moveField(fieldname, new_absolute_position)

        notifyContainerModified(self.schema)
        notify(SchemaModifiedEvent(self.__parent__.__parent__))
Exemplo n.º 3
0
    def change(self, fieldset_index):
        """ AJAX method to change the fieldset of a field
        """
        schema = self.context.field.interface
        field_name = self.context.field.__name__
        fieldset = get_fieldset_from_index(schema, fieldset_index)
        position = new_field_position(schema, fieldset_index)

        editable_schema = IEditableSchema(schema)
        editable_schema.changeFieldFieldset(field_name, fieldset)
        editable_schema.moveField(field_name, position)

        notifyContainerModified(schema)
        notify(SchemaModifiedEvent(self.__parent__.__parent__))
Exemplo n.º 4
0
    def change(self, fieldset_index):
        """ AJAX method to change the fieldset of a field
        """
        fieldset_index = int(fieldset_index)
        fieldsets = self.schema.queryTaggedValue(FIELDSETS_KEY, [])
        field_name = self.field.__name__

        # get current fieldset
        fieldset_fields = []
        for fieldset in fieldsets:
            fieldset_fields.extend(fieldset.fields)

        # get future fieldset
        fieldset_index -= 1

        if fieldset_index >= 0:
            # the field has not been moved into default
            next_fieldset = fieldsets[fieldset_index]
        else:
            next_fieldset = None

        # computing new Position, which is the last position of the new
        # fieldset
        ordered_field_ids = [info[0] for info in sortedFields(self.schema)]
        if next_fieldset is None:
            # if this is the default,
            new_position = ordered_field_ids.index(fieldset_fields[0])
        else:
            # first we get the first of the fieldsets after the new one
            new_position = None
            for fieldset in fieldsets[fieldsets.index(next_fieldset) + 1:]:
                if len(fieldset.fields) > 0:
                    new_position = ordered_field_ids.index(
                        fieldset.fields[0]) - 1
                    break
            else:
                new_position = len(ordered_field_ids) - 1

        schema = IEditableSchema(self.schema)
        schema.changeFieldFieldset(field_name, next_fieldset)
        schema.moveField(field_name, new_position)

        notifyContainerModified(self.schema)
        notify(SchemaModifiedEvent(self.aq_parent.aq_parent))
Exemplo n.º 5
0
    def change(self, fieldset_index):
        """ AJAX method to change the fieldset of a field
        """
        fieldset_index = int(fieldset_index)
        fieldsets = self.schema.queryTaggedValue(FIELDSETS_KEY, [])
        field_name = self.field.__name__

        # get current fieldset
        fieldset_fields = []
        for fieldset in fieldsets:
            fieldset_fields.extend(fieldset.fields)

        # get future fieldset
        fieldset_index -= 1

        if fieldset_index >= 0:
            # the field has not been moved into default
            next_fieldset = fieldsets[fieldset_index]
        else:
            next_fieldset = None

        # computing new Position, which is the last position of the new
        # fieldset
        ordered_field_ids = [info[0] for info in sortedFields(self.schema)]
        if next_fieldset is None:
            # if this is the default,
            new_position = ordered_field_ids.index(fieldset_fields[0])
        else:
            # first we get the first of the fieldsets after the new one
            new_position = None
            for fieldset in fieldsets[fieldsets.index(next_fieldset) + 1:]:
                if len(fieldset.fields) > 0:
                    new_position = ordered_field_ids.index(
                        fieldset.fields[0]) - 1
                    break
            else:
                new_position = len(ordered_field_ids) - 1

        schema = IEditableSchema(self.schema)
        schema.changeFieldFieldset(field_name, next_fieldset)
        schema.moveField(field_name, new_position)

        notifyContainerModified(self.schema)
        notify(SchemaModifiedEvent(self.aq_parent.aq_parent))