PlanningBox.py 96.1 KB
Newer Older
Sebastien Robin's avatar
Sebastien Robin committed
1 2
##############################################################################
#
Sebastien Robin's avatar
Sebastien Robin committed
3
# Copyright (c) 2005 Nexedi SARL and Contributors. All Rights Reserved.
Sebastien Robin's avatar
Sebastien Robin committed
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
#                    Jonathan Loriette <john@nexedi.com>
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsability of assessing all potential
# consequences resulting from its eventual inadequacies and bugs
# End users who are looking for a ready-to-use solution with commercial
# garantees and support are strongly adviced to contract a Free Software
# Service Company
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
#
##############################################################################
import string, types, sys
from Form import BasicForm
from Products.Formulator.Field import ZMIField
from Products.Formulator.DummyField import fields
from Products.Formulator.MethodField import BoundMethod
from DateTime import DateTime
from Products.Formulator import Widget, Validator
from Products.Formulator.Errors import FormValidationError, ValidationError
Sebastien Robin's avatar
Sebastien Robin committed
36
from SelectionTool import makeTreeList,TreeListLine
37
from Selection import Selection, DomainSelection
Sebastien Robin's avatar
Sebastien Robin committed
38 39 40 41 42 43 44 45 46
import OFS
from AccessControl import ClassSecurityInfo
from zLOG import LOG
from copy import copy
from Acquisition import aq_base, aq_inner, aq_parent, aq_self
from Products.Formulator.Form import BasicForm
from Products.CMFCore.utils import getToolByName

class PlanningBoxValidator(Validator.StringBaseValidator):
Sebastien Robin's avatar
Sebastien Robin committed
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285
  def validate(self, field, key, REQUEST):
    """allows to check if one block is not outside of the planning"""
    bmoved=REQUEST.get('block_moved')
    form = field.aq_parent
    height_global_div= field.get_value('height_global_div')    
    width_line = field.get_value('width_line')
    here = getattr(form, 'aq_parent', REQUEST)
    space_line=field.get_value('space_line')
    selection_name = field.get_value('selection_name')
    sort = field.get_value('sort')
    
    height_header = field.get_value('height_header')
    height_global_div = field.get_value('height_global_div')
    height_axis_x=field.get_value('height_axis_x')
    meta_types = field.get_value('meta_types')
    list_method = field.get_value('list_method')
    report_root_list = field.get_value('report_root_list')
    portal_types = field.get_value('portal_types')
    object_start_method_id = field.get_value('x_start_bloc')
    object_stop_method_id= field.get_value('x_stop_bloc')
    y_axis_width = field.get_value('y_axis_width')
    script=getattr(here,field.get_value('x_axis_script_id'),None)
    scriptY = getattr(here,field.get_value('max_y'),None)
    x_range = field.get_value('x_range')
    info_center = field.get_value('info_center')
    info_topleft = field.get_value('info_topleft')        
    info_topright = field.get_value('info_topright')
    info_backleft = field.get_value('info_backleft')
    info_backright = field.get_value('info_backright')
    block_height= getattr(here,field.get_value('y_axis_method'),None)
    portal_url = here.portal_url()
    list_error=REQUEST.get('list_block_error')
    old_delta2 = REQUEST.get('old_delta2')
    lineb= REQUEST.get('line_begin')
    if old_delta2!='None':
      if old_delta2!='':
        if old_delta2!={}:
          old_delta2=convertStringToDict(old_delta2)
    else:
      old_delta2={}
    
    #first we rebuild the initial object structure with only line and activity block.
    
    # list_object is the variable that contains all the structure of the graphic.
    # Basically, it a list a Line Object.
    list_object=[]
    selection = here.portal_selections.getSelectionFor(selection_name, REQUEST=REQUEST)
    default_params = {}
    if selection is None:
      selection = Selection(params=default_params, default_sort_on = sort)
    else:
      selection.edit(default_sort_on = sort)
      selection.edit(sort_on = sort)       
    here.portal_selections.setSelectionFor(selection_name, selection, REQUEST=REQUEST)
    current_top = height_header
    #we check what is the current zoom in order to redefine height & width
    current_zoom = selection.getZoom()
    current_zoom= float(current_zoom)
    if current_zoom<=1:
      height_global_div = round(height_global_div * current_zoom)
      width_line = round(width_line * current_zoom)
      space_line = round(space_line * current_zoom)  
    #we build line
    (list_object,nbr_line,report_sections,blocks_object)=createLineObject(meta_types=meta_types,
                                                            selection=selection,
                                                            selection_name=selection_name,field=field,
                                                            REQUEST=REQUEST,list_method=list_method,
                                                            here=here,report_root_list=report_root_list,
                                                            y_axis_width=y_axis_width,width_line=width_line,
                                                            space_line=space_line,
                                                            height_global_div=height_global_div,
                                                            height_header=height_header,
                                                            height_axis_x=height_axis_x,form=form,
                                                            current_top=current_top,portal_types=portal_types)
    # blocks_object is a dictionnary that contains all informations used for building blocks of each line
 
    #we build x_occurence (used for the range in x-Axis 
    x_occurence=[]
    #report_sections contains treeListLine instance objects
    for treelistobject in report_sections: 
      method_start = getattr(treelistobject.getObject(),object_start_method_id,None)
      method_stop= getattr(treelistobject.getObject(),object_stop_method_id,None)
      if method_start!=None:
        block_begin = method_start()
      else:
        block_begin = None
      
      if method_stop!=None:
        block_stop= method_stop()
      else:
        block_stop=None
      if block_begin != None: 
       x_occurence.append([block_begin,block_stop])
      #if method start is None it means that we construct the graphic with informations contained
      #in blocks_object. 
      if method_start == None and report_sections!={}:
        for Ablock in blocks_object:
          #object_content is the current object used for building a block.
          #For instance if the context is a project, then object_content is an orderLine.
          for object_content in blocks_object[Ablock]:
            method_start = getattr(object_content,object_start_method_id,None)
            method_stop= getattr(object_content,object_stop_method_id,None)
              
            if method_start!=None:
              block_begin = method_start()
            else:
              block_begin = None
            
            if method_stop!=None:
              block_stop= method_stop()
            else:
              block_stop=None
              
            if block_begin!=None:# and block_stop!=None:
              x_occurence.append([block_begin,block_stop])
          
      params=selection.getParams()
      start=params.get('list_start')
      
      x_axe=script(x_occurence,x_range,float(current_zoom),start)
      y_max= 1
      current_max = 1
      #this part is used for determining the maximum through datas fetched via scriptY
      #y_max is used when blocks have different height.
      if scriptY != None:
        for s in report_sections:
          current_max=scriptY(s.getObject())
          if current_max > y_max:
            y_max = current_max
      else:
        y_max = 1
      indic_line=0
      while indic_line != len(report_sections):
        # o is a Line object, for each line, we add its blocks via insertActivityBlock
        for o in list_object:
          if o.title == report_sections[indic_line].getObject().getTitle():
            if list_object != [] and report_sections[indic_line].getDepth()==0:
              o.insertActivityBlock(line_content=report_sections[indic_line].getObject(),
                                    object_start_method_id=object_start_method_id,
                                    object_stop_method_id=object_stop_method_id,
                                    x_axe=x_axe,field=field,info_center=info_center,
                                    info_topright=info_topright,info_topleft=info_topleft,
                                    info_backleft=info_backleft,info_backright=info_backright,
                                    list_error=list_error,old_delta=['None','None'],REQUEST=REQUEST,
                                    blocks_object=blocks_object,width_line=width_line,
                                    script_height_block=block_height,y_max=y_max)                                                      
              break
        indic_line+=1 
    
    #  the structure is now rebuilt
    block_moved = [] 
    bloc_and_line=[] # store the line and the coordinates of block moved
    if bmoved != '':
      block_moved=convertStringToList(bmoved)
    else:
      return ''
    
    # When a block is moved, we fetch its object Line and its corresponding object Blocks*
    # via returnBlock 
    for current_block in block_moved:
      bloc_and_line=returnBlock(current_block,list_object,bloc_and_line)
    
    #At this point, we know which blocks have moved and the line they belong  
    #IMPORTANT INFORMATION ABOUT RECORD:
    #There is a problem with absolute and relative coordinates, that is why we do not
    #directly use coordinates from bmoved, but only 'delta' which allows to find correct
    #coordinates 
    my_field = None
    prev_delta='' #we store the current delta in a formated string
    list_block_error = []
    errors = []
    error_result = {}
    prev_deltaX=0
    prev_deltaY=0
    deltaX = 0 
    deltaY = 0 
    correct = 1 # correct = 1 if the block is correct otherwise correct = 0
    new_object_planning = {} #structure returned
    for mblock in bloc_and_line:
      if old_delta2!=None:
        # For each block that has moved, we add its former coordinates and its delta
        if old_delta2.has_key(mblock[1].name):
          prev_deltaX=float(old_delta2[mblock[1].name][0])
          prev_deltaY=float(old_delta2[mblock[1].name][1])
      deltaX =float(mblock[0][3]) - float(mblock[0][1])+prev_deltaX 
      deltaY = float(mblock[0][4]) - float(mblock[0][2])+prev_deltaY
      widthblock= float(mblock[0][5])
      heightblock=float(mblock[0][6])
      if mblock[1].url!='':
        url = mblock[1].url
      else:
        url= mblock[2].url
      # several test to know if a block is correct. If it is not, wee add it to list_block_error.
      if mblock[1].begin <0:
        deltaX = (mblock[1].begin)*mblock[2].width + float(mblock[0][3]) +prev_deltaX
      # mblock[1] is a  block ; mblock[2] is a line
      if (mblock[1].marge_top)*mblock[2].height+mblock[2].top+deltaY >mblock[2].top+mblock[2].height:  
        correct = 0
      if (mblock[1].marge_top)*mblock[2].height+heightblock+mblock[2].top+deltaY< mblock[2].top:
        correct = 0
      if (mblock[1].begin)*mblock[2].width+widthblock+mblock[2].begin+deltaX <mblock[2].begin:
        correct = 0
      if (mblock[1].begin)*mblock[2].width + deltaX+ mblock[2].begin> mblock[2].begin + mblock[2].width:
        correct = 0
      if correct == 0:
        list_block_error.append(mblock)
        err = ValidationError(StandardError,mblock[1])
        errors.append(err)
        if prev_delta!='':
          prev_delta+='*'
        prev_delta+=str(mblock[1].name)+','+str(deltaX)+','+str(deltaY)
        # we store once again old_delta because we will need it when a block is moved again.     
      else:
        new_object_planning = convertDataToDate(mblock,x_axe,width_line, deltaX, 
                                                deltaY, url, new_object_planning,lineb)  
    REQUEST.set('list_block_error',list_block_error)
    REQUEST.set('old_delta1',prev_delta)
    if len(errors)>0:
      raise FormValidationError(errors,{})
    return new_object_planning

def convertDataToDate(mblock,x_axe,width_line, deltaX, deltaY, object_url,
                      new_object_planning, lineb):                 
  """this is in this method that we calculate new startdate & stopdate in order 
     to save them"""  
  delta_axe = (DateTime(x_axe[0][-1])-DateTime(x_axe[0][0]))
  #lineb is used to know where really starts the line due to problems with others html tags.
  begin = (mblock[2].begin - float(mblock[0][3])+(float(lineb)-mblock[2].begin))*(-1)
  length = float(mblock[0][5])
  axe_begin = DateTime(x_axe[0][0])
  coeff = float(delta_axe) / float(mblock[2].width)
  delta_start = begin * coeff
  delta_length = length * coeff
  new_start = axe_begin + delta_start
  new_stop=new_start + delta_length
  new_object_planning[object_url]={'start_date':new_start,'stop_date':new_stop}
  return new_object_planning    


Sebastien Robin's avatar
Sebastien Robin committed
286 287
PlanningBoxValidatorInstance=PlanningBoxValidator()        

Sebastien Robin's avatar
Sebastien Robin committed
288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321

def returnBlock(block_searched,planning_struct,block_and_line):
  """return a specific structre containing the block object and its line 
   thanks to its name"""
  for line in planning_struct:
    for block in line.content:
      if block.name == block_searched[0]:
        block_and_line.append([block_searched,block,line])   
        break
      else:
        if line.son!=[]:
          block_and_line = returnBlock(block_searched,line.son,block_and_line)
  return block_and_line

def convertStringToList(import_string):
  """ convert a string from this type 'name,x,y,w,h-name,x,y,w,h...' to a list"""
  list_moved= []
  r_List = import_string.split('*')
  for i in r_List:
    current_block = i.split(',')
    list_moved.append(current_block)
  return list_moved

def convertStringToDict(import_string):
  """ convert a string from this type name,x1,x2,x,y,w,h*name,x1,x2,x,y,w,h
      to list of dictionnaries where the key is the name""" 
  dic={}
  r_List=import_string.split('*')
  for i in r_List:
    current_block = i.split(',')
    dic[current_block[0]]=[current_block[1],current_block[2]]
  return dic    

  
Sebastien Robin's avatar
Sebastien Robin committed
322 323
def createLineObject(meta_types,selection,selection_name,field,REQUEST,list_method,
                     here,report_root_list,y_axis_width,width_line,space_line,
324
                     height_global_div,height_header,height_axis_x,form,current_top,portal_types):
Sebastien Robin's avatar
Sebastien Robin committed
325
  """creates Line Object and stores it in list_object"""
Sebastien Robin's avatar
Sebastien Robin committed
326
  report_sections = []
327 328 329
  filtered_portal_types = map(lambda x: x[0], portal_types)
  if len(filtered_portal_types) == 0:
    filtered_portal_types = None
Sebastien Robin's avatar
Sebastien Robin committed
330 331 332 333 334 335 336 337 338 339
  section_index = 0
  if len(report_sections) > section_index:
    current_section = report_sections[section_index]
  elif len(report_sections):
    current_section = report_sections[0]
  else:
    current_section = None
  filtered_meta_types = map(lambda x: x[0], meta_types)
  params = selection.getParams()
  sort = field.get_value('sort')
340
  selection.edit(default_sort_on = sort)
