2 * FusionForge Documentation Manager
4 * Copyright 2010, Antoine Mercadal - Capgemini
5 * Copyright 2010-2011, Franck Villaume - Capgemini
6 * Copyright 2011-2012, Franck Villaume - TrivialDev
7 * Copyright 2011, Alain Peyrat
8 * http://fusionforge.org
10 * This file is part of FusionForge. FusionForge is free software;
11 * you can redistribute it and/or modify it under the terms of the
12 * GNU General Public License as published by the Free Software
13 * Foundation; either version 2 of the Licence, or (at your option)
16 * FusionForge is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License along
22 * with FusionForge; if not, write to the Free Software Foundation, Inc.,
23 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 /*! ListFileController
27 * @param groupId the current FusionForge groupID
29 DocManListFileController = function(params)
31 this.lockInterval = [];
36 this.initModalEditWindow();
39 DocManAddItemController = function(params)
45 DocManListFileController.prototype =
47 /*! Binds the controls to the actions
49 bindControls: function() {
50 if (typeof(this.params.buttonEditDirectory) != 'undefined') {
51 this.params.buttonEditDirectory.click(jQuery.proxy(this, "toggleEditDirectoryView"));
53 if (typeof(this.params.buttonAddItem) != 'undefined') {
54 this.params.buttonAddItem.click(jQuery.proxy(this, "toggleAddItemView"));
58 resizableDiv: function() {
59 if (typeof(this.params.divHandle) != 'undefined') {
60 this.params.divHandle.mousedown(jQuery.proxy(this, "dragging"));
61 var params = this.params;
62 var w = jQuery('#maindiv').width() - this.params.divHandle.width() - 10;
63 jQuery(document).mouseup(function(){isDragging = false;}).mousemove(function(e){
64 if (typeof(isDragging) != 'undefined') {
66 params.divLeft.css('width', e.pageX);
67 params.divRight.css('width', w - e.pageX);
68 jQuery.Storage.set("treesize",""+params.divLeft.width());
75 initSize: function() {
76 if (typeof(this.params.divLeft) != 'undefined' && typeof(this.params.divRight) != 'undefined') {
77 if (this.params.divLeft.height() > this.params.divRight.height()) {
78 this.params.divHandle.css('height', this.params.divLeft.height());
80 this.params.divHandle.css('height', this.params.divRight.height());
82 if (jQuery.Storage.get("treesize") != 0) {
83 this.params.divLeft.css('width', parseInt(jQuery.Storage.get("treesize")));
84 var w = jQuery('#maindiv').width() - this.params.divHandle.width() - 10;
85 this.params.divRight.css('width', w - this.params.divLeft.width());
90 initModalEditWindow: function() {
91 var modalId = this.params.divEditFile;
92 jQuery(modalId).dialog({
97 title: this.params.divEditTitle,
99 Save: jQuery.proxy(function() {
100 jQuery('#editdocdata').submit();
101 var id = jQuery('#docid').attr('value');
102 jQuery.get(this.params.docManURL, {
103 group_id: this.params.groupId,
107 childgroup_id: this.params.childGroupId
109 clearInterval(this.lockInterval[id]);
110 jQuery(modalId).dialog( "close" );
112 Cancel: jQuery.proxy(function() {
113 var id = jQuery('#docid').attr('value');
114 jQuery.get(this.params.docManURL, {
115 group_id: this.params.groupId,
119 childgroup_id: this.params.childGroupId
121 clearInterval(this.lockInterval[id]);
122 jQuery(modalId).dialog( "close" );
128 dragging: function() {
132 /*! toggle edit group view div visibility
134 toggleEditDirectoryView: function() {
135 if (!this.params.divEditDirectory.is(":visible")) {
136 this.params.divEditDirectory.show();
137 if (typeof(this.params.divAddItem) != 'undefined') {
138 this.params.divAddItem.hide();
141 this.params.divEditDirectory.hide();
143 if (typeof(this.params.divLeft) != 'undefined' && typeof(this.params.divRight) != 'undefined') {
144 if (this.params.divLeft.height() > this.params.divRight.height()) {
145 this.params.divHandle.css('height', this.params.divLeft.height());
147 this.params.divHandle.css('height', this.params.divRight.height());
153 /*! toggle add item view div visibility
155 toggleAddItemView: function() {
156 if (!this.params.divAddItem.is(":visible")) {
157 this.params.divAddItem.show();
158 this.params.divEditDirectory.hide();
160 this.params.divAddItem.hide();
162 if (typeof(this.params.divLeft) != 'undefined' && typeof(this.params.divRight) != 'undefined') {
163 if (this.params.divLeft.height() > this.params.divRight.height()) {
164 this.params.divHandle.css('height', this.params.divLeft.height());
166 this.params.divHandle.css('height', this.params.divRight.height());
172 /*! toggle add file edit view div visibility and play with lock
174 * @param id the docid
176 toggleEditFileView: function(docparams) {
177 this.docparams = docparams;
178 jQuery('#title').attr('value', this.docparams.title);
179 jQuery('#description').attr('value', this.docparams.description);
180 jQuery('#docid').attr('value', this.docparams.id);
181 if (this.docparams.isURL) {
182 jQuery('#uploadnewroweditfile').hide();
183 jQuery('#fileurlroweditfile').show();
185 jQuery('#fileurlroweditfile').hide();
186 jQuery('#uploadnewroweditfile').show();
188 if (!this.docparams.useCreateOnline || !this.docparams.isText) {
189 jQuery('#editonlineroweditfile').hide();
190 jQuery('#editor').attr('disabled', true);
192 jQuery('#filelink').text(this.docparams.filename);
193 if (this.docparams.statusId != 2) {
194 if (this.docparams.isURL) {
195 jQuery('#filelink').attr('href', this.docparams.filename);
197 jQuery('#filelink').attr('href', this.docparams.docManURL + '/view.php/' + this.docparams.groupId + '/' + this.docparams.id + '/' + this.docparams.filename);
200 jQuery('#doc_group').empty();
201 jQuery.each(this.docparams.docgroupDict, function(key, value) {
202 jQuery('#doc_group').append(jQuery("<option>").text(key).attr("value",value));
204 jQuery('#doc_group option[value='+this.docparams.docgroupId+']').attr("selected", "selected");
205 jQuery('#stateid').empty();
206 jQuery.each(this.docparams.statusDict, function(key, value) {
207 jQuery('#stateid').append(jQuery("<option>").text(key).attr("value",value));
209 jQuery('#stateid option[value='+this.docparams.statusId+']').attr("selected", "selected");
210 if (this.docparams.isText) {
211 jQuery.getJSON(this.docparams.docManURL + '/?group_id=' + this.docparams.groupId + '&action=getfile&fileid=' + this.docparams.id , jQuery.proxy(function(data){
212 jQuery('#defaulteditzone').text(data.body);
215 jQuery('#editdocdata').attr('action', this.docparams.action);
217 jQuery.get(this.docparams.docManURL, {
218 group_id: this.docparams.groupId,
221 fileid: this.docparams.id,
222 childgroup_id: this.docparams.childGroupId
224 this.lockInterval[this.docparams.id] = setInterval("jQuery.get('" + this.docparams.docManURL + "', {group_id:"+this.docparams.groupId+",action:'lockfile',lock:1,fileid:"+this.docparams.id+",childgroup_id:"+this.docparams.childGroupId+"})",this.docparams.lockIntervalDelay);
225 jQuery(this.params.divEditFile).dialog("open");
230 /*! build list of id, comma separated
232 buildUrlByCheckbox: function(id) {
233 var CheckedBoxes = new Array();
234 for (var h = 0; h < jQuery("input:checked").length; h++) {
235 if (typeof(jQuery("input:checked")[h].className) != "undefined" && jQuery("input:checked")[h].className.match('checkeddocid'+id)) {
236 CheckedBoxes.push(jQuery("input:checked")[h].value);
242 checkAll: function(id, type) {
243 if (jQuery('#checkall'+type).is(':checked')) {
244 jQuery('.'+id).each(function() {
245 jQuery(this).attr('checked', true);
247 jQuery('#massaction'+type).show();
249 jQuery('.'+id).each(function() {
250 jQuery(this).attr('checked', false);
252 jQuery('#massaction'+type).hide();
256 checkgeneral: function(id) {
257 if (jQuery(this).attr('checked', false)) {
258 jQuery('#checkall'+id).attr('checked', false);
259 jQuery('#massaction'+id).hide();
261 for (var h = 0; h < jQuery("input:checked").length; h++) {
262 console.log("%s", jQuery("input:checked")[h].className);
263 if (typeof(jQuery("input:checked")[h].className) != "undefined" && jQuery("input:checked")[h].className.match('checkeddocid'+id)) {
264 jQuery('#massaction'+id).show();
270 DocManAddItemController.prototype =
272 /*! Binds the controls to the actions
274 bindControls: function() {
275 this.params.buttonDoc.click(jQuery.proxy(this, "toggleAddFileView"));
276 this.params.buttonDir.click(jQuery.proxy(this, "toggleAddDirectoryView"));
277 this.params.buttonZip.click(jQuery.proxy(this, "toggleInjectZipView"));
280 toggleAddDirectoryView: function() {
281 if (!this.params.divCreateDir.is(":visible")) {
282 this.params.divCreateDir.show();
283 this.params.divCreateDoc.hide();
284 this.params.divZipInject.hide();
286 this.params.divCreateDoc.hide();
287 this.params.divZipInject.hide();
289 if (typeof(jQuery('#left')) != 'undefined' && typeof(jQuery('#right')) != 'undefined') {
290 if (jQuery('#left').height() > jQuery('#right').height()) {
291 jQuery('#handle').css('height', jQuery('#left').height());
293 jQuery('#handle').css('height', jQuery('#right').height());
298 toggleInjectZipView: function() {
299 if (!this.params.divZipInject.is(":visible")) {
300 this.params.divZipInject.show();
301 this.params.divCreateDir.hide();
302 this.params.divCreateDoc.hide();
304 this.params.divCreateDir.hide();
305 this.params.divCreateDoc.hide();
307 if (typeof(jQuery('#left')) != 'undefined' && typeof(jQuery('#right')) != 'undefined') {
308 if (jQuery('#left').height() > jQuery('#right').height()) {
309 jQuery('#handle').css('height', jQuery('#left').height());
311 jQuery('#handle').css('height', jQuery('#right').height());
316 toggleAddFileView: function() {
317 if (!this.params.divCreateDoc.is(":visible")) {
318 this.params.divCreateDoc.show();
319 this.params.divCreateDir.hide();
320 this.params.divZipInject.hide();
322 this.params.divCreateDir.hide();
323 this.params.divZipInject.hide();
325 if (typeof(jQuery('#left')) != 'undefined' && typeof(jQuery('#right')) != 'undefined') {
326 if (jQuery('#left').height() > jQuery('#right').height()) {
327 jQuery('#handle').css('height', jQuery('#left').height());
329 jQuery('#handle').css('height', jQuery('#right').height());