Ejemplo n.º 1
0
 def get_initial_events(self, request, rootid):
   '''Retrieves a list of initial javascript calls that should be sent to the client
      when the view first loads.  Typically, this is a series of add_processor
      events.'''
   root = datagate.get_item(rootid) 
   events = []
   checkedPoet = ""
   events.append(Event('populateCategories', checkedPoet))
   meeting = datagate.get_item(request.getvalue('global_meetingid', ''))
   usergroups = meeting.search1(name='groups')
   groups = datagate.get_child_items(usergroups.id)
   users = []
   for group in groups:
     users.append(group.name)
   tagSets = root.search1(name="sets")
   sets = []
   for tag in tagSets:
       sets.append(tag.name)
   
   # the questions list
   for child in root.search1(name="questions"):
     options = child.search1(name="options")     
     allChoices = options.get_child_items(self)
     allOptions = []
     for choice in allChoices:
       allOptions.append(choice.text)
     allSets = child.search1(name="sets")       
     tags = []
     for t in  allSets.get_child_items(self):
       tags.append(t.name)
     events.append(Event('addToQuestionList', child.id, child.text, child.delete))
     events.append(Event('addAllUsers', users))
     events.append(Event('addSets', sets))
     events.append(Event('populateForm', child.text, child.descrip, child.users, child.format, child.comment, child.comOpt, options.num_selections, allOptions, tags, child.na))
   return events  
Ejemplo n.º 2
0
 def add_question_action(self, request):
   root = datagate.get_item(request.getvalue('global_rootid', ''))
   creator = request.session.user
   questions = root.search1(name="questions")
   item = datagate.create_item(creatorid=creator.id, parentid=questions.id)
   item.name = "question"
   item.text = "New Question"
   item.delete = False
   item.descrip = ""
   poet = datagate.create_item(creatorid=creator.id, parentid=item.id)
   poet.name = 'poet'
   poet.save()
   sets = datagate.create_item(creatorid=creator.id, parentid=item.id)
   sets.name = 'sets'
   sets.save()
   tagSets = root.search1(name="sets")
   tags = []
   for tag in tagSets:
       tags.append(tag.name)
   meeting = datagate.get_item(request.getvalue('global_meetingid', ''))
   usergroups = meeting.search1(name='groups')
   groups = datagate.get_child_items(usergroups.id)
   users = []
   for group in groups:
     users.append(group.name)
   item.users = users
   item.format = 'likert'
   item.comment = ""
   item.comOpt = ""
   item.na = ""
   item.save()
   options = datagate.create_item(creatorid=creator.id, parentid=item.id)
   options.name = 'options'
   options.num_selections = 0
   options.save()
   answers = datagate.create_item(creatorid=creator.id, parentid=item.id)
   answers.name = 'answers'
   answers.save()
   events = []
   events.append(Event('addToQuestionList', item.id, item.text, item.delete))
   events.append(Event('addAllUsers', users))
   events.append(Event('addSets', tags))
   events.append(Event('populateForm', item.text, item.descrip, item.users, item.format, item.comment, item.comOpt, options.num_selections, [], '', item.na))
   return events
Ejemplo n.º 3
0
  def send_menu(self, request):
    '''Sends the menu'''
    meeting = Directory.get_meeting(request.getvalue('global_rootid', ''))
    activities_item = meeting.search1(name='activities')
    activities = datagate.get_child_items(activities_item.id)
    rights = self.get_user_rights(request)

    request.writeln(HTML_HEAD_NO_CLOSE + '''
      <script language='JavaScript' type='text/javascript'>
      <!--
        var views = new Array();
    ''')
    for activity in activities:
      request.writeln('        views["' + activity.id + '"] = "' + activity.view + '";')
    request.writeln('''        
        function selectActivity() {
          var activityid = document.getElementById('activityid').value;
          parent.activity.location.href = "''' + request.cgi_href(global_windowid=request.getvalue('global_windowid', ''), global_view=None, global_rootid=None, frame=None) + '''&global_view=" + views[activityid] + "&global_rootid=" + activityid;   
        }
        
        function initialLoad() {
          selectActivity();
        }
        
        function openHelp() {
          window.open("''' + WEB_PROGRAM_URL + '''/Help/", "helpwindow", "dependent,height=400,width=300,scrollbars,resizable");
          return false;
        }
      
        function gotoActivity(activityid, requester_sessionid) {
          var activity = document.getElementById('activityid');
          if ("''' + request.session.id + '''" != requester_sessionid) {
            activity.value = activityid;
            selectActivity();
          }else{
            alert("The sync message has been sent to all participants in this meeting.");
          }
        }

        function syncParticipants() {
          if (confirm("Syncronize this meeting's participants to this activity?")) {
            var activityid = document.getElementById('activityid').value;
            sendEvent('gotoActivity', activityid, "''' + request.session.id + '''");
          }
        }
        
      //-->
      </script>
      </head>      
    
      <body id="menu" ''" onload="initialLoad();" style="margin:0;padding:0;">
      <table cellspacing="0"  style="border-bottom:#99ccff 1px dotted;padding:3px;">
      	<tr>
      		<td id="menu-logo">
      			<div id="poet-logo">POET</div>
      		</td>
      	<td id="menu-activities">
    ''')

    user_is_pm = 0
    for child in meeting:
      if child.name == "groups":
        for group in child:
          if group.name == "PM":
            for pm_item in group:
              if pm_item.user_id == request.session.user.id:
                user_is_pm = 1

    if rights['Show Activities Selector'] or request.session.user.superuser == '1' or user_is_pm == 1: # don't show unless there are more than one or the superuser
      request.writeln('''
        <div class="hide">Activity:
        <select name="activityid" id='activityid' onchange="javascript:selectActivity()">
      ''')
      for activity in activities:
        request.writeln('<option value="' + activity.id + '">' + activity.name + '</option>')
      request.writeln('</select>')
      if request.session.user.superuser == '1':
        request.writeln('<input type="button" value="Sync Participants" onclick="javascript:syncParticipants();"></div>')

    # select activity based on meeting status
    elif meeting.status < 2: #results not released -- send to QuestionAsker
      # this hidden input allows the selectActivity() js functions to work (called with body.onLoad)
      request.writeln('<input type="hidden" name="activityid" id="activityid" value="' + activities[1].id + '">')
    else: #results released -- send to Findings
      request.writeln('<input type="hidden" name="activityid" id="activityid" value="' + activities[2].id + '">')

    request.writeln('</td><td id="user-menu">')
    request.writeln('logged in as <strong>' + html(request.session.user.name) + '</strong>')
    if request.session.user.superuser == '1' or user_is_pm == 1:
      request.writeln('<span class="divider">|</span> <a target="_top" href="' + request.cgi_href(itemid=meeting.id, global_view='Administrator', global_adminview='POET') + '">Edit</a>')
    request.writeln('''
        <span class="divider">|</span> <a onclick='javascript:openHelp();'>Help</a> <span class="divider">|</span> 
        <a target="_top" href="''' + request.cgi_href(global_view='logout') + '''" >Logout</a>
      </td></tr></table>
      <script language='JavaScript' type='text/javascript'>startEventLoop();</script>
      </body></html>
    ''')