Sebastien Robin's avatar
Sebastien Robin committed
341 342 343 344 345 346 347
  kw=params
  report_depth = REQUEST.get('report_depth', None)
  is_report_opened = REQUEST.get('is_report_opened', selection.isReportOpened())
  portal_categories = getattr(form, 'portal_categories', None)
  if 'select_expression' in kw:
    del kw['select_expression']
  if hasattr(list_method, 'method_name'):
348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374
    if list_method.method_name == 'objectValues':
      list_method = here.objectValues
      kw = copy(params)
      kw['spec'] = filtered_meta_types
    else:
     # The Catalog Builds a Complex Query
      kw = {}
      if REQUEST.form.has_key('portal_type'):
        kw['portal_type'] = REQUEST.form['portal_type']
      elif REQUEST.has_key('portal_type'):
        kw['portal_type'] = REQUEST['portal_type']
      elif filtered_portal_types is not None:
        kw['portal_type'] = filtered_portal_types
      elif filtered_meta_types is not None:
        kw['meta_type'] = filtered_meta_types
      elif kw.has_key('portal_type'):
        if kw['portal_type'] == '':
          del kw['portal_type']
      # Remove useless matter
      for cname in params.keys():
        if params[cname] != '' and params[cname]!=None:
          kw[cname] = params[cname]
      # Try to get the method through acquisition
      try:
        list_method = getattr(here, list_method.method_name)
      except:
        pass
Sebastien Robin's avatar
Sebastien Robin committed
375 376 377 378 379 380 381 382 383 384 385 386 387 388
  elif list_method in (None, ''): # Use current selection
    list_method = None
  select_expression = ''
  default_selection_report_path = report_root_list[0][0].split('/')[0]
  if default_selection_report_path in portal_categories.objectIds() or \
    (portal_domains is not None and default_selection_report_path in portal_domains.objectIds()):
    pass
  else:
    default_selection_report_path = report_root_list[0][0]          
  selection_report_path = selection.getReportPath(default = (default_selection_report_path,))
  if report_depth is not None:
    selection_report_current = ()
  else:
    selection_report_current = selection.getReportList()
Sebastien Robin's avatar
Sebastien Robin committed
389 390 391 392 393 394
  report_tree_list = makeTreeList(here=here, form=form, root_dict=None,report_path=selection_report_path,
                                  base_category=None,depth=0, 
                                  unfolded_list=selection_report_current, selection_name=selection_name, 
                                  report_depth=report_depth,
                                  is_report_opened=is_report_opened, sort_on=selection.sort_on,
                                  form_id=form.id)
395
  
Sebastien Robin's avatar
Sebastien Robin committed
396 397 398 399 400 401 402 403
  if report_depth is not None:
    report_list = map(lambda s:s[0].getRelativeUrl(), report_tree_list)
    selection.edit(report_list=report_list)
  report_sections = []
  list_object = []
  nbr_line=0
  object_list=[]    
  indic_line=0 
Sebastien Robin's avatar
Sebastien Robin committed
404 405 406 407 408
  index_line = 0
  blocks_object= {}  
  for object_tree_line in report_tree_list:      
    selection.edit(report = object_tree_line.getSelectDomainDict())            
    if object_tree_line.getIsPureSummary():
Sebastien Robin's avatar
Sebastien Robin committed
409 410 411 412 413 414 415 416
      original_select_expression = kw.get('select_expression')
      kw['select_expression'] = select_expression
      selection.edit( params = kw )
      if original_select_expression is None:
        del kw['select_expression']
      else:
        kw['select_expression'] = original_select_expression
    
Sebastien Robin's avatar
Sebastien Robin committed
417
    if object_tree_line.getIsPureSummary() and selection_report_path[0]=='parent':
Sebastien Robin's avatar
Sebastien Robin committed
418 419
      stat_result = {}
      index = 1
Sebastien Robin's avatar
Sebastien Robin committed
420
      report_sections += [object_tree_line]
Sebastien Robin's avatar
Sebastien Robin committed
421 422 423 424 425
      nbr_line+=1       
    else:
      # Prepare query
      selection.edit( params = kw )
      if list_method not in (None, ''):
Sebastien Robin's avatar
Sebastien Robin committed
426
        selection.edit(exception_uid_list=object_tree_line.getExceptionUidList())
427
        object_list = selection(method = list_method, context=here, REQUEST=REQUEST)
Sebastien Robin's avatar
Sebastien Robin committed
428 429 430 431
      else:
        object_list = here.portal_selections.getSelectionValueList(selection_name,
                                                          context=here, REQUEST=REQUEST)
      
Sebastien Robin's avatar
Sebastien Robin committed
432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457
      exception_uid_list = object_tree_line.getExceptionUidList()
      if exception_uid_list is not None:
      # Filter folders if this is a parent tree
        new_object_list = []
        for o in object_list:
        #LOG('exception_uid_list', 0, '%s %s' % (o.getUid(), exception_uid_list))
          if o.getUid() not in exception_uid_list:
            new_object_list.append(o)
                      
        object_list = new_object_list
      
      current_list=[]
      add = 1
      #a test with 'add' variable because maketreelist return two times the 
      #same object when it is open, don't know why...
      for object in report_sections:
        if getattr(object_tree_line.getObject(),'uid') == getattr(object.getObject(),'uid'):
          add = 0
          break  
      if add == 1:       
        report_sections += [object_tree_line] 
        nbr_line+=1
        for p in object_list:
          current_list.append(p.getObject())
        blocks_object[object_tree_line.getObject()]=current_list
  selection.edit(report=None)
Sebastien Robin's avatar
Sebastien Robin committed
458
  index = 0
Sebastien Robin's avatar
Sebastien Robin committed
459 460 461
  #we start to build our line object structure right here.
  index_report=0
  for line_report in report_sections:
Sebastien Robin's avatar
Sebastien Robin committed
462
    stat_result = {}
Sebastien Robin's avatar
Sebastien Robin committed
463 464 465
    stat_context = line_report.getObject().asContext(**stat_result)
    stat_context.domain_url = line_report.getObject().getRelativeUrl()
    stat_context.absolute_url = lambda x: line_report.getObject().absolute_url()     
Sebastien Robin's avatar
Sebastien Robin committed
466
    url=getattr(stat_context,'domain_url','')
Sebastien Robin's avatar
Sebastien Robin committed
467 468 469

    if line_report.getDepth() == 0:
      paternity = 1    
Sebastien Robin's avatar
Sebastien Robin committed
470
      height=(height_global_div-height_header-height_axis_x-((nbr_line-1)*space_line))/float(nbr_line)
Sebastien Robin's avatar
Sebastien Robin committed
471
      line = Line(title=line_report.getObject().getTitle(),
Sebastien Robin's avatar
Sebastien Robin committed
472 473 474 475 476 477 478 479
                   name='fra' + str(indic_line),
                   begin=y_axis_width,
                   width=width_line,
                   height=height,
                   top=current_top,color='#ffffff',
                   paternity=paternity,url=url)    
      list_object.append(line)
      
480 481 482 483
      if paternity == 0:
        height=(height_global_div-height_header-height_axis_x-
               ((nbr_line-1)*space_line))/(float(nbr_line)) + (space_line)  
        current_top=current_top+height
Sebastien Robin's avatar
Sebastien Robin committed
484 485 486 487

      else:
        if (index+1)<=(len(report_sections)-1): 
          if report_sections[index+1].getDepth()==0:
488 489 490
            height=((height_global_div-height_header-height_axis_x-
                   (((nbr_line-1))*space_line))/float(nbr_line))+ (space_line)
            current_top=current_top+height    
Sebastien Robin's avatar
Sebastien Robin committed
491
          else:
492 493 494
            height=((height_global_div-height_header-height_axis_x-
                   (((nbr_line-1))*space_line))/float(nbr_line))
            current_top=current_top+height 
Sebastien Robin's avatar
Sebastien Robin committed
495 496
    else:
      current_index = 0      
Sebastien Robin's avatar
Sebastien Robin committed
497
      while line_report.getDepth() == report_sections[index-current_index].getDepth():
Sebastien Robin's avatar
Sebastien Robin committed
498 499
        current_index += 1
      if report_sections[index-current_index].getDepth() == 0:
500 501 502
        current_top=list_object[len(list_object)-1].createLineChild(report_sections,field,
                                current_top,y_axis_width,width_line,space_line,height_global_div,
                                height_header,height_axis_x,nbr_line,index,url)
Sebastien Robin's avatar
Sebastien Robin committed
503 504 505
      else : # in this case wee add a soon to a soon
        depth=0 
        current_soon=list_object[len(list_object)-1]
Sebastien Robin's avatar
Sebastien Robin committed
506
        while depth != (line_report.getDepth()-1):
Sebastien Robin's avatar
Sebastien Robin committed
507 508
          current_soon=list_object[len(list_object)-1].soon[len(list_object[len(list_object)-1].soon)-1]
          depth+=1
509 510 511
        current_top=current_soon.createLineChild(report_sections,field,current_top,y_axis_width,
                                                 width_line,space_line,height_global_div,height_header
                                                ,height_axis_x,nbr_line,index,url)    
Sebastien Robin's avatar
Sebastien Robin committed
512 513
    index += 1
    indic_line+=1
Sebastien Robin's avatar
Sebastien Robin committed
514
  return (list_object,nbr_line,report_sections,blocks_object)
Sebastien Robin's avatar
Sebastien Robin committed
515 516

def createGraphicCall(current_line,graphic_call):
Sebastien Robin's avatar
Sebastien Robin committed
517 518 519 520 521 522 523 524 525 526
  """ create html code of children used by graphic library to know which block can be moved.
      Refers to javascript library for more information"""
  for line in current_line.son:
    for block in line.content:
      if block.types=='activity' or block.types=='activity_error':
        graphic_call+='\"'+block.name+'\",'
      elif block.types=='info':
        graphic_call+='\"'+block.name+'\"+NO_DRAG,'   
    if line.son!=[]: # case of a son which has sons...
      graphic_call+=createGraphicCall(line,graphic_call)        
Sebastien Robin's avatar
Sebastien Robin committed
527 528 529 530
  return graphic_call
  
class PlanningBoxWidget(Widget.Widget):
    property_names = Widget.Widget.property_names +\
Sebastien Robin's avatar
Sebastien Robin committed
531 532
                     ['height_header', 'height_global_div','height_axis_x', 'width_line','space_line',
                     'list_method','report_root_list','selection_name','portal_types',
533
                     'meta_types','sort','title_line','y_unity','y_axis_width','y_range','x_range',
Sebastien Robin's avatar
Sebastien Robin committed
534 535 536
                     'x_axis_script_id','x_start_bloc','x_stop_bloc','y_axis_method','max_y',
                     'constraint_method','info_center','info_topleft','info_topright','info_backleft',
                     'info_backright','security_index']
Sebastien Robin's avatar
Sebastien Robin committed
537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643
    
    default = fields.TextAreaField('default',
                                title='Default',
                                description=(
        "Default value of the text in the widget."),
                                default="",
                                width=20, height=3,
                                required=0)	     
     
                             
    height_header = fields.IntegerField('height_header',
                                title='height of the header (px):',
                                description=(
        "value of the height of the header, required"),
                                default=50,
                                required=1)    
                                                                             
    height_global_div = fields.IntegerField('height_global_div',
                                title='height of the graphic (px):',
                                description=(
        "value of the height of the graphic, required"),
                                default=700,
                                required=1) 
    height_axis_x = fields.IntegerField('height_axis_x',
                                title='height of X-axis (px):',
                                description=(
        "value of the height of X-axis"),
                                default=50,
                                required=1) 	
                                
    width_line = fields.IntegerField('width_line',
                                title='width of the graphic (px):',
                                description=(
        "value of width_line, required"),
                                default=1000,
                                required=1) 
    space_line = fields.IntegerField('space_line',
                                title='space between each line of the graphic (px):',
                                description=(
        "space between each line of the graphic,not required"),
                                default=10,
                                required=0)   
                                
    report_root_list = fields.ListTextAreaField('report_root_list',
                                 title="Report Root",
                                 description=(
        "A list of domains which define the possible root."),
                                 default=[],
                                 required=0)
  
    selection_name = fields.StringField('selection_name',
                                 title='Selection Name',
                                 description=('The name of the selection to store'
                                              'params of selection'),
                                 default='',
                                 required=0)
                                 
    portal_types = fields.ListTextAreaField('portal_types',
                                 title="Portal Types",
                                 description=(
        "Portal Types of objects to list. Required."),
                                 default=[],
                                 required=0)
                                 
    meta_types = fields.ListTextAreaField('meta_types',
                                 title="Meta Types",
                                 description=(
        "Meta Types of objects to list. Required."),
                                 default=[],
                                 required=0)
                                                              
    sort = fields.ListTextAreaField('sort',
                                 title='Default Sort',
                                 description=('The default sort keys and order'),
                                 default=[],
                                 required=0)
  
    list_method = fields.MethodField('list_method',
                                 title='List Method',
                                 description=('The method to use to list'
                                             'objects'),
                                 default='',
                                 required=0)                             

    title_line = fields.StringField('title_line',
                                title='specific method which fetches the title of each line: ',
                                description=('specific method for inserting title in line'),
                                default='',
                                required=0)                            

    y_unity = fields.StringField('y_unity',
                                 title='Unity in Y-axis:',
                                 description=('The unity in Y-axis,not required'),
                                 default='',
                                 required=0)

    y_axis_width = fields.IntegerField('y_axis_width',
                                title='width of Y-axis (px):',
                                description=(
        "width of Y-axis, required"),
                                default=200,
                                required=1) 
    
    y_range = fields.IntegerField('y_range',
                                title='number of range of Y-axis :',
                                description=(
        "Number of Range of Y-axis, not required"),
Sebastien Robin's avatar
Sebastien Robin committed
644
                                default=0,
Sebastien Robin's avatar
Sebastien Robin committed
645 646 647 648 649 650 651 652 653 654 655 656 657 658 659
                                required=0) 
 
    x_range = fields.StringField('x_range',
                                 title='range of X-Axis:',
                                 description=('Nature of the subdivisions of X-Axes, not Required'),
                                 default='Day',
                                 required=0)	
 
    x_axis_script_id = fields.StringField('x_axis_script_id',
                                 title='script for building the X-Axis:',
                                 description=('script for building the X-Axis'),
                                 default='',
                                 required=0)	

    x_start_bloc = fields.StringField('x_start_bloc',
Sebastien Robin's avatar
Sebastien Robin committed
660 661
                                 title='specific method which fetches the data for the beginning of a\
                                        block:',
Sebastien Robin's avatar
Sebastien Robin committed
662 663 664 665 666 667 668 669 670 671 672 673 674 675
                                 description=('Method for building X-Axis such as getstartDate'
                                              'objects'),
                                 default='getStartDate',
                                 required=0)	
    
    x_stop_bloc = fields.StringField('x_stop_bloc',
                                 title='specific method which fetches the data for the end of each block',
                                 description=('Method for building X-Axis such getStopDate'
                                              'objects'),
                                 default='',
                                 required=0)	

 
    y_axis_method = fields.StringField('y_axis_method',
Sebastien Robin's avatar
Sebastien Robin committed
676 677 678 679 680 681 682 683
                                 title='specific method of data type for creating height of blocks',
                                 description=('Method for building height of blocks'
                                              'objects'),
                                 default='',
                                 required=0) 
                                 

    max_y  = fields.StringField('max_y',
Sebastien Robin's avatar
Sebastien Robin committed
684 685 686 687
                                 title='specific method of data type for creating Y-Axis',
                                 description=('Method for building Y-Axis'
                                              'objects'),
                                 default='',
Sebastien Robin's avatar
Sebastien Robin committed
688 689 690
                                 required=0)

  
