# -*- coding: utf-8
# Copyright 2006 by Meelis Mets
from Products.Archetypes.public import BaseSchema, Schema
from Products.Archetypes.public import StringField, LinesField
from Products.Archetypes.public import LinesWidget, TextAreaWidget, StringWidget, SelectionWidget
from Widgets import StructuredTaskWidget, DictField
from Products.Archetypes.public import BaseContent, registerType
from Globals import InitializeClass
from Products.CMFCore.utils import getToolByName
import random
import urllib
import time
from AccessControl import ClassSecurityInfo, Unauthorized
from config import PROJECT_NAME
from BaseTask import BaseTask
from Permissions import *
newschema = BaseTask.schema.copy()
newschema["Deadline"].widget.description_msgid = "desc_stask_deadline"
newschema["Target"].widget.description_msgid = "desc_stask_target"
newschema["Lecturer"].widget.description_msgid = "desc_stask_lecturer"
newschema["refsForAnswers"].widget.description_msgid = "desc_stask_related_competencies"
schema = newschema + Schema((
StringField('help',
widget=TextAreaWidget(
label="Help text",
description="Add help text here, this text should describe how to fill form or something like that",
label_msgid='label_help',
description_msgid='help_desc',
i18n_domain="eportfolio"),
),
DictField('datafields',
accessor='getDatafields',
mutator='setDatafields',
widget=StructuredTaskWidget(
label='Fields',
label_msgid='label_datafields',
description='Data fields',
description_msgid='help_datafields',
visible={'view':'visible','edit':'invisible'},
i18n_domain="eportfolio"
),
),
))
schema.moveField('attachedFile', pos='bottom')
schema.moveField('refsForAnswers', before='attachedFile')
class StructuredWidgetFunctions:
def arrayToString(self, array):
""" array to string splittable by \n """
string = ''
for value in array:
string = string+value+'\n'
return string
def arrayToBr(self, array):
""" array to string splittable by
"""
string = ''
for value in array:
string = string+value+'
'
return string
def countLines(self, text):
""" count lines """
counter = 0
splitter = text.split("\n")
counter = len(splitter)
return counter
def addFields(self, REQUEST):
""" add Fields """
title = REQUEST.get('title')
help = REQUEST.get('help')
type = REQUEST.get('type')
required = REQUEST.get('required')
size = REQUEST.get('size')
edit = REQUEST.get('edit_mode')
options = REQUEST.get('options')
if(type=='subtitle'):
size = REQUEST.get('format')
id = REQUEST.get('id')
if (id == 'none' or id == ''):
id = str(random.randrange(10000,99999,1))+str(time.time())
if (size == '' and type == 'text'):
size = 15
if (size == '' and type == 'textarea'):
size = 3
field = {'id': id, 'title': title, 'help': help, 'type': type, 'required': required, 'size': size, 'options': options}
if (edit=='none'):
if(title != ''):
self.appFields.append(field)
else:
i=0
for f in self.appFields:
if (edit == f['id']):
if(title != ''):
self.appFields[i]=field
i=i+1
self._p_changed = 1
def getRequired(self):
"""req"""
req = "["
for field in self.appFields:
if(field['required']=='on'):
req=req+"\'"+field['id']+"\',"
req = req[:-1]
return req+"]"
def removeFields(self, REQUEST):
""" remove Fields """
newAppFields = []
nr=0
id = REQUEST.get('idd')
for field in self.appFields:
if (id != field['id']):
newAppFields.append(self.appFields[nr])
nr=nr+1
self.appFields = newAppFields
self._p_changed = 1
def moveFields(self, REQUEST):
""" move Fields """
nr=0
id = REQUEST.get('idd')
where = REQUEST.get('where')
for field in self.appFields:
if (id == field['id']):
if (where == 'up' and nr>0):
temp = self.appFields[nr-1]
self.appFields[nr-1] = self.appFields[nr]
self.appFields[nr] = temp
self._p_changed = 1
return 1
if (where == 'down' and nr