Ejemplo n.º 4
0
  def process_admin_actions(self, request):
    '''Process all item actions'''
    meeting = datagate.get_item(request.getvalue('global_meetingid', ''))
    action = request.getvalue('_mhaction', '')

    if action == 'copyitem':
      meeting = datagate.copy_deep(request.getvalue('_copyitemid', ''), Directory.meetings_item.id)
      meeting.name = request.getvalue('_itemname', '')
      meeting.save()
      return meeting

    #elif action == 'publish':
    #handled by Ask

    elif action == 'results':
      meeting.status = 2
    
    elif action == 'import':
      try:
        importfile = request.form['subaction']
        gz = gzip.GzipFile(importfile.filename, 'r', fileobj=importfile.file)
        doc = xml.dom.minidom.parse(gz)
        
      except IOError:
        raise IOError, 'An error occurred while importing the file.  Are you sure it is a gzipped XML document (exported from GroupMind)?'
      return Directory.import_meeting(doc, request.session.user.id)

      activities_item = meeting.search1(name='activities')
      groups_item = meeting.search1(name='groups')
      if action == 'editname':
        itemname = request.getvalue('activityname', '')
        if itemname != '':
          child = activities_item.get_child(request.getvalue('activityid'))
          child.name = itemname
          child.save()
    
    elif action == 'addactivity':
      # create the activity
      name = request.getvalue('name', '')
      if name != '':
        activity = datagate.create_item(creatorid=request.session.user.id, parentid=activities_item.id)
        activity.name = name
        activity.previousid = request.getvalue('previousid', '')
        activity.view = request.getvalue('viewtype', '')
        activity.save()
        
        # allow the activity view to initialize itself
        BaseView.views[activity.view.lower()].initialize_activity(request, activity)

    elif action == 'delactivity':
      datagate.del_item(request.getvalue('activityid', ''))
      
    elif action == 'moveactivity':
      activity = datagate.get_item(request.getvalue('activityid'))
      parent = activity.get_parent()
      parent.remove_child(activity)
      parent.insert_child(activity, request.getvalue('previousid'))
      parent.save()
      
    elif action == 'addgroup':
      name = request.getvalue('name', '')
      if name != '':
        group = datagate.create_item(creatorid=request.session.user.id, parentid=groups_item.id)
        group.name = name
        group.save()
        
    elif action == 'delgroup':
      datagate.del_item(request.getvalue('groupid', ''))

    elif action == 'groupusers':
      fromGroup = request.getvalue('fromGroup', '')
      toGroup = request.getvalue('toGroup', '')
      users = request.getvalue('users', '').split()

      if not fromGroup == "unassigned_list":
        for c in datagate.get_child_items(fromGroup):
          for u in users:
            if c.user_id == u:
              datagate.get_item(fromGroup).remove_child(c)
      if not toGroup == "unassigned_list":
        for u in users:
          child = datagate.create_item(creatorid=request.session.user.id, parentid=toGroup)
          child.user_id = u
          child.save()

    elif action == 'addset':
      groupid = request.getvalue('groupid', '')
      group = datagate.get_item(groupid)
      submit = request.getvalue('switchSet', '')
      
      if submit == 'released':
        meeting.status = 1
        creator = request.session.user 

        activities_item = meeting.search1(name='activities')
        root = activities_item.search1(name="Question Editor")
        questions = root.search1(name="questions")
        groupMapping = root.search1(name="groupMapping")

        d = {} #dictionary -- for binding dynamic variable names to values
        for g in groupMapping:
          listName = (str(g.name) + "IDlist").replace(' ', '') #replace -- removes spaces
          d[listName] = []

        sets = root.search1(name="sets")
        d2 = {} #dictionary -- for binding dynamic variable names to values
        for s in sets:
          listName2 = (str(s.name) + "IDlist").replace(' ', '') #replace -- removes spaces
          d2[listName2] = []

        for q in questions:
          if  not q.delete:
            userGroups = q.users
            for u in userGroups:
              for g in groupMapping:
                if u == g.name:
                  listName = (str(g.name) + "IDlist").replace(' ', '')
                  (d[listName]).append(q.id)

            allSets = q.search1(name="sets")       
            for t in  allSets.get_child_items(self):
              for s in sets:
                if s.name == t.name:
                  listName2 = (str(s.name) + "IDlist").replace(' ', '')
                  (d2[listName2]).append(q.id)

        for g in groupMapping:
          children = g.get_child_items(self)
          if not children:
            p = datagate.create_item(creatorid=creator.id, parentid=g.id)
            p.name = 'percent'
            p.percent = 0
            p.save()
            ques = datagate.create_item(creatorid=creator.id, parentid=g.id)
            ques.name = 'quesId'
          else:
            ques = g.search1(name='quesId')

          listName = (str(g.name) + "IDlist").replace(' ', '')
          ques.quesId = d[listName]
          ques.save()

        for s in sets:
          childs = s.get_child_items(self)
          if not childs:
            questions = datagate.create_item(creatorid=creator.id, parentid=s.id)
            questions.name = "quesId"
          else:
            questions = s.search1(name='quesId')

          listName2 = (str(s.name) + "IDlist").replace(' ', '')
          questions.quesId = d2[listName2]
          questions.save()
      
        setsid = request.getvalue('setsid', '')
        sets = datagate.get_item(setsid)
        setList = []
        for item in sets:
          cbname = item.name + "_cb"
          cb = request.getvalue(cbname, '')
          if cb == "on":
            setList.append(item.name)
        if setList == []:
          group.sets = ''
        else:
          group.sets = setList 
      else:
        group.sets = ''
      group.save()
    # finally, return the meeting (since we might have created it here)          
    return meeting
