CMS  Version 3.9
document_file_view.inc
Go to the documentation of this file.
1 <?php
7 Fakoli::using("document");
8 
10 {
11  var $id;
12  var $library;
13 
14  function __construct($library, $id = "documents")
15  {
16  $this->id = $id;
17  $this->library = $library;
18  }
19 
20  function writeScript()
21  {
22  ob_start();
23  ?>
24  <script type="text/javascript">
25  function editFile(id)
26  {
27  modalPopup("Edit Document Properties", "/action/document/edit?document_id=" + id, 900, 'auto');
28  }
29 
30  function addFile()
31  {
32  modalPopup("Add a New Document", "/action/document/upload?document_library_id=<?echo $this->library->document_library_id?>", 900, 'auto');
33  }
34 
35  function editResult(result)
36  {
37  if (result == "1")
38  {
39  window.location.reload();
40  }
41  else
42  {
43  document.id('Document_form__error').set({'text': result, 'display': 'table-cell'});
44  }
45  }
46 
47  function uploadResult(result)
48  {
49  if (result == "1")
50  {
51  window.location.reload();
52  }
53  else
54  {
55  document.id('Document_form__error').set({'text': result, 'display': 'table-cell'});
56  }
57  }
58 
59  function moveDocuments(document_library_id)
60  {
61  var table = document.id(<?php echo $this->id?>);
62  var document_ids = [];
63  table.getElements("input[type=checkbox]:checked").each(function(cbox)
64  {
65  document_ids.push(cbox.value);
66  });
67 
68  document_ids = document_ids.join(",");
69  modalPopup("Move Documents", "/action/document/move_documents?document_library_id=" + document_library_id + "&document_ids=" + document_ids, "700px", "auto", true);
70  }
71 
72  function moveDocumentsResponse(response)
73  {
74  if (response == "OK")
75  {
76  window.location.reload();
77  }
78  else
79  {
80  notification(response);
81  }
82  }
83 
84  function deleteDocuments(document_library_id)
85  {
86  if (confirm("Are you sure you want to delete the selected documents?\nThis operation cannot be undone."))
87  {
88  var table = document.id(<?php echo $this->id?>);
89  var document_ids = [];
90  table.getElements("input[type=checkbox]:checked").each(function(cbox)
91  {
92  document_ids.push(cbox.value);
93  });
94 
95  document_ids = document_ids.join(",");
96  go("/action/document/delete_documents?document_library_id=" + document_library_id + "&document_ids=" + document_ids);
97  }
98  }
99 
100  </script>
101  <?
102  $script = ob_get_contents();
103  ob_end_clean();
104 
105  return $script;
106  }
107 
108  function drawView()
109  {
110  global $script;
111 
112  $documents = $this->library->Documents("ORDER BY title DESC");
113 
114  $table = new DataListView($documents, $this->id);
115  $table->selector();
116  $table->column("ID", "{document_id}", true);
117  $table->column("Title", "<b><a href='#' onclick='editFile({document_id});return false'>{title}</b></a>", true, "width: 40%")
118  ->column("Author", "{author}", true, "width: 35%")
119  ->column("Last Modified", "{last_modified}", true, "width: 25%;text-align: center");
120 
121  $table->filter = true;
122  $table->sortable = true;
123  $table->pageSize = 20;
124  $table->excelFile = "documents";
125  $table->emptyMessage = "No Documents have been added yet.";
126 
127 
128  $table->showSelectAll = true;
129  $contextMenu = $table->commandMenu();
130  $contextMenu->command("move_documents", "Move Documents...", "moveDocuments({$this->library->document_library_id})", false);
131  $contextMenu->command("delete_documents", "Delete Documents", "deleteDocuments({$this->library->document_library_id})", false);
132 
133  $script .= $this->writeScript();
134  $script .= $table->writeScript();
135  $table->drawView();
136 ?>
137  <br/>
138  <br/>
139  <a href="#" class="button" onclick="addFile(); return false"> Add a New Document </a>
140  <a href='#' class='button' onclick='moveDocuments(); return false'> Move Documents... </a>
141  <a href='#' class='button' onclick='deleteDocuments(); return false'> Delete Documents </a>
142  <br/>
143 <?
144  }
145 }?>
__construct($library, $id="documents")
This class maps the publication table.
Definition: document.inc:43
static using()
Import the datamodels, views and manifest for the specified component(s).
Definition: core.inc:116
$documents