[gen] Ajaxified query result and tied object rows.
This commit is contained in:
		
							parent
							
								
									1bd6cf29a3
								
							
						
					
					
						commit
						45192ca4bc
					
				
					 7 changed files with 142 additions and 71 deletions
				
			
		| 
						 | 
				
			
			@ -701,7 +701,7 @@ class BaseMixin:
 | 
			
		|||
 | 
			
		||||
    def getFieldValue(self, name, layoutType=None, outerValue=None):
 | 
			
		||||
        '''Returns the database value of field named p_name for p_self.'''
 | 
			
		||||
        if layoutType == 'search': return # No object in search screens.
 | 
			
		||||
        if layoutType == 'search': return # No object in search screens
 | 
			
		||||
        field = self.getAppyType(name)
 | 
			
		||||
        if field.type == 'Pod': return
 | 
			
		||||
        if '*' not in name: return field.getValue(self)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -136,14 +136,13 @@ function getAjaxChunk(pos) {
 | 
			
		|||
    if (xhrObjects[pos].xhr.readyState == 4) {
 | 
			
		||||
      // We have received the HTML chunk
 | 
			
		||||
      var hookElem = getAjaxHook(hook);
 | 
			
		||||
      var responseOk = (xhrObjects[pos].xhr.status == 200);
 | 
			
		||||
      if (hookElem && responseOk) {
 | 
			
		||||
      if (hookElem) {
 | 
			
		||||
        injectChunk(hookElem, xhrObjects[pos].xhr.responseText);
 | 
			
		||||
        // Call a custom Javascript function if required
 | 
			
		||||
        if (xhrObjects[pos].onGet) {
 | 
			
		||||
          xhrObjects[pos].onGet(xhrObjects[pos], hookElem);
 | 
			
		||||
        }
 | 
			
		||||
        // Eval inner scripts if any.
 | 
			
		||||
        // Eval inner scripts if any
 | 
			
		||||
        var innerScripts = getElementsHavingName('div', 'appyHook');
 | 
			
		||||
        for (var i=0; i<innerScripts.length; i++) {
 | 
			
		||||
          eval(innerScripts[i].innerHTML);
 | 
			
		||||
| 
						 | 
				
			
			@ -152,7 +151,7 @@ function getAjaxChunk(pos) {
 | 
			
		|||
        var msg = xhrObjects[pos].xhr.getResponseHeader('Appy-Message');
 | 
			
		||||
        if (msg) showAppyMessage(decodeURIComponent(escape(msg)));
 | 
			
		||||
      }
 | 
			
		||||
      if (responseOk) xhrObjects[pos].freed = 1;
 | 
			
		||||
      xhrObjects[pos].freed = 1;
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -308,7 +307,7 @@ function askRefField(hookId, objectUrl, innerRef, startNumber, action,
 | 
			
		|||
                     actionParams){
 | 
			
		||||
  var hookElems = hookId.split('_');
 | 
			
		||||
  var fieldName = hookElems[1];
 | 
			
		||||
  // Sends an Ajax request for getting the content of a reference field.
 | 
			
		||||
  // Sends an Ajax request for getting the content of a reference field
 | 
			
		||||
  var startKey = hookId + '_startNumber';
 | 
			
		||||
  var scope = hookElems.pop();
 | 
			
		||||
  var params = {'innerRef': innerRef, 'scope': scope};
 | 
			
		||||
| 
						 | 
				
			
			@ -631,12 +630,10 @@ function submitAppyForm(button) {
 | 
			
		|||
  theForm.submit();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Function used for triggering a workflow transition
 | 
			
		||||
function triggerTransition(formId, transitionId, msg, back) {
 | 
			
		||||
function submitForm(formId, msg, showComment, back) {
 | 
			
		||||
  var f = document.getElementById(formId);
 | 
			
		||||
  f.transition.value = transitionId;
 | 
			
		||||
  if (!msg) {
 | 
			
		||||
    /* We must submit the form and either refresh the entire page (back is null)
 | 
			
		||||
    /* Submit the form and either refresh the entire page (back is null)
 | 
			
		||||
       or ajax-refresh a given part only (p_back corresponds to the id of the
 | 
			
		||||
       DOM node to be refreshed. */
 | 
			
		||||
    if (back) askAjax(back, formId);
 | 
			
		||||
| 
						 | 
				
			
			@ -646,11 +643,18 @@ function triggerTransition(formId, transitionId, msg, back) {
 | 
			
		|||
    // Ask a confirmation to the user before proceeding
 | 
			
		||||
    if (back) {
 | 
			
		||||
      var js = "askAjax('"+back+"', '"+formId+"');"
 | 
			
		||||
      askConfirm('script', js, msg, true) }
 | 
			
		||||
    else askConfirm('form', formId, msg, true);
 | 
			
		||||
      askConfirm('script', js, msg, showComment) }
 | 
			
		||||
    else askConfirm('form', formId, msg, showComment);
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Function used for triggering a workflow transition
 | 
			
		||||
function triggerTransition(formId, transitionId, msg, back) {
 | 
			
		||||
  var f = document.getElementById(formId);
 | 
			
		||||
  f.transition.value = transitionId;
 | 
			
		||||
  submitForm(formId, msg, true, back);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function onDeleteObject(objectUid) {
 | 
			
		||||
  f = document.getElementById('deleteForm');
 | 
			
		||||
  f.objectUid.value = objectUid;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -374,9 +374,10 @@ class AbstractWrapper(object):
 | 
			
		|||
 | 
			
		||||
    pxTransitions = Px('''
 | 
			
		||||
     <form var="transitions=targetObj.getTransitions()" if="transitions"
 | 
			
		||||
           var2="formId='trigger_%s' % targetObj.id" method="post"
 | 
			
		||||
           var2="formId='trigger_%s' % targetObj.id;
 | 
			
		||||
                 zobj=targetObj"
 | 
			
		||||
           id=":formId" action=":targetObj.absolute_url() + '/onTrigger'"
 | 
			
		||||
           style="display: inline">
 | 
			
		||||
           style="display: inline" method="post">
 | 
			
		||||
      <input type="hidden" name="transition"/>
 | 
			
		||||
      <!-- Input field for storing the comment coming from the popup -->
 | 
			
		||||
      <textarea id="comment" name="comment" cols="30" rows="3"
 | 
			
		||||
| 
						 | 
				
			
			@ -575,6 +576,53 @@ class AbstractWrapper(object):
 | 
			
		|||
      </table>
 | 
			
		||||
     </form>''')
 | 
			
		||||
 | 
			
		||||
    # The object, as shown in a list of referred (tied) objects
 | 
			
		||||
    pxViewAsTied = Px('''
 | 
			
		||||
     <tr valign="top" class=":rowCss"
 | 
			
		||||
         var2="tiedUid=tied.o.id;
 | 
			
		||||
               objectIndex=field.getIndexOf(zobj, tiedUid)|None;
 | 
			
		||||
               mayView=tied.o.mayView()"
 | 
			
		||||
         id=":tiedUid">
 | 
			
		||||
      <td if="not inPickList and numbered">:field.pxNumber</td>
 | 
			
		||||
      <td if="checkboxes" class="cbCell">
 | 
			
		||||
       <input if="mayView" type="checkbox" name=":ajaxHookId" checked="checked"
 | 
			
		||||
              value=":tiedUid" onclick="toggleCb(this)"/>
 | 
			
		||||
      </td>
 | 
			
		||||
      <td for="column in columns" width=":column.width" align=":column.align"
 | 
			
		||||
          var2="refField=column.field">:refField.pxRenderAsTied</td>
 | 
			
		||||
      <!-- Store data in this tr node allowing to ajax-refresh it -->
 | 
			
		||||
      <script>:field.getAjaxDataRow(tied, ajaxHookId, rowCss=rowCss, \
 | 
			
		||||
               currentNumber=currentNumber)</script>
 | 
			
		||||
     </tr>''')
 | 
			
		||||
 | 
			
		||||
    # When calling pxViewAsTied from Ajax, this surrounding PX is called to
 | 
			
		||||
    # define the appropriate variables based on request values.
 | 
			
		||||
    pxViewAsTiedFromAjax = Px('''
 | 
			
		||||
     <x var="dummy=ztool.updatePxContextFromRequest();
 | 
			
		||||
             tied=obj;
 | 
			
		||||
             zobj=ztool.getObject(sourceId);
 | 
			
		||||
             obj=zobj.appy();
 | 
			
		||||
             field=zobj.getAppyType(refFieldName);
 | 
			
		||||
             layoutType='view';
 | 
			
		||||
             render=field.getRenderMode(layoutType);
 | 
			
		||||
             linkList=field.link == 'list';
 | 
			
		||||
             numberWidth=len(str(totalNumber));
 | 
			
		||||
             tiedClassName=ztool.getPortalType(field.klass);
 | 
			
		||||
             target=ztool.getLinksTargetInfo(field.klass);
 | 
			
		||||
             mayEdit=not field.isBack and zobj.mayEdit(field.writePermission);
 | 
			
		||||
             mayLink=not inPickList and mayEdit and \
 | 
			
		||||
                     field.mayAdd(zobj, mode='link', checkMayEdit=False);
 | 
			
		||||
             mayUnlink=not inPickList and mayEdit and \
 | 
			
		||||
                       field.getAttribute(zobj, 'unlink');
 | 
			
		||||
             gotoNumber=numbered;
 | 
			
		||||
             changeOrder=not inPickList and mayEdit and \
 | 
			
		||||
                         field.getAttribute(zobj, 'changeOrder');
 | 
			
		||||
             changeNumber=not inPickList and numbered and changeOrder and \
 | 
			
		||||
                          (totalNumber > 3);
 | 
			
		||||
             columns=ztool.getColumnsSpecifiers(tiedClassName, \
 | 
			
		||||
                   field.getAttribute(obj, 'shownInfo'), dir);
 | 
			
		||||
             showSubTitles=showSubTitles|True">:obj.pxViewAsTied</x>''')
 | 
			
		||||
 | 
			
		||||
    # The object, as shown in a list of query results
 | 
			
		||||
    pxViewAsResult = Px('''
 | 
			
		||||
     <tr var2="obj=zobj.appy(); mayView=zobj.mayView();
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue