Page 1 sur 1

Récupérer le documents sélectionné

MessagePublié: 25 Fév 2008 à 10:15
par oguruma
[syntax="javascript"]var docs = document.forms[0].$$SelectDoc;
var itemchecked = false;
var unid = "";
for (index = 0, i = interests.length; index < i; index++) {
if (docs[index].checked) {
itemchecked = true;
if (unid === "") {
unid = "&" + docs[index].value;
}
else {
unid = unid + "&" + docs[index].value;
}
}
}
if (!itemchecked) {
alert("you better have checked something");
}
else {
location.href = "/mydatabase.nsf/myagent?OpenAgent" + unid;
}[/syntax]


je pense qu'il y aura d'autres tips à venir sur ce sujet de la part du contributeur qui a lancé cette idée à travers sa réponse dans un post ;)

MessagePublié: 25 Fév 2008 à 10:24
par oguruma
quelques liens sur le sujet
http://www.tlcc.com/tlcc/tips/selview.n ... e?OpenPage

un très bon pdf à télécharger
http://brefere.com/notesnet/processselectedwebdocs.pdf

http://www-10.lotus.com/ldd/nd6forum.ns ... enDocument


n my CRM application I wanted users to use client information in other applications, where they must be able to download specific information from the database, such as e-mail addresses. Here's how I did it.

Code

Code : Tout sélectionner
Create a form with a embedded view for the web
($$ViewTemplate for &ltviewname>)
with a field called $$SelectDoc (hidden for Web)
and a field SaveOptions with value "0"
to prevent saving of the document.


On the associated view-properties under the
advanced tab 'Allow selection of documents
' has to be checked.

WebQuerySave event calls the agent.
@Command([ToolsRunMacro];
"(webGetEmailAddresses)")

What happens is that the File Download box appears.
When you select Open, a text file
opens with all e-mail addresses of the selected documents.

The trick is the lines
Print ("Content-type: application/txt");
Print ("Content-Disposition: attachment; filename=test.txt");

These send HTTP-Header information.
 
  Code: code for action on actionbar on view:
var cb = document.forms[0].$$SelectDoc;
//find the first checked document ..
var selectcount = 0;
var docUNID = new Array();
for (i = 0; i < cb.length; i++) {
     if (cb[i].checked) {
          docUNID[selectcount] = cb[i].value;
          selectcount++;
     }
}
if  (docUNID[0] == null) {
  alert('No documents selected.');
}
else{
  if (docUNID != null){
         result = window.confirm('Emailaddresses
 are exported. Select OK to confirm');
         if (result == true){
              document.forms[0].submit();
         }
  }


The submit statement triggers the WebQuerySave event.

agent (webGetEmailaAddresses):

Sub Initialize
 
Dim ses As New notessession
Dim db As notesdatabase
Dim doc, newDoc As notesdocument
Dim item As notesitem
 
Dim dateTime As New 
Set db=ses.currentdatabase
Set doc = ses.DocumentContext
Set item = doc.getFirstItem("$$SelectDoc")
 
Print ("Content-type: application/txt");
 Print ("Content-Disposition: attachment; filename=test.txt");
 
'for every value $$SelectDoc
 get the notes-document Forall v In
item.Values Set newDoc =
db.GetDocumentByUNID(v)
'send the emailadress to the
 browser Print  newDoc.Email(0) & Chr(13)
End Forall
End Sub


====================================

_________________
_________________
$$ViewTemplate:
_________________

Paste the functions needed for actions in the JSHeader:
(these are named the same as the Lotus ones just with the form names updated)
function _SelectMarkForDelete(){
  var form = document.ApDocs;
  for (var i = 0; i < form.elements.length; i++) {
    if (form.elements[i].type == "checkbox") {
      if (form.elements[i].name == "$$SelectDoc") {
        if (form.elements[i].checked) {
          var theImg = eval("document._SelectImg" + form.elements[i].value);
          if (theImg.src.indexOf("httrash.gif") != -1)
            theImg.src = "/icons/ecblank.gif";
          else
            theImg.src = "/icons/httrash.gif";
          form.elements[i].checked = false;
        }
      }
    }
  }
}

function _SelectDelete(){
  var form = document.ApDocs;
  for (var i = 0; i < form.elements.length; i++) {
    if (form.elements[i].type == "checkbox") {
      if (form.elements[i].name == "$$SelectDoc") {
        var theImg = eval("document._SelectImg" + form.elements[i].value);
        if (theImg == null)
          continue;
        if (theImg.src.indexOf("httrash.gif") != -1) {
          form.elements[i].checked = true;
          theImg.src = "/icons/ecblank.gif";
         }
         else {
          form.elements[i].checked = false;
         }
      }
    }
  }
}

function _SelectAllDocs(select){
  var form = document.ApDocs;
  for (var i = 0; i < form.elements.length; i++) {
    if (form.elements[i].type == "checkbox") {
      if (form.elements[i].name == "$$SelectDoc") {
        form.elements[i].checked = select;
      }
    }
  }
}

_________________

Above the embedded view, add this code to end the default form and start our custom one:
</form><ends>
<form>

_________________

Next add these actions (chose Javascript type) with the following code:

Select All:
_SelectAllDocs(true); return false;

Deselect All:
_SelectAllDocs(false); return false;

Approve:
var frm = document.ApDocs;
frm.submit();

At the bottom of the template form, end the custom form we've begun:
(Note: This may not be needed, look at your view source to see if Domino inserts one automatically for you.)
</form>

_________________
_________________
View Embedded in View Template:
_________________

Add a collumn with the following formula:
"[<INPUT>]"


_________________
_________________
Temporary Form:
_________________

- Name form to match post name in view hack code above
add SaveOptions field (CWC) with value "0" to prevent doc from saving
add DBPath field (CFD) with formula:
db:=@Subset(@DbName; -1);
@ReplaceSubstring(@ReplaceSubstring(db; "\\"; "/"); " "; "+");
add webquerysave event agent call.

_________________
_________________
Agent to Process Selected Docs:
_________________

- Name agent name in webquerysave of temporary form above

Sub Initialize
   ' this agent processes the list of documents selected in the WebOrdersPending view.
   ' the view has a hacked form that loads a dummy doc "ApprTmp", that then calls this agent via the webquerysave
   Dim session As New NotesSession
   Dim db As NotesDatabase                  ' this db
   Dim view As NotesView                     ' the approver pending view - needed only to do a view refresh         
   Dim tmpDoc As NotesDocument            ' current tmpdoc ApprTmp
   Dim doc As NotesDocument
   Dim item As NotesItem
   Dim value As String
   
   On Error Goto ErrorHandler
   
   On Error 4091 Goto ErrorHandler4091
   
   Set db = session.CurrentDatabase
   Set view = db.GetView("WebOrdersPending")
   Set tmpDoc = session.DocumentContext
   Set item  = tmpDoc.GetFirstItem("$$SelectDoc")
   
   ' update the docs
   Forall v In item.Values
      Set doc = db.GetDocumentByUNID( v )
      If Not (doc Is Nothing) Then
         doc.Status = value
         Call doc.Save( True, True)
      End If
   End Forall
   Call view.Refresh
   Print "[" & tmpDoc.DbPath(0) & "/WebOrdersPending!OpenView]"
   Exit Sub
   
ErrorHandler:
   Print "<br>" &  "Info: " & Str(Err) & ": " & Error$ & " on line: " & Cstr(Erl)
   Exit Sub
ErrorHandler4091:
   Print "[" & tmpDoc.DbPath(0) & "/WebOrdersPending!OpenView]"
   Exit Sub
End Sub


==========================


http://www.integra4notes.com/faq/pages/0130


==========================