Ejemplo n.º 5
0
  def send_tabs(self, request):
    global_meetingid = request.getvalue('global_meetingid', '')
    # the calling view can send in a tabdefsid which is the parent of the tab definitions
    # if it isn't sent, we assume the root id is also the tab definitions, which means the tabdef and the tab data parent are the same
    tabdefs = datagate.get_child_items(request.getvalue('tabdefsid', request.getvalue('global_rootid', '')))

    # get the tabs from the database
    # the root id is the parent of where we'll store the values for each tab
    rootid = request.getvalue('global_rootid', '')
    tabs = datagate.get_child_items(rootid)
    tabsdict = {} # a dict relating the linkitemids to the tab objects
    for tab in tabs:
      tabsdict[tab.linkitemid] = tab

    # initial tab id and view    
    initialtabid = request.session.get_attribute('tabpaneid', '')
    initialtabview = 'Commenter' # default to something

    # ensure we have items for each tabdef
    for tabdef in tabdefs:
      # grab the view if this is our meeting
      if initialtabid == tabdef.id:
        initialtabview = tabdef.view
        
      # if not created yet on this node, create it
      if tabsdict.has_key(tabdef.id):
        tab = tabsdict[tabdef.id]
      else:
        # create the new tab
        tab = datagate.create_item(creatorid=request.session.user.id, parentid=rootid)
        tab.linkitemid = tabdef.id
        tab.save()
        
        # allow the view to initialize the new item
        BaseView.views[tabdef.view.lower()].initialize_activity(request, tab)
        
        # save in the tabsdict
        tabsdict[tab.linkitemid] = tab

      # ensure the rights haven't changed
      rights_changed = 0
      for key in tabdef.__dict__.keys():
        if len(key) > 12 and key[:12] == 'grouprights_':
          if getattr(tab, key) != getattr(tabdef, key):
            setattr(tab, key, getattr(tabdef, key))
            rights_changed = 1
      if rights_changed:
        tab.save()
    
    # ensure we have an initial tab to select
    if (initialtabid == '' or not tabsdict.has_key(initialtabid)) and len(tabdefs) > 0: 
      initialtabid = tabdefs[0].id
      initialtabview = tabdefs[0].view

    # the javascript for selection    
    request.writeln(HTML_HEAD_NO_CLOSE + '''
      <script language='JavaScript' type='text/javascript'>
      <!--
        var selected = null;
        function select(linkitemid, tabid, tabview) {
          // unselect the previous one
          if (selected != null) {
            selected.style.fontWeight = "Normal";
          }
          // select the new one
          selected = document.getElementById(tabid);
          selected.style.fontWeight = "Bold";
          parent.tabdetail.location.href="''' + request.cgi_href(view=None, global_rootid=None) + '''&global_rootid=" + tabid + "&sessionattribute=tabpaneid," + linkitemid + "&view=" + tabview;
        }      
        
        function initialLoad() {
          select("''' + initialtabid + '''", "''' + tabsdict[initialtabid].id + '''", "''' + initialtabview + '''");
        }
      //-->
      </script>
            
      <style type="text/css">
        .tab        
        {
          font-family: Helvetica;
          font-size: small;
          letter-spacing: 1px;
          word-spacing: 2px;
          padding-bottom: 5px;
          cursor: pointer; 
        }
      </style>      
    ''')
    request.writeln('</head>' + HTML_BODY_NO_CLOSE + ' style="padding: 5px" onLoad="javascript:initialLoad()">')

    # send the title, if there is one
    title = request.getvalue('title', '')
    if title != '':
      request.writeln('<div align="center" style="font-size: large; padding-bottom: 5px">' + title + '</div>')

    # send the tabs
    lasttab = len(tabdefs) - 1
    request.writeln('<table border="0" cellspacing="0" cellpadding="0" width="100%">')

    # header row
    request.writeln('<tr>')
    request.writeln('<td></td>')
    request.writeln('<td background="' + join(WEB_PROGRAM_URL, 'tab-dark.png') + '"><img src="' + join(WEB_PROGRAM_URL, 'tab-dark.png') + '"></td>')
    for i in range(len(tabdefs)):
      tabdef = tabdefs[i]
      tab = tabsdict[tabdef.id]
      request.writeln('<td background="' + join(WEB_PROGRAM_URL, 'tab-top.png') + '"><img src="' + join(WEB_PROGRAM_URL, 'tab-top.png') + '"></td>')
      if i == lasttab:
        request.writeln('<td background="' + join(WEB_PROGRAM_URL, 'tab-curve-end.png') + '"><img src="' + join(WEB_PROGRAM_URL, 'tab-curve-end.png') + '"></td>')
      else:
        request.writeln('<td background="' + join(WEB_PROGRAM_URL, 'tab-curve.png') + '"><img src="' + join(WEB_PROGRAM_URL, 'tab-curve.png') + '"></td>')
    request.writeln('<td></td>')
    request.writeln('</tr>')
    
    # main row
    request.writeln('<tr>')
    request.writeln('<td></td>')
    request.writeln('<td background="' + join(WEB_PROGRAM_URL, 'tab-dark.png') + '"><img src="' + join(WEB_PROGRAM_URL, 'tab-dark.png') + '"></td>')
    for i in range(len(tabdefs)):
      tabdef = tabdefs[i]
      tab = tabsdict[tabdef.id]
      if i == 0:
        request.writeln('<td noWrap id="' + tab.id + '" onClick="select(\'' + tabdef.id + '\', \'' + tab.id + '\', \'' + tabdef.view + '\')" bgcolor="#F4F4F4" class="tab" style="padding-left:8px">' + tabdef.name + '</td>')
      else:
        request.writeln('<td noWrap id="' + tab.id + '" onClick="select(\'' + tabdef.id + '\', \'' + tab.id + '\', \'' + tabdef.view + '\')" bgcolor="#F4F4F4" class="tab">' + tabdef.name + '</td>')
      if i == lasttab:
        request.writeln('<td background="' + join(WEB_PROGRAM_URL, 'tab-line-end.png') + '"><img src="' + join(WEB_PROGRAM_URL, 'tab-line-end.png') + '"></td>')
      else:
        request.writeln('<td background="' + join(WEB_PROGRAM_URL, 'tab-line.png') + '"><img src="' + join(WEB_PROGRAM_URL, 'tab-line.png') + '"></td>')
    request.writeln('<td></td>')
    request.writeln('</tr>')
    
    # footer row    
    request.writeln('<tr>')
    request.writeln('<td><img src="' + join(WEB_PROGRAM_URL, 'tab-dark.png') + '"><img src="' + join(WEB_PROGRAM_URL, 'tab-dark.png') + '"><img src="' + join(WEB_PROGRAM_URL, 'tab-dark.png') + '"><img src="' + join(WEB_PROGRAM_URL, 'tab-dark.png') + '"><img src="' + join(WEB_PROGRAM_URL, 'tab-dark.png') + '"></td>')
    request.writeln('<td background="' + join(WEB_PROGRAM_URL, 'tab-dark.png') + '"><img src="' + join(WEB_PROGRAM_URL, 'tab-dark.png') + '"></td>')
    for i in range(len(tabdefs)):
      tabdef = tabdefs[i]
      tab = tabsdict[tabdef.id]
      request.writeln('<td background="' + join(WEB_PROGRAM_URL, 'tab-dark.png') + '"><img src="' + join(WEB_PROGRAM_URL, 'tab-dark.png') + '"></td>')
      if i == lasttab:
        request.writeln('<td background="' + join(WEB_PROGRAM_URL, 'tab-botright-end.png') + '"><img src="' + join(WEB_PROGRAM_URL, 'tab-botright-end.png') + '"></td>')
      else:
        request.writeln('<td background="' + join(WEB_PROGRAM_URL, 'tab-dark.png') + '"><img src="' + join(WEB_PROGRAM_URL, 'tab-dark.png') + '"></td>')
    request.writeln('<td width="100%" background="' + join(WEB_PROGRAM_URL, 'tab-dark.png') + '"><img src="' + join(WEB_PROGRAM_URL, 'tab-dark.png') + '"></td>')
    request.writeln('</tr>')
    
    request.writeln('</table>')
    request.writeln('</html>')