Sebastien Robin's avatar
Sebastien Robin committed
691
  
Sebastien Robin's avatar
Sebastien Robin committed
692 693 694 695 696 697
    constraint_method = fields.StringField('constraint_method',
                                          title='name of constraint method between blocks',
                                          description=('Constraint method between blocks'
                                                      'objects'),
                                          default='SET_DHTML',
                                          required=1)
698 699 700 701 702 703 704 705 706 707 708
  
    info_center = fields.StringField('info_center',
                                 title='specific method of data called for inserting info in block center',
                                 description=('Method for displaying info in the center of a block'
                                              'objects'),
                                 default='',
                                 required=0) 
   
    info_topright = fields.StringField('info_topright',
                                 title='specific method of data called for inserting info in block topright',
                                 description=('Method for displaying info in the topright of a block'
Sebastien Robin's avatar
Sebastien Robin committed
709 710 711
                                              'objects'),
                                 default='',
                                 required=0)
712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732
                                 
    info_topleft = fields.StringField('info_topleft',
                                 title='specific method of data called for inserting info in block topleft',
                                 description=('Method for displaying info in the topleft corner of a block'
                                              'objects'),
                                 default='',
                                 required=0)                             
                                 
    info_backleft = fields.StringField('info_backleft',
                                 title='specific method of data called for inserting info in block backleft',
                                 description=('Method for displaying info in the backleft of a block'
                                              'objects'),
                                 default='',
                                 required=0)
    info_backright = fields.StringField('info_backright',
                                 title='specific method of data called for inserting info in block backright',
                                 description=('Method for displaying info in the backright of a block'
                                              'objects'),
                                 default='',
                                 required=0)
   
Sebastien Robin's avatar
Sebastien Robin committed
733 734
    security_index = fields.IntegerField('security_index',
                                title='variable depending of the type of web browser :',
Sebastien Robin's avatar
Sebastien Robin committed
735 736
                                description=("This variable is used because the rounds of each\
                                              web browser seem to work differently"),
Sebastien Robin's avatar
Sebastien Robin committed
737 738 739 740
                                default=2,
                                required=0) 	 
                                                                                       
    def render_css(self, field, key, value, REQUEST):
Sebastien Robin's avatar
Sebastien Robin committed
741 742 743
        """In this method we build our structure object, then we return all the style sheet of each div"""
        
        # DATA DEFINITION 
Sebastien Robin's avatar
Sebastien Robin committed
744 745 746 747 748 749 750 751 752 753 754 755 756 757
        height_header = field.get_value('height_header')
        height_global_div = field.get_value('height_global_div')
        height_axis_x=field.get_value('height_axis_x')
        width_line = field.get_value('width_line')
        space_line = field.get_value('space_line')
        selection_name = field.get_value('selection_name')
        security_index = field.get_value('security_index')
        y_unity = field.get_value('y_unity')
        y_axis_width = field.get_value('y_axis_width')
        y_range = field.get_value('y_range')
        portal_types= field.get_value('portal_types')
        meta_types = field.get_value('meta_types')
        x_range=field.get_value('x_range')
        here = REQUEST['here']
758
        title=field.get_value('title')
Sebastien Robin's avatar
Sebastien Robin committed
759 760
        list_method = field.get_value('list_method')
        report_root_list = field.get_value('report_root_list')
Sebastien Robin's avatar
Sebastien Robin committed
761
        scriptY = getattr(here,field.get_value('max_y'),None)
Sebastien Robin's avatar
Sebastien Robin committed
762
        script=getattr(here,field.get_value('x_axis_script_id'),None)
Sebastien Robin's avatar
Sebastien Robin committed
763 764
        block_height= getattr(here,field.get_value('y_axis_method'),None)
        constraint_method = field.get_value('constraint_method')
765
        #info inside a block
Sebastien Robin's avatar
Sebastien Robin committed
766
        
767 768 769 770 771
        info_center = field.get_value('info_center')
        info_topleft = field.get_value('info_topleft')        
        info_topright = field.get_value('info_topright')
        info_backleft = field.get_value('info_backleft')
        info_backright = field.get_value('info_backright')
Sebastien Robin's avatar
Sebastien Robin committed
772

Sebastien Robin's avatar
Sebastien Robin committed
773 774 775
        object_start_method_id = field.get_value('x_start_bloc')
        object_stop_method_id= field.get_value('x_stop_bloc')
        form = field.aq_parent
776 777 778
        sort = field.get_value('sort')   
        x_occurence=[] # contains datas of start and stop of each block like
                       # this [ [ [x1,x2],[x1,x2] ],[ [x1,x2],[x1,x2] ],.....] 
Sebastien Robin's avatar
Sebastien Robin committed
779 780
                       #it is not directly coordinates but datas.                    
        x_axe=[] # will contain what wee need to display in X-axis.
Sebastien Robin's avatar
Sebastien Robin committed
781 782
        yrange=[] # we store the value in Y-axis of each block 
        nbr=1
Sebastien Robin's avatar
Sebastien Robin committed
783
        blocks_object={}      
Sebastien Robin's avatar
Sebastien Robin committed
784
        current_top=height_header
Sebastien Robin's avatar
Sebastien Robin committed
785
        line_list=[] #in this list we store all the objects of type Line
Sebastien Robin's avatar
Sebastien Robin committed
786 787
        giant_string='' #will contain all the html code.
        report_sections=[]
Sebastien Robin's avatar
Sebastien Robin committed
788 789 790
        list_error=REQUEST.get('list_block_error')
        old_delta=[REQUEST.get('old_delta1'),REQUEST.get('old_delta2')]
        # END DATA DEFINITION                         
791
        
Sebastien Robin's avatar
Sebastien Robin committed
792
        # we fetch fold/unfold datas 
793
        #here.portal_selections.setSelectionFor(selection_name, None)#uncoment to put selection to null
Sebastien Robin's avatar
Sebastien Robin committed
794 795 796 797
        selection = here.portal_selections.getSelectionFor(selection_name, REQUEST=REQUEST)
        default_params = {}
        if selection is None:
          selection = Selection(params=default_params, default_sort_on = sort)
798 799 800
        else:
          selection.edit(default_sort_on = sort)
          selection.edit(sort_on = sort)       
Sebastien Robin's avatar
Sebastien Robin committed
801
        here.portal_selections.setSelectionFor(selection_name, selection, REQUEST=REQUEST)
Sebastien Robin's avatar
Sebastien Robin committed
802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822
        # we check what is the current zoom in order to redefine height & width
        current_zoom = selection.getZoom()
        current_zoom= float(current_zoom)
        if current_zoom<=1:
          height_global_div = round(height_global_div * current_zoom)
          width_line = round(width_line * current_zoom)
          space_line = round(space_line * current_zoom)  
        #we build lines 
        (line_list,nbr_line,report_sections,blocks_object)=createLineObject(meta_types=meta_types,
                                                                selection=selection,
                                                                selection_name=selection_name,field=field,
                                                                REQUEST=REQUEST,list_method=list_method,
                                                                here=here,report_root_list=report_root_list,
                                                                y_axis_width=y_axis_width,
                                                                width_line=width_line,space_line=space_line,
                                                                height_global_div=height_global_div,
                                                                height_header=height_header,
                                                                height_axis_x=height_axis_x,form=form,
                                                                current_top=current_top,
                                                                portal_types=portal_types)
        #we build x_occurence (used for the range in x-Axis 
Sebastien Robin's avatar
Sebastien Robin committed
823
        
Sebastien Robin's avatar
Sebastien Robin committed
824 825 826 827 828 829 830 831
        for tree_list_object in report_sections:
          method_start = getattr(tree_list_object.getObject(),object_start_method_id,None)
          method_stop= getattr(tree_list_object.getObject(),object_stop_method_id,None)
          if method_start!=None:
            block_begin = method_start()
          else:
            block_begin = None
          
Sebastien Robin's avatar
Sebastien Robin committed
832 833 834 835
          if method_stop!=None:
            block_stop= method_stop()
          else:
            block_stop=None
Sebastien Robin's avatar
Sebastien Robin committed
836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879
          
          if block_begin!=None:# and block_stop!=None:  
            x_occurence.append([block_begin,block_stop])
          
          if method_start == None and report_sections!={}:
            for Ablock in blocks_object:
              for object_content in blocks_object[Ablock]:
                method_start = getattr(object_content,object_start_method_id,None)
                method_stop= getattr(object_content,object_stop_method_id,None)
              
                if method_start!=None:
                  block_begin = method_start()
                else:
                  block_begin = None
            
                if method_stop!=None:
                  block_stop= method_stop()
                else:
                  block_stop=None
              
                if block_begin!=None:# and block_stop!=None:
                  x_occurence.append([block_begin,block_stop])
          
        params=selection.getParams()
        start=params.get('list_start')
        
        x_axe=script(x_occurence,x_range,float(current_zoom),start)
        #x_axe[0] is a list of chronological dates that wich represents the 
        #the range of the graphic.for example: 
        #x_axis=[['2005/11/04','2005/12/04' etc.],['april','may','june' etc.]
        #,start_delimiter,delta]
        # we add mobile block to the line object 
        
        y_max= 1
        current_max = 1
        if scriptY != None:
          for s in report_sections:
            current_max=scriptY(s.getObject())
            if current_max > y_max:
              y_max = current_max
        else:
          y_max = 1

        indic_line=0
880
        while indic_line != len(report_sections):
Sebastien Robin's avatar
Sebastien Robin committed
881 882 883 884 885 886 887 888 889 890 891 892
          for object_line in line_list:
            if object_line.title == report_sections[indic_line].getObject().getTitle():
              if line_list != [] and report_sections[indic_line].getDepth()==0:
                object_line.insertActivityBlock(line_content=report_sections[indic_line].getObject(),
                                      object_start_method_id=object_start_method_id,
                                      object_stop_method_id=object_stop_method_id,
                                      x_axe=x_axe,field=field,info_center=info_center,
                                      info_topright=info_topright,info_topleft=info_topleft,
                                      info_backleft=info_backleft,info_backright=info_backright,
                                      list_error=list_error,old_delta=old_delta,REQUEST=REQUEST,
                                      blocks_object=blocks_object,width_line=width_line,
                                      script_height_block=block_height,y_max=y_max)                                                      
893 894
                break
          indic_line+=1
Sebastien Robin's avatar
Sebastien Robin committed
895 896
        # At this point line_list contains our tree of datas. Then we
        # add others labels, indicators etc. for the graphic.
Sebastien Robin's avatar
Sebastien Robin committed
897

Sebastien Robin's avatar
Sebastien Robin committed
898 899 900 901 902
        #One constructs the vertical dotted line
        if x_axe != []:        
          marge_left=y_axis_width+width_line/float(len(x_axe[1]))
          for i in line_list:
            i.appendVerticalDottedLine(x_axe,width_line,marge_left)
Sebastien Robin's avatar
Sebastien Robin committed
903

Sebastien Robin's avatar
Sebastien Robin committed
904
        #one constructs the maximum horizontal dotted line 10px under the top of the line
Sebastien Robin's avatar
Sebastien Robin committed
905
        maximum_y=y_max
Sebastien Robin's avatar
Sebastien Robin committed
906 907 908
        marge_top=10
        if y_range!=0:
          for i in line_list:  
909
            i.appendHorizontalDottedLine(marge_top,maximum_y,height_global_div,height_header,
Sebastien Robin's avatar
Sebastien Robin committed
910 911
                                         height_axis_x,nbr_line,y_range,y_max)
        #end construct of horizontal dotted line 
Sebastien Robin's avatar
Sebastien Robin committed
912

Sebastien Robin's avatar
Sebastien Robin committed
913
        # we construct y-axis
Sebastien Robin's avatar
Sebastien Robin committed
914
        way=[]    
Sebastien Robin's avatar
Sebastien Robin committed
915
        y=[] #we store here the objects for creating y-axis 
Sebastien Robin's avatar
Sebastien Robin committed
916 917 918
        level=0
        current_top=height_header
        idx=0
Sebastien Robin's avatar
Sebastien Robin committed
919 920 921 922 923 924 925 926 927 928
        
        for i in line_list:
          current_top=i.buildYtype(way=way,y=y,level=level,y_axis_width=y_axis_width,
                                   height_global_div=height_global_div,height_header=height_header,
                                   height_axis_x=height_axis_x,nbr_line=nbr_line,current_top=current_top,
                                   space_line=space_line,y_max=y_max,y_range=y_range,
                                   y_unity=y_unity,selection_name=selection_name,form=form)  
          height=((height_global_div-height_header-height_axis_x-((nbr_line-1)*space_line))/\
                 float(nbr_line))+space_line
          current_top=y[-1].top+height
Sebastien Robin's avatar
Sebastien Robin committed
929
          idx+=1
