2012-02-28 22:02:02 +00:00
|
|
|
/**
|
|
|
|
* ownCloud
|
|
|
|
*
|
|
|
|
* @author Bartek Przybylski
|
2012-03-24 17:35:16 +00:00
|
|
|
* @copyright 2012 Bartek Przybylski bartek@alefzero.eu
|
2012-02-28 22:02:02 +00:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 3 of the License, or any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public
|
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2012-05-05 11:48:12 +00:00
|
|
|
* this class to ease the usage of jquery dialogs
|
2012-02-28 22:02:02 +00:00
|
|
|
*/
|
2012-09-05 20:22:04 +00:00
|
|
|
var OCdialogs = {
|
2012-05-05 11:48:12 +00:00
|
|
|
/**
|
|
|
|
* displays alert dialog
|
|
|
|
* @param text content of dialog
|
|
|
|
* @param title dialog title
|
|
|
|
* @param callback which will be triggered when user press OK
|
|
|
|
*/
|
|
|
|
alert:function(text, title, callback, modal) {
|
|
|
|
var content = '<p><span class="ui-icon ui-icon-alert"></span>'+text+'</p>';
|
|
|
|
OCdialogs.message(content, title, OCdialogs.ALERT_DIALOG, OCdialogs.OK_BUTTON, callback, modal);
|
|
|
|
},
|
|
|
|
/**
|
|
|
|
* displays info dialog
|
|
|
|
* @param text content of dialog
|
|
|
|
* @param title dialog title
|
|
|
|
* @param callback which will be triggered when user press OK
|
|
|
|
*/
|
|
|
|
info:function(text, title, callback, modal) {
|
|
|
|
var content = '<p><span class="ui-icon ui-icon-info"></span>'+text+'</p>';
|
|
|
|
OCdialogs.message(content, title, OCdialogs.ALERT_DIALOG, OCdialogs.OK_BUTTON, callback, modal);
|
|
|
|
},
|
|
|
|
/**
|
|
|
|
* displays confirmation dialog
|
|
|
|
* @param text content of dialog
|
|
|
|
* @param title dialog title
|
|
|
|
* @param callback which will be triggered when user press YES or NO (true or false would be passed to callback respectively)
|
|
|
|
*/
|
|
|
|
confirm:function(text, title, callback, modal) {
|
|
|
|
var content = '<p><span class="ui-icon ui-icon-notice"></span>'+text+'</p>';
|
|
|
|
OCdialogs.message(content, title, OCdialogs.ALERT_DIALOG, OCdialogs.YES_NO_BUTTONS, callback, modal);
|
|
|
|
},
|
|
|
|
/**
|
|
|
|
* prompt for user input
|
|
|
|
* @param text content of dialog
|
|
|
|
* @param title dialog title
|
|
|
|
* @param callback which will be triggered when user press OK (input text will be passed to callback)
|
|
|
|
*/
|
|
|
|
prompt:function(text, title, default_value, callback, modal) {
|
|
|
|
var content = '<p><span class="ui-icon ui-icon-pencil"></span>'+text+':<br/><input type="text" id="oc-dialog-prompt-input" value="'+default_value+'" style="width:90%"></p>';
|
|
|
|
OCdialogs.message(content, title, OCdialogs.PROMPT_DIALOG, OCdialogs.OK_CANCEL_BUTTONS, callback, modal);
|
|
|
|
},
|
|
|
|
/**
|
|
|
|
* prompt user for input with custom form
|
|
|
|
* fields should be passed in following format: [{text:'prompt text', name:'return name', type:'input type', value: 'dafault value'},...]
|
2012-10-31 08:42:26 +00:00
|
|
|
* select example var fields=[{text:'Test', name:'test', type:'select', options:[{text:'hallo',value:1},{text:'hallo1',value:2}] }];
|
2012-05-05 11:48:12 +00:00
|
|
|
* @param fields to display
|
|
|
|
* @param title dialog title
|
|
|
|
* @param callback which will be triggered when user press OK (user answers will be passed to callback in following format: [{name:'return name', value: 'user value'},...])
|
|
|
|
*/
|
|
|
|
form:function(fields, title, callback, modal) {
|
|
|
|
var content = '<table>';
|
2012-10-26 18:34:04 +00:00
|
|
|
$.each(fields, function(index, val){
|
|
|
|
content += '<tr><td>'+val.text+'</td><td>';
|
2012-10-31 08:42:26 +00:00
|
|
|
var type=val.type;
|
2012-10-26 18:34:04 +00:00
|
|
|
|
2012-05-05 11:48:12 +00:00
|
|
|
if (type == 'text' || type == 'checkbox' || type == 'password') {
|
2012-10-26 18:34:04 +00:00
|
|
|
content += '<input type="'+type+'" name="'+val.name+'"';
|
2012-05-05 11:48:12 +00:00
|
|
|
if (type == 'checkbox') {
|
2012-10-26 18:34:04 +00:00
|
|
|
if (val.value != undefined && val.value == true) {
|
2012-05-05 11:48:12 +00:00
|
|
|
content += ' checked="checked">';
|
|
|
|
} else {
|
|
|
|
content += '>';
|
|
|
|
}
|
2012-10-26 18:34:04 +00:00
|
|
|
} else if (type == 'text' || type == 'password' && val.value) {
|
|
|
|
content += ' value="'+val.value+'">';
|
2012-05-05 11:48:12 +00:00
|
|
|
}
|
|
|
|
} else if (type == 'select') {
|
2012-10-26 18:34:04 +00:00
|
|
|
content += '<select name="'+val.name+'"';
|
2012-10-31 08:42:26 +00:00
|
|
|
if (val.value != undefined) {
|
2012-10-26 18:34:04 +00:00
|
|
|
content += ' value="'+val.value+'"';
|
2012-05-05 11:48:12 +00:00
|
|
|
}
|
|
|
|
content += '>';
|
2012-10-26 18:34:04 +00:00
|
|
|
$.each(val.options, function(index, valo){
|
2012-10-31 08:42:26 +00:00
|
|
|
content += '<option value="'+valo.value+'">'+valo.text+'</option>';
|
2012-10-26 18:34:04 +00:00
|
|
|
});
|
2012-05-05 11:48:12 +00:00
|
|
|
content += '</select>';
|
|
|
|
}
|
|
|
|
content += '</td></tr>';
|
2012-10-26 18:34:04 +00:00
|
|
|
|
|
|
|
});
|
2012-05-05 11:48:12 +00:00
|
|
|
content += '</table>';
|
|
|
|
OCdialogs.message(content, title, OCdialogs.FORM_DIALOG, OCdialogs.OK_CANCEL_BUTTONS, callback, modal);
|
|
|
|
},
|
|
|
|
filepicker:function(title, callback, multiselect, mimetype_filter, modal) {
|
|
|
|
var c_name = 'oc-dialog-'+OCdialogs.dialogs_counter+'-content';
|
|
|
|
var c_id = '#'+c_name;
|
|
|
|
var d = '<div id="'+c_name+'" title="'+title+'"><select id="dirtree"><option value="0">'+OC.currentUser+'</option></select><div id="filelist"></div><div class="filepicker_loader"><img src="'+OC.filePath('gallery','img','loading.gif')+'"></div></div>';
|
2012-09-21 10:05:01 +00:00
|
|
|
if (!modal) modal = false; // Huh..
|
2012-05-05 11:48:12 +00:00
|
|
|
if (!multiselect) multiselect = false;
|
|
|
|
$('body').append(d);
|
|
|
|
$(c_id + ' #dirtree').focus(function() {
|
|
|
|
var t = $(this);
|
|
|
|
t.data('oldval', t.val())
|
|
|
|
}).change({dcid: c_id}, OC.dialogs.handleTreeListSelect);
|
|
|
|
$(c_id).ready(function(){
|
|
|
|
$.getJSON(OC.filePath('files', 'ajax', 'rawlist.php'), {mimetype: mimetype_filter} ,function(r) {
|
|
|
|
OC.dialogs.fillFilePicker(r, c_id, callback)
|
|
|
|
});
|
|
|
|
}).data('multiselect', multiselect).data('mimetype',mimetype_filter);
|
|
|
|
// build buttons
|
|
|
|
var b = [{
|
2012-09-21 09:48:57 +00:00
|
|
|
text: t('core', 'Choose'),
|
2012-05-05 11:48:12 +00:00
|
|
|
click: function(){
|
|
|
|
if (callback != undefined) {
|
|
|
|
var p;
|
|
|
|
if ($(c_id).data('multiselect') == true) {
|
|
|
|
p = [];
|
2013-03-04 15:36:49 +00:00
|
|
|
$(c_id+' .filepicker_element_selected .filename').each(function(i, elem) {
|
2012-05-05 11:48:12 +00:00
|
|
|
p.push(($(c_id).data('path')?$(c_id).data('path'):'')+'/'+$(elem).text());
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
var p = $(c_id).data('path');
|
|
|
|
if (p == undefined) p = '';
|
2013-03-04 15:36:49 +00:00
|
|
|
p = p+'/'+$(c_id+' .filepicker_element_selected .filename').text()
|
2012-05-05 11:48:12 +00:00
|
|
|
}
|
|
|
|
callback(p);
|
|
|
|
$(c_id).dialog('close');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
2012-09-21 09:48:57 +00:00
|
|
|
text: t('core', 'Cancel'),
|
2012-05-05 11:48:12 +00:00
|
|
|
click: function(){$(c_id).dialog('close'); }}
|
|
|
|
];
|
|
|
|
$(c_id).dialog({width: ((4*$('body').width())/9), height: 400, modal: modal, buttons: b});
|
|
|
|
OCdialogs.dialogs_counter++;
|
|
|
|
},
|
|
|
|
// guts, dont use, dont touch
|
|
|
|
message:function(content, title, dialog_type, buttons, callback, modal) {
|
|
|
|
var c_name = 'oc-dialog-'+OCdialogs.dialogs_counter+'-content';
|
|
|
|
var c_id = '#'+c_name;
|
|
|
|
var d = '<div id="'+c_name+'" title="'+title+'">'+content+'</div>';
|
|
|
|
if (modal == undefined) modal = false;
|
|
|
|
$('body').append(d);
|
|
|
|
var b = [];
|
|
|
|
switch (buttons) {
|
|
|
|
case OCdialogs.YES_NO_BUTTONS:
|
2012-09-21 09:48:57 +00:00
|
|
|
b[1] = {text: t('core', 'No'), click: function(){ if (callback != undefined) callback(false); $(c_id).dialog('close'); }};
|
|
|
|
b[0] = {text: t('core', 'Yes'), click: function(){ if (callback != undefined) callback(true); $(c_id).dialog('close');}};
|
2012-05-05 11:48:12 +00:00
|
|
|
break;
|
|
|
|
case OCdialogs.OK_CANCEL_BUTTONS:
|
2012-09-21 09:48:57 +00:00
|
|
|
b[1] = {text: t('core', 'Cancel'), click: function(){$(c_id).dialog('close'); }};
|
2012-05-05 11:48:12 +00:00
|
|
|
case OCdialogs.OK_BUTTON: // fallthrough
|
|
|
|
var f;
|
|
|
|
switch(dialog_type) {
|
|
|
|
case OCdialogs.ALERT_DIALOG:
|
|
|
|
f = function(){$(c_id).dialog('close'); if(callback) callback();};
|
|
|
|
break;
|
|
|
|
case OCdialogs.PROMPT_DIALOG:
|
|
|
|
f = function(){OCdialogs.prompt_ok_handler(callback, c_id)};
|
|
|
|
break;
|
|
|
|
case OCdialogs.FORM_DIALOG:
|
|
|
|
f = function(){OCdialogs.form_ok_handler(callback, c_id)};
|
|
|
|
break;
|
|
|
|
}
|
2012-09-21 09:48:57 +00:00
|
|
|
b[0] = {text: t('core', 'Ok'), click: f};
|
2012-05-05 11:48:12 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
var possible_height = ($('tr', d).size()+1)*30;
|
|
|
|
$(c_id).dialog({width: 4*$(document).width()/9, height: possible_height + 120, modal: modal, buttons: b});
|
|
|
|
OCdialogs.dialogs_counter++;
|
|
|
|
},
|
|
|
|
// dialogs buttons types
|
|
|
|
YES_NO_BUTTONS: 70,
|
|
|
|
OK_BUTTONS: 71,
|
|
|
|
OK_CANCEL_BUTTONS: 72,
|
|
|
|
// dialogs types
|
|
|
|
ALERT_DIALOG: 80,
|
|
|
|
INFO_DIALOG: 81,
|
|
|
|
PROMPT_DIALOG: 82,
|
|
|
|
FORM_DIALOG: 83,
|
|
|
|
dialogs_counter: 0,
|
|
|
|
determineValue: function(element) {
|
|
|
|
switch ($(element).attr('type')) {
|
|
|
|
case 'checkbox': return element.checked;
|
|
|
|
}
|
|
|
|
return $(element).val();
|
|
|
|
},
|
|
|
|
prompt_ok_handler: function(callback, c_id) { $(c_id).dialog('close'); if (callback != undefined) callback($(c_id + " input#oc-dialog-prompt-input").val()); },
|
|
|
|
form_ok_handler: function(callback, c_id) {
|
|
|
|
if (callback != undefined) {
|
|
|
|
var r = [];
|
|
|
|
var c = 0;
|
|
|
|
$(c_id + ' input, '+c_id+' select').each(function(i, elem) {
|
|
|
|
r[c] = {name: $(elem).attr('name'), value: OCdialogs.determineValue(elem)};
|
|
|
|
c++;
|
|
|
|
});
|
|
|
|
$(c_id).dialog('close');
|
|
|
|
callback(r);
|
|
|
|
} else {
|
|
|
|
$(c_id).dialog('close');
|
|
|
|
}
|
|
|
|
},
|
|
|
|
fillFilePicker:function(r, dialog_content_id) {
|
2013-03-04 15:36:49 +00:00
|
|
|
var entry_template = '<div data-entryname="*ENTRYNAME*" data-dcid="'+dialog_content_id+'" data="*ENTRYTYPE*"><img src="*MIMETYPEICON*" style="margin-right:1em;"><span class="filename">*NAME*</span><div style="float:right;margin-right:1em;">*LASTMODDATE*</div></div>';
|
2012-05-05 11:48:12 +00:00
|
|
|
var names = '';
|
2012-10-26 18:34:04 +00:00
|
|
|
$.each(r.data, function(index, a) {
|
|
|
|
names += entry_template.replace('*LASTMODDATE*', OC.mtime2date(a.mtime)).replace('*NAME*', a.name).replace('*MIMETYPEICON*', a.mimetype_icon).replace('*ENTRYNAME*', a.name).replace('*ENTRYTYPE*', a.type);
|
|
|
|
});
|
|
|
|
|
2013-03-04 15:36:49 +00:00
|
|
|
$(dialog_content_id + ' #filelist').html(names).on('click', '[data="file"]', function() {
|
|
|
|
OC.dialogs.handlePickerClick(this, $(this).data('entryname'), $(this).data('dcid'));
|
|
|
|
});
|
2012-05-05 11:48:12 +00:00
|
|
|
$(dialog_content_id + ' .filepicker_loader').css('visibility', 'hidden');
|
|
|
|
},
|
|
|
|
handleTreeListSelect:function(event) {
|
|
|
|
var newval = parseInt($(this).val());
|
|
|
|
var oldval = parseInt($(this).data('oldval'));
|
|
|
|
while (newval != oldval && oldval > 0) {
|
|
|
|
$('option:last', this).remove();
|
|
|
|
$('option:last', this).attr('selected','selected');
|
|
|
|
oldval--;
|
|
|
|
}
|
|
|
|
var skip_first = true;
|
|
|
|
var path = '';
|
|
|
|
$(this).children().each(function(i, element) {
|
|
|
|
if (skip_first) {
|
|
|
|
skip_first = false;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
path += '/'+$(element).text();
|
|
|
|
});
|
|
|
|
$(event.data.dcid).data('path', path);
|
|
|
|
$(event.data.dcid + ' .filepicker_loader').css('visibility', 'visible');
|
|
|
|
$.getJSON(OC.filePath('files', 'ajax', 'rawlist.php'), {dir: path, mimetype: $(event.data.dcid).data('mimetype')}, function(r){OC.dialogs.fillFilePicker(r, event.data.dcid)});
|
|
|
|
},
|
|
|
|
// this function is in early development state, please dont use it unlsess you know what you are doing
|
|
|
|
handlePickerClick:function(element, name, dcid) {
|
|
|
|
var p = $(dcid).data('path');
|
|
|
|
if (p == undefined) p = '';
|
|
|
|
p = p+'/'+name;
|
|
|
|
if ($(element).attr('data') == 'file'){
|
|
|
|
if ($(dcid).data('multiselect') != true) {
|
|
|
|
$(dcid+' .filepicker_element_selected').removeClass('filepicker_element_selected');
|
|
|
|
}
|
|
|
|
$(element).toggleClass('filepicker_element_selected');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
$(dcid).data('path', p);
|
|
|
|
$(dcid + ' #dirtree option:last').removeAttr('selected');
|
|
|
|
var newval = parseInt($(dcid + ' #dirtree option:last').val())+1;
|
|
|
|
$(dcid + ' #dirtree').append('<option selected="selected" value="'+newval+'">'+name+'</option>');
|
|
|
|
$(dcid + ' .filepicker_loader').css('visibility', 'visible');
|
|
|
|
$.getJSON(OC.filePath('files', 'ajax', 'rawlist.php'), {dir: p, mimetype: $(dcid).data('mimetype')}, function(r){OC.dialogs.fillFilePicker(r, dcid)});
|
|
|
|
}
|
2012-02-28 22:02:02 +00:00
|
|
|
};
|