Ejemplo n.º 6
0
  def send_admin_page(self, request):
    '''Sends an administrator page for this view.'''

    # send the html    
    request.writeln('''
      <script language='JavaScript' type='text/javascript'>
      <!--
        function editname(id, name) {
          var text = prompt("Edit item Name:", name);
          if (text != null && text != '') {
            text = encode(text);
            window.location.href = "''' + request.cgi_href(gm_action='TabPane.editname', itemid=item.id, activityid=None, activityname=None) + '''&activityid=" + id + "&activityname=" + text;
          }
        }
        
      //-->
      </script>
    ''')

    # item name
    request.writeln("<p><center><font size=+1>Edit " + self.title + ": " + item.name + "</font>")
    request.writeln("</center></p>")
    
    # activities in this item (top level records in the Items table)
    activities = datagate.get_child_items(item.id)
    if len(activities) == 0: previousid=''
    else: previousid = activities[-1].id
    request.writeln(request.cgi_form(gm_action='TabPane.addactivity', name=None, previousid='last', itemid=item.id, text=None, viewtype=None) + '''
      <center>
      <table border=1 cellspacing=0 cellpadding=5>
        <tr>
          <th>&nbsp;</th>
          <th>Activity</th>
          <th>Type</th>
          <th>Actions</th>
        </tr>
    ''')
    for i in range(len(activities)):
      activity = activities[i]
      request.writeln('<tr>')
      request.writeln('<td>&nbsp;' + str(i+1) + '.&nbsp;</td>')
      request.writeln('<td><a href="javascript:editname(\'' + activity.id + '\', \'' + decode(activity.name).replace("'", "\\'") + '\');">' + activity.name + '</a></td>')
      request.writeln('<td>' + BaseView.regular_components_dict[activity.view.lower()].NAME + '</td>')
      request.write('<td>')
      if i == 0: request.write('Up')
      else: request.write('<a href="' + request.cgi_href(itemid=item.id, gm_action='TabPane.moveactivity', activityid=activity.id, previousid=activities[i-1].get_previousid()) + '">Up</a>')
      request.write('&nbsp;|&nbsp;')
      if i == len(activities) - 1: request.write('Down')
      else: request.write('<a href="' + request.cgi_href(itemid=item.id, gm_action='TabPane.moveactivity', activityid=activity.id, previousid=activities[i+1].id) + '">Down</a>')
      request.write('&nbsp;|&nbsp;')
      request.write('<a href="' + request.cgi_href(itemid=activity.id, gm_action=None, view='Administrator', global_adminview=activity.view) + '">Edit</a>')
      request.write('&nbsp;|&nbsp;')
      request.write('''<a href="javascript:confirm_url('Delete this activity and *all* related data?', \'''' + request.cgi_href(itemid=item.id, gm_action='TabPane.delactivity', activityid=activity.id) + '''\');">Delete</a>''')
      request.writeln('</td>')
      request.writeln('</tr>')
    request.writeln('''
        <tr>
          <td>&nbsp;</td>
          <td><input type="text" name="name" value="New Activity" onfocus="clearField(this);"></td>
          <td>
            <select name="viewtype">
    ''')
    for activity_type in BaseView.regular_components:
      request.writeln('<option value="' + activity_type[0] + '">' + activity_type[1].NAME + '</option>')
    request.writeln('''
            </select>
          </td>
          <td align="center"><input type="submit" value="Add"></td>
        </tr>
      </table>
      </center>
      </form>
    ''')
    
    return item