Sebastien Robin's avatar
Sebastien Robin committed
930 931
        line_list=y+line_list #we need to add the y-axis block at the beginning of our structure
                                  #otherwise the display is not correct;don't know why...
Sebastien Robin's avatar
Sebastien Robin committed
932

Sebastien Robin's avatar
Sebastien Robin committed
933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949
        #build X axis 
        line_list.append(Line('','axis_x',y_axis_width,width_line,height_axis_x,\
                                current_top-space_line)) 
        line_list[-1].createXAxis(x_axe,width_line,y_axis_width)
        if x_axe!=[]:
          x_subdivision=width_line/float(len(x_axe[1]))
        else:
          x_subdivision = 0
        REQUEST.set('line_list',line_list)  
        REQUEST.set('report_root_list',report_root_list)
        REQUEST.set('selection_name',selection_name)
        REQUEST.set('x_axe',x_axe)
        REQUEST.set('start',start)
        REQUEST.set('delta1',old_delta[0])
        REQUEST.set('delta2',old_delta[1])
        REQUEST.set('constraint_method',constraint_method)
        for i in line_list:
950
          giant_string+=i.render_css(y_axis_width,security_index,x_subdivision)   
Sebastien Robin's avatar
Sebastien Robin committed
951
        return giant_string
Sebastien Robin's avatar
Sebastien Robin committed
952
    
Sebastien Robin's avatar
Sebastien Robin committed
953
    def render(self,field, key, value, REQUEST):
Sebastien Robin's avatar
Sebastien Robin committed
954 955
        """ this method return a string called 'giant_string' wich contains the planningbox html
            of the web page""" 
Sebastien Robin's avatar
Sebastien Robin committed
956 957
        here = REQUEST['here']
        portal_url= here.portal_url()
958
        title=field.get_value('title')
Sebastien Robin's avatar
Sebastien Robin committed
959 960
        line_list = REQUEST.get('line_list')
        x_axe = REQUEST.get('x_axe')  
961
        width_line = field.get_value('width_line')
Sebastien Robin's avatar
Sebastien Robin committed
962
        start_page=REQUEST.get('list_start')
963
        height_global_div = field.get_value('height_global_div')
964
        y_axis_width = field.get_value('y_axis_width')
Sebastien Robin's avatar
Sebastien Robin committed
965
        report_root_list=REQUEST.get('report_root_list')
966
        selection_name = field.get_value('selection_name')
Sebastien Robin's avatar
Sebastien Robin committed
967
        start_page=REQUEST.get('start')
968
        report_root_list = field.get_value('report_root_list')
Sebastien Robin's avatar
Sebastien Robin committed
969 970 971 972
        constraint_method=REQUEST.get('constraint_method')
        #the following javascript function allows to know where is exactly situated 
        #the beginning of lines in absolute coordinates since we have problems due to 
        #others tags (form,tr,table...) which are declared previously in the html.    
Sebastien Robin's avatar
Sebastien Robin committed
973
        
Sebastien Robin's avatar
Sebastien Robin committed
974 975 976 977 978 979 980
        giant_string="""<script type="text/javascript">
        function setLineBegin()
        {
        document.forms["main_form"]["line_begin"].value = document.getElementById("fra0").offsetLeft;
        }
        window.onmousemove = setLineBegin;
        </script>"""
Sebastien Robin's avatar
Sebastien Robin committed
981
        
Sebastien Robin's avatar
Sebastien Robin committed
982 983 984 985 986 987
        # we record current delta in delta1, and we record old_delta in delta2
        odelta=[REQUEST.get('delta1'),REQUEST.get('delta2')]
        selection = here.portal_selections.getSelectionFor(selection_name, REQUEST=REQUEST)
        giant_string+='<input type=\"hidden\" name=\"list_selection_name\" value='+selection_name+' />\n'
        
        #header of the graphic###
988 989 990 991
        giant_string+='<div id=\"header\" style=\"position:absolute;width:'+str(width_line+y_axis_width)+\
                      'px;height:'+str(height_global_div)+'px;background:#d5e6de;margin-left:0px;\
                       border-style:solid;border-color:#000000;border-width:1px;margin-top:1px\">\
                       <table><tr><td><h3><u>'+title+'</h3></u></td><td>'
Sebastien Robin's avatar
Sebastien Robin committed
992

Sebastien Robin's avatar
Sebastien Robin committed
993
        selection = here.portal_selections.getSelectionFor(selection_name, REQUEST=REQUEST)
994 995 996 997 998
        if selection is None:
          selection_report_path = report_root_list[0]
        else:  
          selection_report_path = selection.getReportPath()
        
Sebastien Robin's avatar
Sebastien Robin committed
999 1000 1001 1002 1003 1004
        report_tree_options = ''
        for c in report_root_list:
          if c[0] == selection_report_path:
            report_tree_options += """<option selected value="%s">%s</option>\n""" % (c[0], c[1])
          else:
            report_tree_options += """<option value="%s">%s</option>\n""" % (c[0], c[1])
Sebastien Robin's avatar
Sebastien Robin committed
1005
        
Sebastien Robin's avatar
Sebastien Robin committed
1006 1007 1008 1009
        report_popup = """<select name="report_root_url"
                       onChange="submitAction(this.form,'%s/portal_selections/setReportRoot')">
                       %s</select></td>\n""" % (here.getUrl(),report_tree_options)
        giant_string += report_popup
Sebastien Robin's avatar
Sebastien Robin committed
1010
        
Sebastien Robin's avatar
Sebastien Robin committed
1011
        #now we declare zoom widget 
1012 1013 1014 1015
        if selection != None:
          current_zoom=selection.getZoom()
        else:
          current_zoom = 1
Sebastien Robin's avatar
Sebastien Robin committed
1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089
        zoom=(0.25,0.5,0.75,1,2,4,8,10)
        zoom_select= """<td>
              <select name="zoom" onChange="submitAction(this.form,'"""
        zoom_select+=here.getUrl()+ '/portal_selections/setZoom\')">'
        for z in zoom:
          if z == float(current_zoom):
            zoom_select+='<option selected value=\"'+str(z)+'\">x'+str(z)+'</option>\n'
          else:
            zoom_select+='<option value=\"'+str(z)+'\">x'+str(z)+'</option>\n'
        giant_string += zoom_select
        
        
        #now the page number widget 
        pages='</select></td><td><select name="list_start" title=Change  \
        onChange="submitAction(this.form,\''+here.getUrl()+'/portal_selections/setPage\')">'
        selected=''
        date_planning=''
        if x_axe!=[]:
          x_planning=x_axe[2]
          delta=x_axe[3]
          if isinstance(x_planning, DateTime):
            date_planning = x_planning
            for p in range(1,float(current_zoom)+1):
              if x_planning == start_page :
                selected= 'selected '
              else:
                selected= '' 
              pages+='<option '+selected+'value=\"'+str(date_planning.Date())+'\">'+str(p)+' of '\
                     +str(current_zoom)+'</option>\n'
              date_planning+=delta
              x_planning=date_planning.Date()
          else:
            for p in range(1,float(current_zoom)+1):
              axe_index = 0
              while x_planning != x_axe[0][axe_index]:
                axe_index+=1 
              
              if x_planning == start_page :
                selected= 'selected '
              else:
                selected= '' 
              pages+='<option '+selected+'value=\"'+str(x_axe[0][axe_index])+'\">'+str(p)+' of '\
                     +str(current_zoom)+'</option>\n'
              axe_index = axe_index + delta       
              current_item = x_axe[0][axe_index]
        else:
          x_planning=[]
          delta=0
  
        pages+='</select></td></tr></table></div>\n'        
        giant_string += pages 
        #just because setPage wants it
        giant_string += '<input type=\"hidden\" name=\"listbox_uid:list\">\n'
        #we change old_delta2 to  old_delta1
        giant_string += '<input type=\"hidden\" name=\"old_delta1\" value=\"'+str(odelta[0])+'\">\n'
        giant_string += '<input type=\"hidden\" name=\"old_delta2\" value=\"'+str(odelta[0])+'\">\n' 
        giant_string+= '<input type=\"hidden\" name=\"block_moved\">\n'
        giant_string+= '<input type=\"hidden\" name=\"line_begin\">\n'

        for i in range(0,len(line_list)):
          giant_string+=line_list[i].render(portal_url,y_axis_width)    

        #here is the declaration of four divs which are used for redimensionning
        giant_string+='<div id=\"top\" style=\"position:absolute;width:5px;height:5px;\
                        background:#a45d10\"></div>\n'
        giant_string+='<div id=\"right\" style=\"position:absolute;width:5px;height:5px;\
                        background:#a45d10"></div>\n'
        giant_string+='<div id=\"bottom\" style=\"position:absolute;width:5px;height:5px\
                       ;background:#a45d10\"></div>\n'
        giant_string+='<div id=\"left\" style=\"position:absolute;width:5px;height:5px;\
                       background:#a45d10\"></div>\n'
        giant_string+='<script type=\"text/javascript\">\n'+ constraint_method + '('

        for i in range(0,len(line_list)):
Sebastien Robin's avatar
Sebastien Robin committed
1090
          graphic_call=''
Sebastien Robin's avatar
Sebastien Robin committed
1091 1092
          for j in line_list[i].content:
            if j.types=='activity' or j.types=='activity_error':
Sebastien Robin's avatar
Sebastien Robin committed
1093 1094 1095
              giant_string+='\"'+j.name+'\",'
            elif j.types=='info':
              giant_string+='\"'+j.name+'\"+NO_DRAG,'
Sebastien Robin's avatar
Sebastien Robin committed
1096 1097 1098 1099 1100 1101 1102
          current_object=line_list[i]
          if current_object.son!=[]:  
           giant_string+=createGraphicCall(current_object,graphic_call)     
        giant_string+='\"top\"+CURSOR_N_RESIZE+VERTICAL, \"right\"+CURSOR_E_RESIZE+HORIZONTAL,\
                       \"bottom\"+CURSOR_S_RESIZE+VERTICAL,\
                       \"left\"+CURSOR_W_RESIZE+HORIZONTAL);\n'
        giant_string+='</script> </div> \n '
Sebastien Robin's avatar
Sebastien Robin committed
1103 1104
        return giant_string  

Sebastien Robin's avatar
Sebastien Robin committed
1105
# class line 
Sebastien Robin's avatar
Sebastien Robin committed
1106
class Line:
Sebastien Robin's avatar
Sebastien Robin committed
1107 1108 1109 1110 1111 1112
  """objects which represent a line directly in a planningbox"""
  def __init__(self,title='',name='',begin=0,width=0,height=0,top=0,color='',son=None,y_type='none',
               paternity=0,url=''):  
    """used for building a Line object"""
    if son is None:
     son = []
Sebastien Robin's avatar
Sebastien Robin committed
1113 1114 1115 1116 1117 1118 1119 1120
    self.title=title
    self.name=name
    self.begin=begin
    self.width=width
    self.height=height
    self.top=top
    self.content=[]
    self.color=color
Sebastien Robin's avatar
Sebastien Robin committed
1121
    self.son=son
Sebastien Robin's avatar
Sebastien Robin committed
1122 1123 1124 1125 1126
    self.y_type=y_type
    self.paternity=paternity
    self.url=url

  def render(self,portal_url,y_axis_width):
Sebastien Robin's avatar
Sebastien Robin committed
1127
    """ creates "pure" html code of the line, its Block, its son """
Sebastien Robin's avatar
Sebastien Robin committed
1128 1129
    html_render='<div id=\"'+self.name+'\"></div>\n'
    for j in self.content:
Sebastien Robin's avatar
Sebastien Robin committed
1130 1131 1132
      if j.types=='activity' or j.types=='activity_error':
        #checks if the block starts before the beginning of the line               
        if ((self.begin+j.begin*self.width) < self.begin): 
1133 1134 1135
          html_render+='<div id=\"'+j.name+'\" ondblclick=\"showGrips()\" onclick=\"if (dd.elements.'\
                       +j.name+'.moved==0){dd.elements.'+j.name+'.moveBy('+str(round(j.begin*self.width))\
                       +',0);dd.elements.'+j.name+'.resizeTo('+str(round(j.width*self.width))+','\
Sebastien Robin's avatar
Sebastien Robin committed
1136 1137 1138 1139 1140 1141 1142
                       + str(j.height*(self.height-10))+');dd.elements.'+j.name+'.moved=1;} \">'
        # "done" is used because otherwise everytime we move the block it will execute moveby()
        #checks if the block is too large for the end of the line if it is the case, one cuts the block
        elif ((j.width*self.width)+(self.begin+j.begin*self.width)>self.width+y_axis_width): 
          html_render+='<div id=\"'+j.name+'\" ondblclick=\"showGrips()\" onclick=\"dd.elements.'\
                       +j.name+'.resizeTo('+str(round(j.width*self.width))+','\
                       +str(j.height*(self.height-10))+') \">'
Sebastien Robin's avatar
Sebastien Robin committed
1143 1144
        else:
          html_render+='<div id=\"'+j.name+'\" ondblclick=\"showGrips()\">'      
1145 1146
        # we add info Block inside the div thanks to the render method of the Block class
        html_render+=j.render(self.width,self.height,portal_url,self.begin,y_axis_width,self)      
Sebastien Robin's avatar
Sebastien Robin committed
1147 1148
        html_render+='</div>\n'
      elif j.types!='info':
1149
        html_render+='<div id=\"'+j.name+'\">'+str(j.text)+'</div>\n'      
Sebastien Robin's avatar
Sebastien Robin committed
1150 1151
    if self.son!=[]:
      for i in self.son:
1152
        html_render+=i.render(portal_url,y_axis_width)      
Sebastien Robin's avatar
Sebastien Robin committed
1153 1154 1155
    return html_render    
    
    
1156
  def render_css(self,y_axis_width,security_index,x_subdivision):
Sebastien Robin's avatar
Sebastien Robin committed
1157 1158 1159 1160
    """creates style sheet of each div which represents a Line instance """
    css_render='#'+self.name+'{position:absolute;\nborder-style:solid;\nborder-color:#53676e;\
                               \nborder-width:1px;\n'
    data={}
