2005-11-25

Notes - Lotus Script: Replace Substring

Function ReplaceSubstring(sourcestr As String, fromstr As String, tostr As String) As String
   ' This function replaces characters in a string. Take all the occurrences of "fromstr"
   ' in the source string and replace them with "tostr"
   Dim tempstr As String
   Dim convstr As String
   Dim i As Long
   Dim length As Long
   tempstr = sourcestr
   If Len(fromstr) = 0 Then
      ReplaceSubstring = sourcestr
      Exit Function
   End If
   If Instr(tostr, fromstr) <> 0 Then ' If, for example, "\" is being replaced with "\\"
      ' Find a character (or set) that is not in the source string.
      ' Try the extended characters (over 128 ASCII)
      i = 128
      length = 1
      convstr = ""
      While convstr = ""
         If Instr(tempstr, String$(length, Chr$(i))) = 0 Then convstr = String$(length, Chr$(i))
         i = i + 1
         If i = 256 Then ' If all the extended characters were in there
            length = length + 1 ' Start over, but try 2 extended characters (or 3 or 4)
            i = 128
         End If
      Wend
      ' Go through tempstr twice - once replacing fromstr with the computed
      ' string, then replacing the computed string with tostr
      While Instr(tempstr, fromstr) <> 0
         tempstr = Left(tempstr, Instr(tempstr, fromstr)-1) & convstr _
         & Mid(tempstr, Instr(tempstr, fromstr)+Len(fromstr))
      Wend
      While Instr(tempstr, convstr) <> 0
         tempstr = Left(tempstr, Instr(tempstr, convstr)-1) & tostr _
         & Mid(tempstr, Instr(tempstr, convstr)+Len(convstr))
      Wend
   Else ' It's a normal replace substring call - fromstr is not part of tostr
      While Instr(tempstr, fromstr) <> 0
         tempstr = Left(tempstr, Instr(tempstr, fromstr)-1) & tostr _
         & Mid(tempstr, Instr(tempstr, fromstr)+Len(fromstr))
      Wend
   End If
   ReplaceSubstring = tempstr
End Function

2005-11-14

Notes - Web: bypassing the $$Return field

To avoid the processing of the $$Return field, save the document with the command:
@Command([FileSave])

If using Javascript then instead of using document.forms[0].submit(), create a button with the above formula and give it an id (ex:bt_save) and then on the submit script do:
 
document.all.bt_save.click()

 


The url of the document will be the original one (http://server_name//database_name/form_name?OpenForm), with "&Seq=1" (2,3,...) appended in the end.

2005-11-11

Notes - Web: simulate notes client continue=false behaviour on web save

Form:
(Server_Name e Path_Info are CGI fields)


. field SaveOptions=0
. field $$Return= "[http://" + Server_Name + @Left(Path_Info;"nsf") + "nsf/0/"+ @Text(@DocumentUniqueID) + "?OpenDocument]"



WebQuerySaveAgent:
(if the validation fails, then the doc will not be saved because of the SaveOptions field value)

if (validateForm) doc.SaveOptions=1



Form - onload:
(optionally)
if (document.all.field_error.value!="") alert("Document not saved. \n Errors:" + document.all.field_error.value)


2005-11-10

Web - Js: generic form validation function

function isSomethingSelected( obj ){
    for (var r=0; r < obj.length; r++){
     if ( obj[r].checked ) return true;
  }
}

/*--- form validation--- */
function checkRequiredField(sFname)
  {
   field = self.document.getElementById(sFname);
   sType = field.type.toLowerCase();
   var bOk = true;

   switch (sType)
   {
    case "text":
    case "textarea" :
     if (field.value=="") bOk=false;
     break;
    case "checkbox":
    case "radio":
     if ( !field[0]) { //handle single item group first
      if ( !field.checked ) bOk=false;
     }
     else
     {
      if (!isSomethingSelected(field)) bOk=false;
     }
     break;
    case "select-one":
     if (field.selectedIndex == 0) bOk= false;
     break;
    case "select-multiple":
     if (field.selectedIndex == -1) bOk=false;
     break;
    default:
     break;
   }
  return bOk;
}

2005-11-09

Web - Js: including javascript stored in a separate file

<script type="text/javascript" src="/file_path/file_name.js"></script>

Web - CSS: including style sheets stored in a separate file

<link="stylesheet" type="text/css" media="print" href="/file_path/file_name.css"/>

<style type="text/css" media="screen">@import "/path_file/path_name.css"; </style>

DOM: window.open

Gecko DOM Reference

Syntax
WindowObjectReference = window.open(strUrl, strWindowName [, strWindowFeatures]);

Web - CSS: how to make a "fake" link

.linkClass
{

text-decoration : underline;
cursor : hand;
}

Notes - Web: document link in html view

"<a href=\"0/" +@Text(@DocumentUniqueID)+"\">" + field_name + “</a>”