Ejemplo n.º 7
0
 def get_data_items(self, request):
   '''Retrieves the data items for this view.'''
   return datagate.get_child_items(request.getvalue('global_rootid', ''))
Ejemplo n.º 8
0
  def send_menu(self, request):
    '''Sends the menu'''
    meeting = Directory.get_meeting(request.getvalue('global_rootid', ''))
    activities_item = meeting.search1(name='activities')
    activities = datagate.get_child_items(activities_item.id)
    rights = self.get_user_rights(request)

    request.writeln(HTML_HEAD_NO_CLOSE + '''
      <script language='JavaScript' type='text/javascript'>
      <!--
        var views = new Array();
    ''')
    for activity in activities:
      request.writeln('        views["' + activity.id + '"] = "' + activity.view + '";')
    request.writeln('''        
        function selectActivity() {
          var activityid = document.getElementById('activityid').value;
          parent.activity.location.href = "''' + request.cgi_href(global_windowid=request.getvalue('global_windowid', ''), global_view=None, global_rootid=None, frame=None) + '''&global_view=" + views[activityid] + "&global_rootid=" + activityid;
        }
        
        function initialLoad() {
          selectActivity();
        }
        
        function openHelp() {
          window.open("''' + WEB_PROGRAM_URL + '''Help/", "helpwindow", "dependent,height=400,width=300,scrollbars,resizable");
          return false;
        }
        
        function gotoActivity(activityid, requester_sessionid) {
          var activity = document.getElementById('activityid');
          if ("''' + request.session.id + '''" != requester_sessionid) {
            activity.value = activityid;
            selectActivity();
          }else{
            alert("The sync message has been sent to all participants in this meeting.");
          }
        }

        function syncParticipants() {
          if (confirm("Syncronize this meeting's participants to this activity?")) {
            var activityid = document.getElementById('activityid').value;
            sendEvent('gotoActivity', activityid, "''' + request.session.id + '''");
          }
        }
        
      //-->
      </script>
      </head>      
    
      <body background="''' + join(WEB_PROGRAM_URL, "background1.png") + '''" onload="initialLoad();">
      <table border=0 cellspacing=3 cellpadding=0 width=100%><tr><td nowrap valign="center" align="left" style="color:#FFFFFF; font-weight:800">
        ''' + html(meeting.name) + ''': ''' + html(request.session.user.name) + '''
      </td><td nowrap align="center" style="color:#FFFFFF">
    ''')

    if rights['Show Activities Selector'] or request.session.user.superuser == '1': # don't show unless there are more than one or the superuser
      request.writeln('''
        Activity:
        <select name="activityid" id='activityid' onchange="javascript:selectActivity()">
      ''')
      for activity in activities:
        request.writeln('<option value="' + activity.id + '">' + activity.name + '</option>')
      request.writeln('</select>')
      if request.session.user.superuser == '1':
        request.writeln('<input type="button" value="Sync Participants" onclick="javascript:syncParticipants();">')
    
    else: 
      # this hidden input allows the selectActivity() js functions to work (called with body.onLoad)
      request.writeln('<input type="hidden" name="activityid" id="activityid" value="' + activities[0].id + '">')

    request.writeln('</td><td align="right" style="color:#FFFFFF">')
    if request.session.user.superuser == '1':
      request.writeln('<a style="color:white" target="_top" href="' + request.cgi_href(itemid=meeting.id, global_view='Administrator', global_adminview='MeetingHome') + '">Administrator</a> | ')
    request.writeln('''
        <a style='color:white' onclick='javascript:openHelp();'>Help</a>
        | 
        <a target="_top" href="''' + request.cgi_href(global_view='logout') + '''" style="color:white">Logout</a>
      </td></tr></table>
      <script language='JavaScript' type='text/javascript'>startEventLoop();</script>
      </body></html>
    ''')
Ejemplo n.º 9
0
def get_meetings():
  '''Returns all meetings in the database as a list of items'''
  return datagate.get_child_items(meetings_item.id)
Ejemplo n.º 10
0
  def send_admin_page(self, request):
    '''Shows the administrator page for this view. (when the user clicks Edit in the administrator)'''
    # get the game objects
    game = datagate.get_item(request.getvalue('itemid'))
    teams = game.search1(name='groups')
    board = game.search1(name='board')
    turns = game.search1(name='turns')
    
    # toc
    request.writeln('Strikecom Setup:')
    request.writeln('<ul>')
    request.writeln('<li><a href="#general">General Setup</a></li>')
    request.writeln('<li><a href="#assets">Assets</a></li>')
    request.writeln('<li><a href="#teams">Game Teams</a></li>')
    request.writeln('<li><a href="#board">Playing Board</a></li>')
    request.writeln('</ul>')
    
    ##### Strikecom General Setup #####
    request.writeln('<a name="general"></a><h1>General Setup:</h1>')
    request.writeln(request.cgi_form(gm_action='StrikeCom.numturns', totalturns=None))
    request.writeln('<div>Total number of turns: <input type="text" size="10" value="' + str(turns.totalturns) + '" name="totalturns"></div>')
    request.writeln('<div align="center"><input type="submit" value="Save"></div>')
    request.writeln('</form>')


    ##### Strikecom Assets Setup #####

    zeroTurn = turns.get_child(turns.childids[0]).search1(name='assetmoves')
    assets = zeroTurn.get_child_items()
    
    request.writeln('<a name="assets"></a><h1>Asset Setup:</h1>')        
        
    if len(teams.get_child_items()) == 0:
      request.writeln('Please add at least one team before setting up assets.')
    else:
      request.writeln(request.cgi_form(view='AssetLibraryExporter', global_meetingid=game.id, gm_contenttype='application/x-gzip',contentdisposition="AssetLibrary.gz"))
      request.writeln('<div align="center"><input type="button" value="Create Asset" onclick="window.open(\'' + request.cgi_href(global_rootid=game.id, view='StrikeComAsset', assetid=None) + '\',\'blah\',\'width=400,height=400\')">')
      if len(assets) > 0:
        request.writeln('<input type="submit" value="Export Assets">')
      request.writeln('</form>')
      request.writeln(request.cgi_multipart_form(action = 'AssetLibraryExporter.assetimporter', global_meetingid=game.id))
      request.writeln('Import Asset Library: <input type="file" size="20" name="_assetlibrary">')
      request.writeln('<input type="submit" value="Import Assets"></form>')
        

      request.writeln('''</div>''')
      request.writeln('<center>')
      request.writeln('''
       <table border=1 cellspacing=0 cellpadding=5>
          <tr id="headers">
            <th>Asset Icon</th>
            <th>Name</th>
            <th>Actions</th>
            <th>Team</th>
            <th>Assignments</th>
          </tr>
      ''')
     
      # since assets are multiple times in the tree, we need to boil it
      # down to the last instance of the asset in the tree
      assets.reverse()
      unique = {}
      for asset in assets :
        if asset.assetid not in unique:
          unique[asset.assetid]=asset
      assets = unique.values()
  
      assets.sort(lambda a,b: cmp(a.name.lower(), b.name.lower()))
      ctr=0
      for asset in assets:
          request.writeln('''
              <tr name="asset_row'''+str(ctr)+'''" id="asset_row'''+str(ctr)+'''"><td>
          ''')
          if asset.filename:
            request.writeln('<img src="'''+ request.cgi_href(view="Filer", global_rootid=asset.id, gm_contenttype=asset.filetype) + '">')
          else:
            request.writeln('&nbsp;')
          request.writeln('</td><td>')
          request.writeln(str(asset.name))
          request.writeln('</td>')
         
          request.writeln('<td align="center" id="actions_td'+str(ctr)+'">') #note if you don't add the ctr var at the end it isn't unigue and weird things happen.
          request.writeln('<a href="#" onclick="window.open(\'' + request.cgi_href(global_rootid=game.id, view='StrikeComAsset', assetid=asset.id) + '\',\'blah\',\'width=400,height=800\')">Edit</a>')
          request.writeln('|')
          request.writeln('<a href="' + request.cgi_href(global_meetingid=game.id, itemid=game.id, gm_action='StrikeCom.delasset', assetid = asset.id, assetname=asset.name) + '">Delete</a>');
          request.writeln('</td><td>')
          
          # team assigned to this asset
          request.writeln(request.cgi_form(gm_action='StrikeCom.assetteam', global_meetingid=game.id, _assetid=asset.id))
          request.writeln('<select name="_teamid" onchange="this.form.submit()">')
          if asset.getvalue('teamid', '') == '':  # make sure this asset is assigned a team
            asset.teamid = teams[0].id
            asset.save()
          for group in teams:
            selected = group.id == asset.teamid and ' selected' or ''
            request.writeln('<option ' + selected + ' value="' + group.id + '">' + group.name + '</option>')
          request.writeln('</select>')        
          request.writeln('</form>')
          
          # team member rights in this asset
          request.writeln('</td><td>')        
          request.writeln(request.cgi_form(gm_action='StrikeCom.assignasset', global_meetingid=game.id, id='assignform', _itemid=asset.id, _assetid=asset.assetid))
          request.writeln('''<table border=1 cellspacing=0 cellpadding=5 id='new_table' id='new_table'>''')
          group = datagate.get_item(asset.teamid)
          
          if group == None:
            group = teams.get_child_items()[0]
          group_ctr = 1
          request.writeln('''<tr><td align='left'>&nbsp;</td><td align='center'><b> <a href='#asset_row' onclick=switchCheckBoxes('see_check'''+str(ctr)+''+str(group_ctr)+'''')>See</a> : <a href='#asset_row' onclick=switchCheckBoxes('move_check'''+str(ctr)+''+str(group_ctr)+'''')>Move</a></b></td></tr>''')
          user_ctr=0
          for member in group:
              user = Directory.get_user(member.user_id) #user is the actual user object.  member is the child of a group
              request.writeln('''<tr><td align='right'>'''+user.name+'''</td>''')
              try:
                  asset.visible_by.index(user.id)
                  request.writeln('''<td align='left'>&nbsp;&nbsp;<input id="see_check'''+str(ctr)+""+str(group_ctr)+""+str(user_ctr)+'''" name="_'''+str(user.id)+''':see"  value='on' checked type='checkbox'> : ''')                    
              except ValueError: #not in the asset yet --> no check                   
                  request.writeln('''<td align='left'>&nbsp;&nbsp;<input id="see_check'''+str(ctr)+""+str(group_ctr)+""+str(user_ctr)+'''" name="_'''+str(user.id)+''':see"  value='on' type='checkbox'> : ''')
              
              try:
                  asset.move_by.index(user.id)
                  request.writeln('''<input id='move_check'''+str(ctr)+""+str(group_ctr)+""+str(user_ctr)+'''' name="_'''+str(user.id)+''':move" value='on' checked type='checkbox'></td></tr>''')
              except ValueError: #not in the asset yet --> no check                   
                  request.writeln('''<input id='move_check'''+str(ctr)+""+str(group_ctr)+""+str(user_ctr)+'''' name="_'''+str(user.id)+''':move" value='on' type='checkbox'></td></tr>''')
              
              user_ctr=user_ctr+1
                          
          request.writeln('''
              <tr><td>&nbsp;</td><td><input type='submit' value='Assign'></td></tr></table></form>
          </tr>''')
          ctr=ctr+1
      
      request.writeln('</table>')
      request.writeln('</center>')
      
  

    ##### Strikecom Teams #####
    request.writeln('<a name="teams"></a><h1>Game Teams:</h1>')
    # groups in this meeting
    groups = datagate.get_child_items(teams.id)
    allusers = Directory.get_users()
    allusers.sort(lambda a,b: cmp(a.username, b.username))
    request.writeln('''
      <script language='JavaScript' type='text/javascript'>
      <!--
        var old_td;
        var old_index = -1;
        var assetindex;
        
        function addTeam() {
          var text = prompt("New Team Name:");
          if (text != null && text != '') {
            text = encode(text);
            window.location.href = "''' + request.cgi_href(global_meetingid=game.id,gm_action='StrikeCom.addgroup', itemid=game.id, name=None) + '''&name=" + text + "#teams";
          }
        }
        function switchCheckBoxes(switch_id)
        {
        //Conan can be changed to work differently.  Other than just ! the boxes 
            var mode = 'move';
            if(switch_id.indexOf('see')!=-1)
            {
               mode = 'see';
            }
            
            var ctr = 0;
            var boxes = document.getElementById(switch_id+""+ctr);
            while(boxes!=null)
            {
             boxes.checked = !boxes.checked;
             
             ctr++;
             boxes = document.getElementById(switch_id+""+ctr);
            }
            
            
        }
      //-->
      </script>
      <center>
      <div align="right"><a href="javascript:addTeam()">Add New Team</a></div>
      <table border=1 cellspacing=0 cellpadding=5>
        <tr>
          <th>Team Name</th>
          <th>Users</th>    
          <th>Actions</th>
        </tr>
    ''')
    for group in groups:
      groupusers = [ Directory.get_user(child.user_id) for child in group]
      groupusers.sort(lambda a,b: cmp(a.username, b.username))
      request.writeln('<tr>')
      request.writeln('<td valign="top">' + html(group.name) + '</td>')
      request.writeln('<td>')
      request.writeln(request.cgi_form(gm_action='StrikeCom.groupusers', global_meetingid=game.id, allusers=None, groupusers=None, groupid=None))
      request.writeln('<input type="hidden" name="groupid" value="' + group.id + '">')
      request.writeln('<table border=0 cellspacing=0 cellpadding=0><tr><td>')
      request.writeln('All Users:<br>')
      request.writeln('<select size="5" name="allusers" multiple>')
      for user in allusers:
        if not user in groupusers:
          request.writeln('<option value="' + user.id + '">' + html(user.name) + '</option>')
      request.writeln('</select>')
      request.writeln('</td><td>')
      request.writeln('<p><input type="submit" value="->" name="submit"></p>')
      request.writeln('<p><input type="submit" value="<-" name="submit"></p>')
      request.writeln('</td><td>')
      request.writeln('Team Members:<br>')
      request.writeln('<select size="5" name="members" multiple>')
      for user in groupusers:
        request.writeln('<option value="' + user.id + '">' + html(user.name) + '</option>')
      request.writeln('</select>')
      request.writeln('</td></tr></table>')
      request.writeln('</form>')
      request.writeln('</td>')
      
      request.writeln('''<td valign="top"><a href="javascript:confirm_url('Delete this team and remove users from the game?', \'''' + request.cgi_href(global_meetingid=game.id, itemid=game.id, gm_action='StrikeCom.delgroup', groupid = group.id, groupname = group.name, allusers=None, groupusers=None) + '''\');">Delete</td>''')
      request.writeln('</tr>')
    request.writeln('''
      </table>
      </center>
    ''')    
    

    #####  Strikecom Playing Board #####
    kargs = {'action':'StrikeCom.boardsetup', 'gridrows':None, 'gridcols':None, 'backgroundfile':None, 'gridheight':None, 'gridwidth':None}
    for r in range(int(board.gridrows)):
      for c in range(int(board.gridcols)):
        cell = 'terrain' + str(r) + '-' + str(c)
        kargs[cell] = None
    
    request.writeln('''
      <a name="board"></a><h1>Playing Board:</h1>
      <center>
      ''' + request.cgi_multipart_form(**kargs) + '''
      <table border=0 cellspacing=10>
        <tr>
          <td>Grid:</td>
          <td><input type="text" size="5" name="gridrows" value="''' + board.gridrows + '''"> rows by <input type="text" size="5" name="gridcols" value="''' + board.gridcols + '''"> columns</td>
        </tr><tr>
          <td>Size in Pixels:</td>
          <td><input type="text" size="5" name="gridheight" value="''' + board.gridheight + '''"> pixels high by <input type="text" size="5" name="gridwidth" value="''' + board.gridwidth + '''"> pixels wide</td>
        </tr><tr>
          <td valign="top">Background Image:</td>
          <td valign="top">
     ''')
    if board.filename:
      request.writeln('''<img src="''' + request.cgi_href(view="Filer", global_rootid=board.id, gm_contenttype=board.filetype) + '''" width="90" height="90"></div>''')     
    request.writeln('''
            <div>Change Image: <input type="file" size="20" name="_backgroundfile"></div>
            <div>(note that you must have a background image to enable zooming)</div>
          </td>
        </tr>
      </table>
    ''')
    request.writeln('Terrain type for each cell:</b>')
    width = str(round(float(board.gridwidth) / float(board.gridcols)))
    height = str(round(float(board.gridheight) / float(board.gridrows)))
    if board.filename:
      request.writeln('<table border=1 cellspacing=0 cellpadding=0 background="' + request.cgi_href(view="Filer", global_rootid=board.id, gm_contenttype=board.filetype) + '">')
    else:
      request.writeln('<table border=1 cellspacing=0 cellpadding=0>')
    for r in range(int(board.gridrows)):
      request.writeln('<tr>')
      for c in range(int(board.gridcols)):
        cell = 'terrain' + str(r) + '-' + str(c)
        request.write('<td valign="top" align="left" width="' + width + '" height="' + height + '">')
        request.write('<input type="text" name="' + cell + '" size="8" value="' + board.getvalue(cell, '') + '">')
        request.writeln('</td>')
      request.writeln('</tr>')

    request.writeln('''
      </table>
    ''')
    
    request.writeln('''
      <input type="submit" value="Save Board Setup">
      </form>
      </center>
    ''')