Sebastien Robin's avatar
Sebastien Robin committed
1161 1162 1163 1164 1165 1166 1167
    if self.color!='':
      css_render+='background:'+str(self.color)+';\n'
    css_render+='height:'+str(self.height)+'px;\n'
    css_render+='margin-left:'+str(self.begin)+'px;\n'
    css_render+='margin-top:'+str(self.top)+'px;\n'
    if self.y_type=='father1':
      css_render+='border-bottom-width:0px;'
Sebastien Robin's avatar
Sebastien Robin committed
1168
    elif self.y_type=='son1':
Sebastien Robin's avatar
Sebastien Robin committed
1169
      css_render+='border-top-width:0px;\nborder-bottom-width:0px;\n'    
Sebastien Robin's avatar
Sebastien Robin committed
1170
    elif self.y_type=='son2':
Sebastien Robin's avatar
Sebastien Robin committed
1171 1172 1173
      css_render+='border-top-width:0px;'
    css_render+='width:'+str(self.width)+'px;\n}'
    for j in self.content: #we generate block's css
Sebastien Robin's avatar
Sebastien Robin committed
1174 1175 1176 1177 1178 1179 1180
      if j.types=='activity' or j.types=='activity_error':
        if j.types=='activity':
          css_render+='#'+j.name+'{position:absolute;\nbackground:#bdd2e7;\nborder-style:solid;\
                      \nborder-color:#53676e;\nborder-width:1px;\n'
        if j.types=='activity_error':
          css_render+='#'+j.name+'{position:absolute;\nbackground:#bdd2e7;\nborder-style:solid;\
                      \nborder-color:#ff0000;\nborder-width:1px;\n'
1181 1182
        css_render+='height:'+str((j.height*(self.height-10))-security_index)+'px;\n' 
        #-10 because wee don't want a block sticked to border-top of the line
Sebastien Robin's avatar
Sebastien Robin committed
1183
        if ((self.begin+j.begin*self.width) < self.begin) and j.types!='activity_error': 
1184
        #checks if the block starts before the beginning of the line
Sebastien Robin's avatar
Sebastien Robin committed
1185 1186
          css_render+='margin-left:'+str(self.begin)+'px;\n' 
          css_render+='width:'+str((j.width*self.width+j.begin*self.width))+'px;\n' 
1187
        #checks if the block is too large for the end of the line. if it is the case, one cuts the block  
Sebastien Robin's avatar
Sebastien Robin committed
1188 1189 1190 1191
        elif ((j.width*self.width)+(self.begin+j.begin*self.width)>self.width+y_axis_width) and \
               j.types!='activity_error': 
          css_render+='width:'+str(round(j.width*self.width)-((self.begin+j.begin*self.width+
          j.width*self.width)-(self.width+y_axis_width)))+'px;\n'
Sebastien Robin's avatar
Sebastien Robin committed
1192 1193 1194 1195
          css_render+='margin-left:'+str(round(self.begin+j.begin*self.width))+'px;\n' 
        else:  
          css_render+='width:'+str(round(j.width*self.width))+'px;\n'
          css_render+='margin-left:'+str(round(self.begin+j.begin*self.width))+'px;\n' 
Sebastien Robin's avatar
Sebastien Robin committed
1196 1197 1198
        css_render+='margin-top:'+str(self.top+10+j.marge_top*(self.height-10))+'px;}\n'
        # we add info Block inside the div  
        css_render+=j.render_css(self.width,self.height,self,y_axis_width)       
Sebastien Robin's avatar
Sebastien Robin committed
1199 1200
        
      elif j.types=='text_x' : 
Sebastien Robin's avatar
Sebastien Robin committed
1201 1202 1203
        data={'border-style:':'solid;','border-color:':'#53676e;','border-width:':'1px;',
              'margin-left:':str(j.begin)+'px;',
              'margin-top:':str(round(1+self.top+self.height/2))+'px;'}
Sebastien Robin's avatar
Sebastien Robin committed
1204 1205
        
      elif j.types=='text_y':
Sebastien Robin's avatar
Sebastien Robin committed
1206 1207 1208
        data={'border-style:':'solid;','border-color:':'#53676e;','border-width:':'0px;',  
              'margin-left:':str(self.width/4)+'px;',
              'margin-top:':str(round(1+self.top+self.height/2))+'px;'}
Sebastien Robin's avatar
Sebastien Robin committed
1209 1210 1211


      elif j.types=='vertical_dotted':
Sebastien Robin's avatar
Sebastien Robin committed
1212 1213 1214 1215 1216
        data={'border-style:':'dotted;','border-color':'#53676e;',
              'margin-left:':str(j.begin)+'px;','margin-top:':str(1+round(self.top))+'px;',
              'height:':str(self.height)+'px;',
              'border-left-width:':'1px;','border-right-width:':'0px;','border-top-width:':'0px;',    
              'border-bottom-width:':'0px;'}
Sebastien Robin's avatar
Sebastien Robin committed
1217 1218

      elif j.types=='horizontal_dotted': 
Sebastien Robin's avatar
Sebastien Robin committed
1219 1220 1221 1222 1223
        data={'border-style:':'dotted;','border-color:':'#53676e;',
               'margin-left:':str(self.begin)+'px;','margin-top:':str(self.top+j.marge_top)+'px;',
               'border-left-width:':'0px;','border-right-width:':'0px;',
               'border-top-width:':'1px;','border-bottom-width:':'0px;',
               'width:':str(self.width)+'px;'}
Sebastien Robin's avatar
Sebastien Robin committed
1224 1225

      elif j.types=='y_coord':
Sebastien Robin's avatar
Sebastien Robin committed
1226 1227 1228 1229 1230 1231
        data={'border-style:':'solid;','border-color:':'#53676e;','border-width:':'0px;',
               'margin-left:':str(self.width-(len(j.text)*5))+'px;',
               'margin-top:':str(self.top+j.marge_top)+'px;',
               'height:':'','border-left-width:':'1px;','border-right-width:':'0px;',
               'border-top-width:':'0px;','border-bottom-width':'0px;','font-size:':'9px;'}
            
Sebastien Robin's avatar
Sebastien Robin committed
1232
      elif j.types=='vertical':
Sebastien Robin's avatar
Sebastien Robin committed
1233 1234 1235 1236 1237 1238 1239
        data={'border-style:':'solid;','border-color:':'#53676e;',
              'margin-left:':str((self.width/4)+j.begin)+'px;',
              'margin-top:':str(round(self.top)-self.height/2+13)+'px;',
              'height:':str(j.height)+'px;','border-left-width:':'1px;',
              'border-right-width:':'0px;','border-top-width:':'0px;', 
              'border-bottom-width:':'0px;'}
                       
Sebastien Robin's avatar
Sebastien Robin committed
1240
      elif j.types=='horizontal':
Sebastien Robin's avatar
Sebastien Robin committed
1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254
        data={'border-style:':'solid;','border-color:':'#53676e;',
              'margin-left:':str((self.width/4)+j.begin)+'px;',
              'margin-top:':str(round(1+self.top+self.height/2))+'px;',
              'height:':'1px;','border-left-width:':'0px;','border-right-width:':'0px;',
              'border-top-width:':'1px;','border-bottom-width:':'0px;','width:':'16px;','height:':'1px;',
             }      

      if j.types!='activity':
        if j.types!='activity_error':
          if j.types!='info':
            css_render+='#'+j.name+'{position:absolute;\n'
            for key in data:
              css_render+=key + data[key] + '\n'
            css_render+='}\n'  
Sebastien Robin's avatar
Sebastien Robin committed
1255

Sebastien Robin's avatar
Sebastien Robin committed
1256 1257 1258
    if self.son!=[]:
      for i in self.son:
        css_render+=i.render_css(y_axis_width,security_index,x_subdivision);
Sebastien Robin's avatar
Sebastien Robin committed
1259 1260
    return css_render      

Sebastien Robin's avatar
Sebastien Robin committed
1261 1262 1263 1264 1265 1266 1267 1268 1269
  def addBlock(self,name,block,error=0):
    """just create and add a block inside 'content' attribut of a Line instance""" 
    type_block=''
    if error == 0:
      type_block='activity'
    else:
      type_block='activity_error'
    self.content.append(Block(type_block,name=name,begin=block[0],width=block[1],height=block[2],text='',
                              content=block[3],marge_top=block[4],url=block[5]))
Sebastien Robin's avatar
Sebastien Robin committed
1270 1271 1272
    
    
  def addBlockInfo(self,name):
Sebastien Robin's avatar
Sebastien Robin committed
1273
    """add a block info inside an activity block"""
Sebastien Robin's avatar
Sebastien Robin committed
1274 1275 1276
    self.content.append(Block('info',name,0,0,0,''))
    
  def addBlockTextY(self,name,text):
Sebastien Robin's avatar
Sebastien Robin committed
1277
    """ add a text  block in y-axis"""
Sebastien Robin's avatar
Sebastien Robin committed
1278 1279 1280
    self.content.append(Block('text_y',name,0,0,0,text))  
  
  def addBlockCoordY(self,name,text,marge_top):
Sebastien Robin's avatar
Sebastien Robin committed
1281
    """ add a text block in y-axis (coordinates) """
Sebastien Robin's avatar
Sebastien Robin committed
1282 1283 1284
    self.content.append(Block('y_coord',name,0,0,0,text,{},marge_top))  
    
  def addBlockTextX(self,name,begin,text):
Sebastien Robin's avatar
Sebastien Robin committed
1285
    """ add a text block in x-axis"""
Sebastien Robin's avatar
Sebastien Robin committed
1286 1287 1288
    self.content.append(Block('text_x',name,begin,0,0,text))    
    
  def addBlockDottedVert(self,name,begin):
Sebastien Robin's avatar
Sebastien Robin committed
1289
    """ add a vertical dotted line"""
Sebastien Robin's avatar
Sebastien Robin committed
1290 1291 1292
    self.content.append(Block('vertical_dotted',name,begin,0,0,''))  
    
  def addBlockDottedHoriz(self,name,marge_top):
Sebastien Robin's avatar
Sebastien Robin committed
1293
    """append a dotted horizontal block"""
Sebastien Robin's avatar
Sebastien Robin committed
1294 1295 1296
    self.content.append(Block('horizontal_dotted',name,0,0,0,'',{},marge_top))   
  
  def addBlockVertical(self,name,marge_top,height,marge_left):
Sebastien Robin's avatar
Sebastien Robin committed
1297 1298
    """append a vertical block(line)""" 
    self.content.append(Block('vertical',name,marge_left,0,height,'',{},marge_top)) 
Sebastien Robin's avatar
Sebastien Robin committed
1299 1300
     
  def addBlockHorizontal(self,name,marge_top,height,marge_left):
Sebastien Robin's avatar
Sebastien Robin committed
1301 1302
    """append a horizontal  block (line)""" 
    self.content.append(Block('horizontal',name,marge_left,0,height,'',{},marge_top))    
Sebastien Robin's avatar
Sebastien Robin committed
1303 1304
         
  def appendVerticalDottedLine(self,x_axe,width_line,marge_left):
Sebastien Robin's avatar
Sebastien Robin committed
1305
    """append a vertical dotted  block"""
Sebastien Robin's avatar
Sebastien Robin committed
1306 1307 1308 1309 1310 1311 1312
    current_marge=marge_left
    indic=0
    for j in x_axe[1]:
      nameblock='Block_vert_'+self.name+str(indic)
      self.addBlockDottedVert(nameblock,current_marge)
      current_marge+=width_line/float(len(x_axe[1]))   
      indic+=1
Sebastien Robin's avatar
Sebastien Robin committed
1313 1314
    if self.son!=[]:
      for i in self.son:
Sebastien Robin's avatar
Sebastien Robin committed
1315 1316
        i.appendVerticalDottedLine(x_axe,width_line,marge_left) 
      
Sebastien Robin's avatar
Sebastien Robin committed
1317 1318 1319
  def buildYtype(self,way=[],y=[],level=0,y_axis_width=0,height_global_div=0,height_header=0,
                 height_axis_x=0,nbr_line=0,current_top=0,space_line=0,y_max=0,y_range=0,
                 y_unity=0,selection_name='',form=0): 
Sebastien Robin's avatar
Sebastien Robin committed
1320
    """ used for determining the type of each part of y axis taking into account father and children
Sebastien Robin's avatar
Sebastien Robin committed
1321 1322 1323 1324
       'way' is a list whichs allows to determinate if the current block is a type 'son1' or 'son2'.
        y parameter is a list which contains all the objects for creating y-axis.  

    """
Sebastien Robin's avatar
Sebastien Robin committed
1325 1326 1327
    report_url=self.url
    if level==0:
      name='axis'+str(self.name)
Sebastien Robin's avatar
Sebastien Robin committed
1328
      if self.son!=[]:
1329 1330 1331
        y.append(Line('',name,1,y_axis_width,
                ((height_global_div-height_header-height_axis_x-((nbr_line-1)*space_line))/float(nbr_line)),
                current_top,'',[],'father1'))
Sebastien Robin's avatar
Sebastien Robin committed
1332
      else:
Sebastien Robin's avatar
Sebastien Robin committed
1333 1334
        y.append(Line('',name,1,y_axis_width,((height_global_div-height_header-height_axis_x-\
        ((nbr_line-1)*space_line))/float(nbr_line)),current_top,'',[],'father2'))
Sebastien Robin's avatar
Sebastien Robin committed
1335 1336
        
      if self.paternity==1:
Sebastien Robin's avatar
Sebastien Robin committed
1337 1338 1339 1340
        if self.son!=[]:
          y[-1].addBlockTextY('ytext'+name,str(3*'&nbsp '*level)+\
          '<a href="portal_selections/foldReport?report_url='+report_url+'&form_id='+\
          form.id+'&list_selection_name='+selection_name+'">-'+self.title+'</a>')
Sebastien Robin's avatar
Sebastien Robin committed
1341
        else:
Sebastien Robin's avatar
Sebastien Robin committed
1342 1343 1344 1345
          y[-1].addBlockTextY('ytext'+name,str(3*'&nbsp '*level)+\
          '<a href="portal_selections/unfoldReport?report_url='+\
          report_url+'&form_id='+form.id+'&list_selection_name='+\
          selection_name+'">+'+self.title+'</a>')
Sebastien Robin's avatar
Sebastien Robin committed
1346
      else:
Sebastien Robin's avatar
Sebastien Robin committed
1347
        y[-1].addBlockTextY('ytext'+name,str(3*'&nbsp '*level)+self.title)
Sebastien Robin's avatar
Sebastien Robin committed
1348 1349 1350
      
      #one constructs the indicators
      if y_range!=0:
Sebastien Robin's avatar
Sebastien Robin committed
1351
        y[-1].createIndicators(y_unity,y_range,y_max,height_global_div,height_header,height_axis_x,nbr_line)
Sebastien Robin's avatar
Sebastien Robin committed
1352
      
Sebastien Robin's avatar
Sebastien Robin committed
1353
      if self.son!=[]:
Sebastien Robin's avatar
Sebastien Robin committed
1354
        level+=1
Sebastien Robin's avatar
Sebastien Robin committed
1355 1356
        for j in range(0,len(self.son)):
          if j==(len(self.son)-1):
Sebastien Robin's avatar
Sebastien Robin committed
1357 1358 1359
            way.append(1)
          else:
            way.append(0)
Sebastien Robin's avatar
Sebastien Robin committed
1360 1361
          current_top+=((height_global_div-height_header-height_axis_x-((nbr_line-1)*space_line))/
                       float(nbr_line))  
Sebastien Robin's avatar
Sebastien Robin committed
1362
         
Sebastien Robin's avatar
Sebastien Robin committed
1363 1364 1365 1366 1367 1368 1369 1370
          current_top=self.son[j].buildYtype(way=way,y=y,level=level,y_axis_width=y_axis_width,
                                             height_global_div=height_global_div,
                                             height_header=height_header,
                                             height_axis_x= height_axis_x,nbr_line=nbr_line,
                                             current_top=current_top,space_line=space_line,
                                             y_max=y_max,y_range=y_range,
                                             y_unity=y_unity,selection_name=selection_name,form=form)
          del way[-1]
Sebastien Robin's avatar
Sebastien Robin committed
1371 1372
  
    else:
Sebastien Robin's avatar
Sebastien Robin committed
1373
      if self.son!=[]:
Sebastien Robin's avatar
Sebastien Robin committed
1374 1375 1376
        name=str(self.name)
        for num in way:
          name=name+str(num)
1377
        y.append(Line('',name,1,y_axis_width,((height_global_div-height_header-height_axis_x)/float(nbr_line))
Sebastien Robin's avatar
Sebastien Robin committed
1378
                      ,current_top,'',[],'son1'))
Sebastien Robin's avatar
Sebastien Robin committed
1379 1380

        if self.paternity==1:
Sebastien Robin's avatar
Sebastien Robin committed
1381 1382 1383 1384 1385
          if self.son!=[]:
            y[-1].addBlockTextY('ytext'+name,str(3*'&nbsp '*level)+\
                                      '<a href="portal_selections/foldReport?report_url='+report_url+\
                                      '&form_id='+form.id+'&list_selection_name='+selection_name+'">-'+\
                                      self.title+'</a>')
Sebastien Robin's avatar
Sebastien Robin committed
1386
          else:
Sebastien Robin's avatar
Sebastien Robin committed
1387 1388 1389 1390
            y[-1].addBlockTextY('ytext'+name,str(3*'&nbsp '*level)+\
                                      '<a href="portal_selections/unfoldReport?report_url='+report_url+\
                                      '&form_id='+form.id+'&list_selection_name='+selection_name+'">+'\
                                      +self.title+'</a>') 
Sebastien Robin's avatar
Sebastien Robin committed
1391
        else:
Sebastien Robin's avatar
Sebastien Robin committed
1392
          y[-1].addBlockTextY('ytext'+name,str(3*'&nbsp '*level)+self.title)
Sebastien Robin's avatar
Sebastien Robin committed
1393 1394

        # one constructs the stick
Sebastien Robin's avatar
Sebastien Robin committed
1395 1396 1397 1398 1399
        y[-1].addBlockVertical('stickVer'+name,current_top-
                                    ((height_global_div-height_header-height_axis_x-((nbr_line-1)*space_line))\
                                    /float(nbr_line)),
                                    (height_global_div-height_header-height_axis_x-((nbr_line-1)*space_line))\
                                    /float(nbr_line),3*level*5-18) 
1400
                                     #5 is the width of the standart font, maybe a future parameter
Sebastien Robin's avatar
Sebastien Robin committed
1401 1402 1403 1404 1405
        y[-1].addBlockHorizontal('stickHor'+name,current_top-
                                    ((height_global_div-height_header-height_axis_x-((nbr_line-1)*space_line))\
                                    /float(nbr_line)),
                                    (height_global_div-height_header-height_axis_x-((nbr_line-1)*space_line))\
                                    /float(nbr_line),3*level*5-18) 
Sebastien Robin's avatar
Sebastien Robin committed
1406 1407
        #one constructs the indicators
        if y_range!=0:
Sebastien Robin's avatar
Sebastien Robin committed
1408
          y[-1].createIndicators(y_unity,y_range,y_max,height_global_div,height_header,height_axis_x,nbr_line)
Sebastien Robin's avatar
Sebastien Robin committed
1409
        level+=1
Sebastien Robin's avatar
Sebastien Robin committed
1410 1411 1412 1413
        for j in range(0,len(self.son)):
          current_top+=((height_global_div-height_header-height_axis_x-((nbr_line-1)*space_line))/\
                       float(nbr_line))
          if j==(len(self.son)-1):
Sebastien Robin's avatar
Sebastien Robin committed
1414 1415 1416
            way.append(1)
          else:
            way.append(0)
Sebastien Robin's avatar
Sebastien Robin committed
1417 1418 1419 1420 1421 1422 1423
          current_top=self.son[j].buildYtype(way=way,y=y,level=level,y_axis_width=y_axis_width,
                                             height_global_div=height_global_div,
                                             height_header=height_header,height_axis_x=height_axis_x,
                                             nbr_line=nbr_line,current_top=current_top,
                                             space_line=space_line,y_max=y_max,y_range=y_range,
                                             y_unity=y_unity,selection_name=selection_name,form=form)
          del way[-1]
Sebastien Robin's avatar
Sebastien Robin committed
1424 1425 1426 1427 1428 1429 1430 1431
      else:
        name=str(self.name)
        test='true'
        for num in way:
          name=name+str(num)
          if num==0:
            test='false'
        if test=='true':
Sebastien Robin's avatar
Sebastien Robin committed
1432 1433
          y.append(Line('',name,1,y_axis_width,((height_global_div-height_header-height_axis_x-\
                       ((nbr_line-1)*space_line))/float(nbr_line)),current_top,'',[],'son2'))
Sebastien Robin's avatar
Sebastien Robin committed
1434
        else:
Sebastien Robin's avatar
Sebastien Robin committed
1435 1436
          y.append(Line('',name,1,y_axis_width,((height_global_div-height_header-height_axis_x-\
                       ((nbr_line-1)*space_line))/float(nbr_line)),current_top,'',[],'son1'))
Sebastien Robin's avatar
Sebastien Robin committed
1437 1438
          
        if self.paternity==1:
Sebastien Robin's avatar
Sebastien Robin committed
1439 1440 1441 1442
          if self.son!=[]:
            y[-1].addBlockTextY('ytext'+name,str(3*'&nbsp '*level)+
            '<a href="portal_selections/foldReport?report_url='+report_url+
            '&form_id='+form.id+'&list_selection_name='+selection_name+'">-'+self.title+'</a>')
Sebastien Robin's avatar
Sebastien Robin committed
1443
          else:
Sebastien Robin's avatar
Sebastien Robin committed
1444 1445 1446
            y[-1].addBlockTextY('ytext'+name,str(3*'&nbsp '*level)+
            '<a href="portal_selections/unfoldReport?report_url='+report_url+
            '&form_id='+form.id+'&list_selection_name='+selection_name+'">+'+self.title+'</a>')
Sebastien Robin's avatar
Sebastien Robin committed
1447 1448
            
        else:
Sebastien Robin's avatar
Sebastien Robin committed
1449
          y[-1].addBlockTextY('ytext'+name,str(3*'&nbsp '*level)+self.title)  
Sebastien Robin's avatar
Sebastien Robin committed
1450 1451
  
        # one constructs the sticks
Sebastien Robin's avatar
Sebastien Robin committed
1452 1453 1454 1455 1456 1457 1458 1459
        y[-1].addBlockVertical('stickVer'+name,current_top-((height_global_div-height_header-\
                               height_axis_x-((nbr_line-1)*space_line))/float(nbr_line)),
                               (height_global_div-height_header-height_axis_x)/float(nbr_line),\
                               3*level*5-18)  
        y[-1].addBlockHorizontal('stickHor'+name,current_top-((height_global_div-height_header\
                                 -height_axis_x-((nbr_line-1)*space_line))/float(nbr_line)),
                                 (height_global_div-height_header-height_axis_x)/float(nbr_line),\
                                 3*level*5-18) 
Sebastien Robin's avatar
Sebastien Robin committed
1460 1461
        #one constructs the indicators   
        if y_range!=0:
Sebastien Robin's avatar
Sebastien Robin committed
1462 1463
          y[-1].createIndicators(y_unity,y_range,y_max,height_global_div,height_header,\
                                 height_axis_x,nbr_line)
Sebastien Robin's avatar
Sebastien Robin committed
1464 1465
    return current_top      

Sebastien Robin's avatar
Sebastien Robin committed
1466 1467 1468 1469
  def createIndicators(self,y_unity,y_range,y_max,height_global_div,height_header,\
                       height_axis_x,nbr_line):
    """creates a blocks used for y-axis coordinates"""
    
Sebastien Robin's avatar
Sebastien Robin committed
1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480
    maximum_y=y_max
    marge_top=0
    indic=0
    while maximum_y>=0:
      nameblock='Block_'+self.name+str(indic)
      text=str('%.2f' %maximum_y)+y_unity    
      self.addBlockCoordY(nameblock,text,marge_top) 
      maximum_y=maximum_y-(y_max/float(y_range)) 
      marge_top+=(((height_global_div-height_header-height_axis_x)/float(nbr_line))-10)/y_range 
      indic+=1

Sebastien Robin's avatar
Sebastien Robin committed
1481 1482 1483 1484

  def appendHorizontalDottedLine(self,marge_top,maximum_y,height_global_div,height_header,
                                 height_axis_x,nbr_line,y_range,y_max): 
    """creates a horizontal dotted line """
Sebastien Robin's avatar
Sebastien Robin committed
1485 1486 1487
    current_top=marge_top
    max_y=maximum_y
    indic=0
Sebastien Robin's avatar
Sebastien Robin committed
1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499
    if y_range !=0:
      while max_y>=0:
        nameblock='Block_hor_'+self.name+str(indic)
        self.addBlockDottedHoriz(nameblock,current_top) 
        max_y=max_y-(y_max/float((y_range-1)))  #-1 because we don't want a dotted line on the X-axis
        #10px under the top of the line . float is important here!
        current_top+=(((height_global_div-height_header-height_axis_x)/float(nbr_line))-marge_top)/y_range
        indic+=1
      if self.son!=[]:
        for i in self.son:
          i.appendHorizontalDottedLine(marge_top,maximum_y,height_global_div,
                                       height_header,height_axis_x,nbr_line,y_range,y_max)
Sebastien Robin's avatar
Sebastien Robin committed
1500
     
Sebastien Robin's avatar
Sebastien Robin committed
1501 1502
  def appendActivityBlock(self,list_block,list_error,old_delta,REQUEST):
    """create an activity block"""
Sebastien Robin's avatar
Sebastien Robin committed
1503
    indic=0
Sebastien Robin's avatar
Sebastien Robin committed
1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514
    name_block=''
    prev_deltaX=0
    prev_deltaY=0
    old_delta2=old_delta[1]
    if old_delta2!='None' and old_delta2!=None:
      if old_delta2!='':
        if old_delta2!={}:
          old_delta2=convertStringToDict(old_delta2)
    else:
      old_delta2={}  
    
Sebastien Robin's avatar
Sebastien Robin committed
1515
    for data_block in list_block:
Sebastien Robin's avatar
Sebastien Robin committed
1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535
      name_block='ActivityBlock_'+self.name+'_'+str(indic)
      if list_error != None: 
        for blockerror in list_error: #we are about to build block with red border
          if blockerror[0][0] == name_block:
            if old_delta2.has_key(name_block):
              prev_deltaX=float(old_delta2[name_block][0])
              prev_deltaY=float(old_delta2[name_block][1])
            deltaX =float(blockerror[0][3]) - float(blockerror[0][1])+prev_deltaX 
            deltaY = float(blockerror[0][4]) - float(blockerror[0][2])+prev_deltaY
            #data_block_error is [begin,width,top,info,height]
            begin=(blockerror[1].begin*blockerror[2].width+deltaX)/blockerror[2].width
            width=float(blockerror[0][5])/blockerror[2].width
            top=((blockerror[1].marge_top)*(blockerror[2].height-10)+deltaY)/(blockerror[2].height-10)
            height=float(blockerror[0][6])/(blockerror[2].height-10)
            data_block_error= [begin,width,height,data_block[3],top,blockerror[1].url]
            self.addBlock(name_block,data_block_error,1)  
          else:
            self.addBlock(name_block,data_block)
      else:
        self.addBlock(name_block,data_block)  
Sebastien Robin's avatar
Sebastien Robin committed
1536
      indic+=1
Sebastien Robin's avatar
Sebastien Robin committed
1537
    
Sebastien Robin's avatar
Sebastien Robin committed
1538
  def createXAxis(self,x_axe,width_line,y_axis_width):
Sebastien Robin's avatar
Sebastien Robin committed
1539
    """creates x-axis """
Sebastien Robin's avatar
Sebastien Robin committed
1540 1541
    marge_left=y_axis_width
    indic1=0
Sebastien Robin's avatar
Sebastien Robin committed
1542 1543 1544 1545 1546 1547
    if x_axe!=[]:
      for i in x_axe[1]:
        nameblock='block_'+self.name+str(indic1)
        self.addBlockTextX(nameblock,marge_left,i)
        indic1+=1  
        marge_left+=width_line/float(len(x_axe[1]))
Sebastien Robin's avatar
Sebastien Robin committed
1548
        
Sebastien Robin's avatar
Sebastien Robin committed
1549 1550 1551
  def addSon(self,son):
    """add a child Line to a Line """
    self.son.append(son)       
Sebastien Robin's avatar
Sebastien Robin committed
1552

Sebastien Robin's avatar
Sebastien Robin committed
1553 1554 1555 1556
  def createLineChild(self,report_section=None,field='',current_top=0,y_axis_width=0,
                      width_line=0,space_line=0,height_global_div=0,height_header=0,
                      height_axis_x=0,nbr_line=0,current_index=0,url=''): 
    """ create the Line object which is the son of an other Line Object"""
Sebastien Robin's avatar
Sebastien Robin committed
1557 1558 1559 1560
    if len(report_section[current_index].getObject().objectValues())!=0:
      paternity=1
    else:
      paternity=0   
Sebastien Robin's avatar
Sebastien Robin committed
1561 1562 1563 1564
    son=Line(title=str(report_section[current_index].getObject().getTitle()),
              name=self.name+'s'+str(current_index) ,begin=y_axis_width,width=width_line,
              height=(height_global_div-height_header-height_axis_x-((nbr_line-1)*space_line))\
              /float(nbr_line),top=current_top,color='#ffffff',paternity=paternity,url=url) 
Sebastien Robin's avatar
Sebastien Robin committed
1565 1566
    if (current_index+1)<=(len(report_section)-1): 
     if report_section[current_index+1].getDepth() == 0:
Sebastien Robin's avatar
Sebastien Robin committed
1567 1568
       current_top=current_top+((height_global_div-height_header-height_axis_x-
                   ((nbr_line-1)*space_line))/float(nbr_line))+space_line       
Sebastien Robin's avatar
Sebastien Robin committed
1569
     else:
Sebastien Robin's avatar
Sebastien Robin committed
1570 1571 1572
       current_top=current_top+((height_global_div-height_header-height_axis_x-
                   ((nbr_line-1)*space_line))/float(nbr_line))
    self.addSon(son)                
Sebastien Robin's avatar
Sebastien Robin committed
1573 1574
    return current_top 

Sebastien Robin's avatar
Sebastien Robin committed
1575 1576 1577 1578
  def insertActivityBlock(self,line_content=None,object_start_method_id=None,object_stop_method_id=None,
                          x_axe=[],field='',info_center='',info_topright='',info_topleft='',
                          info_backleft='',info_backright='',list_error='',old_delta='',REQUEST=None,
                          blocks_object={},width_line=0,script_height_block=None,y_max = 1):
1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590
    """allows to create the mobile block objects"""
    #first we check if the block has information
    center= getattr(line_content,info_center,None) 
    topright = getattr(line_content,info_topright,None)
    topleft = getattr(line_content,info_topleft,None)
    backleft= getattr(line_content,info_backleft,None)
    backright= getattr(line_content,info_backright,None)
    info={}
    if center!=None: info['center']=str(center())
    if topright!=None: info['topright']=str(topright())
    if topleft!=None: info['topleft']=str(topleft())
    if backleft!=None: info['botleft']=str(backleft())
Sebastien Robin's avatar
Sebastien Robin committed
1591
    if backright!=None: info['backright']=str(backright()) 
Sebastien Robin's avatar
Sebastien Robin committed
1592
    marge=0
1593
    method_start = getattr(line_content,object_start_method_id,None)  
Sebastien Robin's avatar
Sebastien Robin committed
1594
    method_stop= getattr(line_content,object_stop_method_id,None)
Sebastien Robin's avatar
Sebastien Robin committed
1595 1596
    wrong_left=0 
    wrong_right=0
Sebastien Robin's avatar
Sebastien Robin committed
1597
    list_block=[]
Sebastien Robin's avatar
Sebastien Robin committed
1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647
    if method_start==None and blocks_object!={}:
      for Ablock in blocks_object:
        #object_content is the current object used for building a block.
        #For instance if the context is a project, then object_content is an orderLine.
        for object_content in blocks_object[Ablock]:
          if self.title == Ablock.getObject().getTitle(): 
            method_start = getattr(object_content,object_start_method_id,None)  
            method_stop= getattr(object_content,object_stop_method_id,None)     
    
            if method_start != None:
              block_begin = method_start()
            else:
              block_begin = None
      
            if method_stop!=None:
              block_stop= method_stop()
            else:
              block_stop=None
            if isinstance(block_begin,DateTime):    
                if round(block_begin-DateTime(x_axe[0][0]))>0:
                  block_left=float(round(block_begin-DateTime(x_axe[0][0])))/round(
                             DateTime(x_axe[0][-1])-DateTime(x_axe[0][0]))
                elif round(block_begin-DateTime(x_axe[0][0]))==0:
                  block_left=0
                else:
                  block_left=float(round(block_begin-DateTime(x_axe[0][0])))/round(
                         DateTime(x_axe[0][-1])-DateTime(x_axe[0][0]))

                if block_stop-DateTime(x_axe[0][0])<=0:
                  wrong_left = 1  #means that the block is outside of x-axis range
        
                if block_begin-DateTime(x_axe[0][-1])>=0:            
                  wrong_right = 1 #the same
      
                block_right=float(round(block_stop-DateTime(x_axe[0][0])))/round(
                              DateTime(x_axe[0][-1])-DateTime(x_axe[0][0]))
                
                center= getattr(object_content,info_center,None) 
                topright = getattr(object_content,info_topright,None)
                topleft = getattr(object_content,info_topleft,None)
                backleft= getattr(object_content,info_backleft,None)
                backright= getattr(object_content,info_backright,None)
                info={}
                if center!=None: info['center']=str(center())
                if topright!=None: info['topright']=str(topright())
                if topleft!=None: info['topleft']=str(topleft())
                if backleft!=None: info['botleft']=str(backleft())
                if backright!=None: ignfo['botright']=str(backright())
                url = getattr(object_content,'domain_url','')
                url = object_content.getUrl()
1648 1649 1650
                
                #if there is a script wich allows to know the height of the current block,
                #then we use it, otherwise block's height is 0,75
Sebastien Robin's avatar
Sebastien Robin committed
1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680
                if script_height_block == None or y_max==1:
                  height = 0.75
                else:
                  height = float(script_height_block(object_content))/y_max
                if wrong_left!=1 and wrong_right!=1: # if outside we do not display
                  list_block.append([block_left,block_right-block_left,height,info,1-height,url])
            else:
              if block_begin !=None:
                for i in x_axe[0]:
                  if block_begin==i:
                    center= getattr(object_content,info_center,None) 
                    topright = getattr(object_content,info_topright,None)
                    topleft = getattr(object_content,info_topleft,None)
                    backleft= getattr(object_content,info_backleft,None)
                    backright= getattr(object_content,info_backright,None)
                    info={}
                    if center!=None: info['center']=str(center())
                    if topright!=None: info['topright']=str(topright())
                    if topleft!=None: info['topleft']=str(topleft())
                    if backleft!=None: info['botleft']=str(backleft())
                    if backright!=None: ignfo['botright']=str(backright())
                    url = getattr(object_content,'domain_url','')
                    if script_height_block == None or y_max==1:
                      height = 0.75
                    else:
                      height = float(script_height_block(object_content))/y_max
                    list_block.append([marge,(block_stop-block_begin)/(float(len(x_axe[0]))),height,info,
                                      1-height,url])   
               # 0.75(height) need to be defined        
                  marge+=1/float(len(x_axe[0])) 
Sebastien Robin's avatar
Sebastien Robin committed
1681
    else:
Sebastien Robin's avatar
Sebastien Robin committed
1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696
      if method_start != None:
        block_begin = method_start()
      else:
        block_begin = None
      
      if method_stop!=None:
        block_stop= method_stop()
      else:
        block_stop=None
      # if datas are DateTime type we need to do special process.
      if isinstance(block_begin,DateTime):    
        if round(block_begin-DateTime(x_axe[0][0]))>0:
          block_left=float(round(block_begin-DateTime(x_axe[0][0])))/round(
                     DateTime(x_axe[0][-1])-DateTime(x_axe[0][0]))
        elif round(block_begin-DateTime(x_axe[0][0]))==0:
1697 1698
          block_left=0
        else:
Sebastien Robin's avatar
Sebastien Robin committed
1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739
          block_left=float(round(block_begin-DateTime(x_axe[0][0])))/round(
                 DateTime(x_axe[0][-1])-DateTime(x_axe[0][0]))

        if block_stop-DateTime(x_axe[0][0])<=0:
          wrong_left = 1  #means that the block is outside of x-axis range
        
        if block_begin-DateTime(x_axe[0][-1])>=0:            
          wrong_right = 1 #the same
      
        block_right=float(round(block_stop-DateTime(x_axe[0][0])))/round(
                          DateTime(x_axe[0][-1])-DateTime(x_axe[0][0]))
        
        if wrong_left!=1 and wrong_right!=1: # if outside we do not display
          if script_height_block == None or y_max==1:
            height = 0.75
          else:
            height = float(script_height_block(line_content.getObject()))/y_max  
          list_block.append([block_left,block_right-block_left,height,info,1-height,''])
      else:
        if block_begin !=None:
          if block_stop !=None:
            for i in x_axe[0]:
              if block_begin==i:
                if script_height_block == None or y_max==1:
                  height = 0.75
                else:
                  height = float(script_height_block(line_content.getObject()))/y_max
              list_block.append([marge,1/(float(len(x_axe[0]))),height,info,1-height,''])   
                # 0.75(height) need to be defined        
              marge+=1/float(len(x_axe[0]))
          else:
            for i in x_axe[0]:
              if isinstance(block_begin,list): 
                for item in block_begin:
                  if item == i:
                    if script_height_block == None or y_max==1:
                      height = 0.75
                    else:
                      height = float(script_height_block(line_content.getObject()))/y_max
                    list_block.append([marge,1/(float(len(x_axe[0]))),height,info,1-height,''])  
              marge+=1/float(len(x_axe[0]))
Sebastien Robin's avatar
Sebastien Robin committed
1740
    if list_block!=[]:
Sebastien Robin's avatar
Sebastien Robin committed
1741
      self.appendActivityBlock(list_block,list_error,old_delta,REQUEST) 
Sebastien Robin's avatar
Sebastien Robin committed
1742
      
Sebastien Robin's avatar
Sebastien Robin committed
1743 1744
    if self.son!=[]:
      son_line= line_content.objectValues()
Sebastien Robin's avatar
Sebastien Robin committed
1745
      indic=0
Sebastien Robin's avatar
Sebastien Robin committed
1746
      while indic != len(son_line):
1747
        indic2=0
Sebastien Robin's avatar
Sebastien Robin committed
1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758
        for s in son_line:
          if s.getTitle() == self.son[indic].title:
            
            self.son[indic].insertActivityBlock(line_content=s,object_start_method_id=object_start_method_id,
                                                object_stop_method_id=object_stop_method_id,x_axe=x_axe,
                                                field=field,info_center=info_center,
                                                info_topright=info_topright,info_topleft=info_topleft,
                                                info_backleft=info_backleft,info_backright=info_backright,
                                                list_error=list_error,old_delta=old_delta,REQUEST=REQUEST,
                                                width_line=width_line,
                                                script_height_block=script_height_block)
Sebastien Robin's avatar
Sebastien Robin committed
1759
        indic+=1
Sebastien Robin's avatar
Sebastien Robin committed
1760
  
Sebastien Robin's avatar
Sebastien Robin committed
1761
        
Sebastien Robin's avatar
Sebastien Robin committed
1762
# class block      
Sebastien Robin's avatar
Sebastien Robin committed
1763
class Block:
Sebastien Robin's avatar
Sebastien Robin committed
1764 1765
  def __init__(self,types,name,begin,width=0,height=0,text='',content={},marge_top=0,id='',url=''):
    """creates a block object"""
Sebastien Robin's avatar
Sebastien Robin committed
1766 1767 1768 1769 1770 1771
    self.types=types
    self.name=name
    self.begin=begin
    self.width=width
    self.height=height
    self.text=text
1772
    self.content=content #stores info block in a dictionnary
Sebastien Robin's avatar
Sebastien Robin committed
1773
    self.marge_top=marge_top
Sebastien Robin's avatar
Sebastien Robin committed
1774 1775 1776 1777
    # self.color=color  should be cool to be implemented in the future...
    self.id = name
    self.url = url
  
1778
  def render(self,line_width,line_height,portal_url,line_begin,y_axis_width,line):
Sebastien Robin's avatar
Sebastien Robin committed
1779
    """used for inserting text in a block. one calculates how to organise the space.
Sebastien Robin's avatar
Sebastien Robin committed
1780 1781 1782
    one defines a width and height parameters (in pixel) which can be 
    changed (depends on the size and the font used).
    One fetches content which is a dictionnary like 
Sebastien Robin's avatar
Sebastien Robin committed
1783 1784
    this {'center':'ezrzerezr','topright':'uihiuhiuh',
          'topleft':'jnoinoin','botleft':'ioioioioi','botright':'ononono'}
Sebastien Robin's avatar
Sebastien Robin committed
1785
    """ 
Sebastien Robin's avatar
Sebastien Robin committed
1786 1787 1788 1789 1790 1791 1792 1793 1794
    string=''
    font_height=10
    font_width=6
    info=''
    #checks if the block starts before the beginning of the line
    if ((line_begin+self.begin*line_width) < line_begin): 
      block_width=self.width+self.begin 
    #checks if the block is too large for the end of the line. if it is the case, one cuts the block
    elif ((self.width*line_width)+(line_begin+self.begin*line_width)>line_width+y_axis_width): 
Sebastien Robin's avatar
Sebastien Robin committed
1795 1796
      block_width=self.width*line_width-((line_begin+self.begin*line_width+self.width*line_width)\
                  -(line_width+y_axis_width))
Sebastien Robin's avatar
Sebastien Robin committed
1797 1798 1799
      block_width=block_width/line_width
    else:
      block_width=self.width
Sebastien Robin's avatar
Sebastien Robin committed
1800 1801
    return self.buildInfoBlockBody(line_width,block_width,font_width,line_height,font_height,
                                   line,portal_url)
Sebastien Robin's avatar
Sebastien Robin committed
1802 1803
    
  def render_css(self,line_width,line_height,line,y_axis_width):
Sebastien Robin's avatar
Sebastien Robin committed
1804
    """used for inserting info inside an activity block"""
Sebastien Robin's avatar
Sebastien Robin committed
1805 1806 1807 1808
    string=''
    font_height=10
    font_width=6
    line_begin=line.begin
Sebastien Robin's avatar
Sebastien Robin committed
1809 1810
    #checks if the block starts before the beginning of the line
    if ((line_begin+self.begin*line_width) < line_begin) and self.types!='activity_error':
Sebastien Robin's avatar
Sebastien Robin committed
1811
      block_width=self.width+self.begin
Sebastien Robin's avatar
Sebastien Robin committed
1812 1813 1814 1815 1816
    #checks if the block is too large for the end of the line. if it is the case, one cuts the block  
    elif ((self.width*line_width)+(line_begin+self.begin*line_width)>line_width+y_axis_width) \
          and self.types!='activity_error':
      block_width=self.width*line_width-((line_begin+self.begin*line_width+self.width*line_width)\
                  -(line_width+y_axis_width))
Sebastien Robin's avatar
Sebastien Robin committed
1817 1818 1819
      block_width=block_width/line_width
    else:
      block_width=self.width
Sebastien Robin's avatar
Sebastien Robin committed
1820
    return self.buildInfoBlockCss(font_height,line_height,block_width,line_width,font_width,line)
Sebastien Robin's avatar
Sebastien Robin committed
1821
    
Sebastien Robin's avatar
Sebastien Robin committed
1822 1823 1824

  def addInfoCenter(self,info): 
    """add info in center of a block"""    
Sebastien Robin's avatar
Sebastien Robin committed
1825 1826
    self.content['center']=info  
    
Sebastien Robin's avatar
Sebastien Robin committed
1827 1828
  def addInfoTopLeft(self,info): 
    """add info in the top left corner of a block """   
Sebastien Robin's avatar
Sebastien Robin committed
1829 1830
    self.content['topleft']=info
  
Sebastien Robin's avatar
Sebastien Robin committed
1831 1832
  def addInfoTopRight(self,info): 
    """add info in the top right corner of a block"""    
Sebastien Robin's avatar
Sebastien Robin committed
1833 1834
    self.content['topright']=info
  
Sebastien Robin's avatar
Sebastien Robin committed
1835 1836
  def addInfoBottomLeft(self,info): 
    """add info in the bottom left corner of a block"""    
Sebastien Robin's avatar
Sebastien Robin committed
1837 1838
    self.content['botleft']=info
  
Sebastien Robin's avatar
Sebastien Robin committed
1839 1840
  def addInfoBottomRight(self,info): 
    """add info in the bottom right corner of a block"""    
Sebastien Robin's avatar
Sebastien Robin committed
1841 1842
    self.content['botright']=info
   
Sebastien Robin's avatar
Sebastien Robin committed
1843

1844
  def buildInfoBlockBody(self,line_width,block_width,font_width,line_height,font_height,line,portal_url):
Sebastien Robin's avatar
Sebastien Robin committed
1845 1846
    """ create the body of the html for displaying info inside a block"""
    string=''
Sebastien Robin's avatar
Sebastien Robin committed
1847
    #line_height=line_height-10
1848 1849 1850 1851
    already=0
    block_name=''
    length_list_info=0
    info=''
Sebastien Robin's avatar
Sebastien Robin committed
1852
    curr_url = ''
1853 1854 1855
    for i in self.content:
      if self.content[i]!=None:
        length_list_info += 1
Sebastien Robin's avatar
Sebastien Robin committed
1856
    for i in self.content:
1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869
      if length_list_info==5:
        test_height= font_height<=((self.height*line_height)/3)
        test_width= ((len(self.content[i])*font_width)<=((block_width*line_width)/3))
      if length_list_info==4 or length_list_info==3:
        test_height= font_height<=((self.height*line_height)/2)
        test_width= ((len(self.content[i])*font_width)<=((block_width*line_width)/2))
      if length_list_info==2:
        test_height=font_height<=(self.height*line_height)
        test_width= (len(self.content[i]*font_width)<=((block_width*line_width)/2))
      if length_list_info==1: 
        test_height= font_height<=(self.height*line_height)
        test_width= (len(self.content[i]*font_width)<=(block_width*line_width))   
      if test_height & test_width:
Sebastien Robin's avatar
Sebastien Robin committed
1870 1871 1872 1873 1874
        if self.url!='':
          curr_url = self.url
        else:
          curr_url = line.url
        string+='<div id=\"'+self.name+i+'\"><a href=\"'+portal_url+'/'+curr_url+'\">'+ self.content[i]
1875 1876 1877 1878 1879 1880 1881 1882
        string+='</a href></div>\n' 
      else: #one adds interogation.png  
        if ((self.width*line_width>=15) & (self.height*line_height>=15)): 
          info+=self.content[i]+'|'
          if already==0 or i=='center':
            block_name=self.name+i
            already=1
    if already==1:
Sebastien Robin's avatar
Sebastien Robin committed
1883 1884
      string+='<div id=\"'+block_name+'\" title=\"'+info+'\"><a href=\"'+portal_url+'/'+curr_url+'\">\
              <img src=\"'+portal_url+'/images/question.png\" height=\"15\" width=\"15\"></a href> '
1885
      string+='</div>\n'   
Sebastien Robin's avatar
Sebastien Robin committed
1886 1887
    return string     

Sebastien Robin's avatar
Sebastien Robin committed
1888

1889
  def buildInfoBlockCss(self,font_height,line_height,block_width,line_width,font_width,line):
Sebastien Robin's avatar
Sebastien Robin committed
1890
    """used for creating css code when one needs to add info inside a block"""
Sebastien Robin's avatar
Sebastien Robin committed
1891
    string=''
Sebastien Robin's avatar
Sebastien Robin committed
1892
    already=0#used when we add interro.png 
1893 1894 1895 1896 1897 1898
    list_info_length = 0 #counts number of info inside a block(between 0 and 5)
    for j in self.content:
      if  self.content[j]!= None:
        list_info_length += 1 
    if list_info_length ==0:return ''

Sebastien Robin's avatar
Sebastien Robin committed
1899 1900 1901 1902 1903 1904
    #definition of coefficient for different cases of info display.
    matrix = {
    ('center',5):{'left':2,'top':2},
    ('center',4):{'left':0,'top':0},
    ('center',3):{'left':2,'top':2},
    ('center',2):{'left':2,'top':2},
Sebastien Robin's avatar
Sebastien Robin committed
1905 1906
    ('center',1):{'left':2,'top':2},
    
Sebastien Robin's avatar
Sebastien Robin committed
1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962
    ('topright',5):{'left':1.01,'top':0},
    ('topright',4):{'left':1.01,'top':0},
    ('topright',3):{'left':1.01,'top':0},
    ('topright',2):{'left':1.01,'top':2},
    ('topright',1):{'left':1.01,'top':0},
    
    ('topleft',5):{'left':0,'top':0},
    ('topleft',4):{'left':1,'top':1},
    ('topleft',3):{'left':0,'top':0},
    ('topleft',2):{'left':0,'top':0},
    ('topleft',1):{'left':0,'top':0},
    
    ('botleft',5):{'left':0,'top':1},
    ('botleft',4):{'left':0,'top':1},
    ('botleft',3):{'left':0,'top':1},
    ('botleft',2):{'left':0,'top':1},
    ('botleft',1):{'left':0,'top':1},
    
    ('botright',5):{'left':1.01,'top':1.1},
    ('botright',4):{'left':1.01,'top':1.1},
    ('botright',3):{'left':1.01,'top':1.1},
    ('botright',2):{'left':1.01,'top':1.1},
    ('botright',1):{'left':1.01,'top':1.1}
    }   
    #definition of coefficient for different cases, when info strings are too long,
    #we use a small picture. The coefficient are suitable for are 15x15px picture. 
    matrix_picture = {
    ('center',5):{'left':2,'top':2},
    ('center',4):{'left':0,'top':0},
    ('center',3):{'left':2,'top':2},
    ('center',2):{'left':0,'top':2},
    ('center',1):{'left':2,'top':2},
    
    ('topright',5):{'left':1,'top':0},
    ('topright',4):{'left':1,'top':0},
    ('topright',3):{'left':1,'top':0},
    ('topright',2):{'left':1,'top':2},
    ('topright',1):{'left':0,'top':0},
    
    ('topleft',5):{'left':0,'top':0},
    ('topleft',4):{'left':1,'top':1},
    ('topleft',3):{'left':0,'top':0},
    ('topleft',2):{'left':0,'top':0},
    ('topleft',1):{'left':0,'top':0},
    
    ('botleft',5):{'left':0,'top':1},
    ('botleft',4):{'left':0,'top':1},
    ('botleft',3):{'left':0,'top':1},
    ('botleft',2):{'left':0,'top':1}, 
    ('botleft',1):{'left':0,'top':1},
    
    ('botright',5):{'left':1,'top':1},
    ('botright',4):{'left':0,'top':0},
    ('botright',3):{'left':0,'top':0},
    ('botright',2):{'left':0,'top':0},
    ('botright',1):{'left':1,'top':1}
Sebastien Robin's avatar
Sebastien Robin committed
1963
    }  
Sebastien Robin's avatar
Sebastien Robin committed
1964
    
1965 1966 1967 1968
    idx= 0
    margin_left=0
    margin_top=0
   
Sebastien Robin's avatar
Sebastien Robin committed
1969
    for i in self.content:         
1970 1971 1972 1973 1974 1975 1976 1977 1978 1979
      matrix_data = matrix[(i,list_info_length)]
      left = matrix_data['left']
      top= matrix_data['top']
      if left == 0:
        margin_left=0
      else:
        margin_left = round(((block_width*line_width)/left)-(font_width*len(self.content[i]))/left)  
      if top==0:
        margin_top=0  
      else:
Sebastien Robin's avatar
Sebastien Robin committed
1980
        margin_top = round(((self.height*(line_height-10))/top)-(font_height))
1981
      if list_info_length==5:
Sebastien Robin's avatar
Sebastien Robin committed
1982
        test_height= font_height<=((self.height*(line_height))/3)
1983 1984
        test_width= ((len(self.content[i])*font_width)<=((block_width*line_width)/3))
      if list_info_length==4 or list_info_length==3:
Sebastien Robin's avatar
Sebastien Robin committed
1985
        test_height= font_height<=((self.height*(line_height))/2)
1986 1987
        test_width= ((len(self.content[i])*font_width)<=((block_width*line_width)/2))
      if list_info_length==2:
Sebastien Robin's avatar
Sebastien Robin committed
1988
        test_height=font_height<=(self.height*(line_height))
1989 1990
        test_width= (len(self.content[i]*font_width)<=((block_width*line_width)/2))
      if list_info_length==1: 
Sebastien Robin's avatar
Sebastien Robin committed
1991
        test_height= font_height<=(self.height*(line_height))
1992 1993 1994
        test_width= (len(self.content[i]*font_width)<=(block_width*line_width))

      if test_height & test_width:
Sebastien Robin's avatar
Sebastien Robin committed
1995 1996
        string+='#'+self.name+i+'{position:absolute;\nmargin-left:'+\
                 str(margin_left)+'px;\nmargin-top:'+str(margin_top)+'px;\n}\n'              
1997 1998 1999 2000
        line.addBlockInfo(self.name+i)
      else: # we add question.png because the size of the block is not enough
        if ((self.width*line_width>=15) & (self.height*line_height>=15)): 
          matrix_data= matrix_picture[(i,list_info_length)]
Sebastien Robin's avatar
Sebastien Robin committed
2001 2002 2003 2004 2005
          left = matrix_data['left']
          top = matrix_data['top']
          if left == 0:
            margin_left=0
          else:
Sebastien Robin's avatar
Sebastien Robin committed
2006
           margin_left=round(((block_width*line_width)/left)-(15/left))
Sebastien Robin's avatar
Sebastien Robin committed
2007 2008 2009
          if top==0:
            margin_top=0  
          else:
2010 2011
            margin_top=round(((self.height*(line_height-10))/top)-(15/top))
          if i=='center' and list_info_length==3:
Sebastien Robin's avatar
Sebastien Robin committed
2012 2013
            margin_left=round(((block_width*line_width)/left)-(15/left))
            margin_top=round(((self.height*(line_height-10))/top)-(font_height))
2014 2015 2016
          if i=='center' and list_info_length==2:  
            margin_top=round(((self.height*(line_height-10))/top)-(font_height/top))    
          if already==0 or i=='center':
Sebastien Robin's avatar
Sebastien Robin committed
2017 2018
            string+='#'+self.name+i+'{position:absolute;\nmargin-left:'+str(margin_left)+\
                    'px;\nmargin-top:'+str(margin_top)+'0px;\n}'  
2019 2020
            block_disp=self.name+i
            already=1
Sebastien Robin's avatar
Sebastien Robin committed
2021 2022 2023 2024
    return string
    
  def get_error_message(self,err_type):
    return 'incorrect block'
Sebastien Robin's avatar
Sebastien Robin committed
2025 2026 2027 2028 2029 2030 2031 2032 2033 2034
PlanningBoxWidgetInstance = PlanningBoxWidget()        
          
class PlanningBox(ZMIField):
    meta_type = "PlanningBox"
    widget = PlanningBoxWidgetInstance
    validator = PlanningBoxValidatorInstance
    security = ClassSecurityInfo()
    security.declareProtected('Access contents information', 'get_value')
    def get_value(self, id, **kw):
      if id == 'default' and kw.get('render_format') in ('list', ):
Sebastien Robin's avatar
Sebastien Robin committed
2035 2036
        return self.widget.render(self, self.generate_field_key() , None , 
                                  kw.get('REQUEST'), render_format=kw.get('render_format'))
Sebastien Robin's avatar
Sebastien Robin committed
2037 2038 2039
      else:
        return ZMIField.get_value(self, id, **kw)

Sebastien Robin's avatar
Sebastien Robin committed
2040
    def render_css(self, value=None, REQUEST=None):      
Sebastien Robin's avatar
Sebastien Robin committed
2041
      return self.widget.render_css(self,'',value,REQUEST)