diff options
author | Bartek Przybylski <bart.p.pl@gmail.com> | 2012-02-28 23:02:02 +0100 |
---|---|---|
committer | Bartek Przybylski <bart.p.pl@gmail.com> | 2012-02-28 23:02:30 +0100 |
commit | 2754cac21ffaba199b05526e0a8df5bcd4a25768 (patch) | |
tree | 61b1cd4f1ba5767d16cc669ab245b52bf0735022 | |
parent | ea15c17149227373045dd6a5d08cf8e83c8a374b (diff) | |
download | nextcloud-server-2754cac21ffaba199b05526e0a8df5bcd4a25768.tar.gz nextcloud-server-2754cac21ffaba199b05526e0a8df5bcd4a25768.zip |
dialogs library for apps
-rw-r--r-- | apps/gallery/templates/index.php | 1 | ||||
-rw-r--r-- | core/js/js.js | 3 | ||||
-rw-r--r-- | core/js/oc-dialogs.js | 145 | ||||
-rw-r--r-- | lib/base.php | 1 |
4 files changed, 148 insertions, 2 deletions
diff --git a/apps/gallery/templates/index.php b/apps/gallery/templates/index.php index 7cc7dad3ac6..1b8d53e82d4 100644 --- a/apps/gallery/templates/index.php +++ b/apps/gallery/templates/index.php @@ -5,7 +5,6 @@ OC_Util::addScript('gallery', 'album_cover'); $l = new OC_L10N('gallery'); ?> -<div id="notification"><div id="gallery_notification_text">Creating thumbnails</div></div> <div id="controls"> <div id="scan"> <div id="scanprogressbar"></div> diff --git a/core/js/js.js b/core/js/js.js index 61588f7a0f2..df1b5c6ce76 100644 --- a/core/js/js.js +++ b/core/js/js.js @@ -125,7 +125,8 @@ OC={ OC.search.showResults(results); }); } - } + }, + dialogs:OCdialogs }; OC.search.customResults={}; OC.search.currentResult=-1; diff --git a/core/js/oc-dialogs.js b/core/js/oc-dialogs.js new file mode 100644 index 00000000000..de67c342a71 --- /dev/null +++ b/core/js/oc-dialogs.js @@ -0,0 +1,145 @@ +/** + * ownCloud + * + * @author Bartek Przybylski + * @copyright 2012 Bartek Przybylski bart.p.pl@gmail.com + * + * 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/>. + * + * todo(bartek): add select option in form + */ + +/** + * this class ease usage of jquery dialogs + */ +OCdialogs = { + /** + * 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) { + var content = '<p><span class="ui-icon ui-icon-alert"></span>'+text+'</p>'; + OCdialogs.message(content, title, OCdialogs.ALERT_DIALOG, OCdialogs.OK_BUTTON, callback); + }, + /** + * 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) { + var content = '<p><span class="ui-icon ui-icon-info"></span>'+text+'</p>'; + OCdialogs.message(content, title, OCdialogs.ALERT_DIALOG, OCdialogs.OK_BUTTON, callback); + }, + /** + * 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) { + var content = '<p><span class="ui-icon ui-icon-notice"></span>'+text+'</p>'; + OCdialogs.message(content, title, OCdialogs.ALERT_DIALOG, OCdialogs.YES_NO_BUTTON, callback); + }, + /** + * 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, callback) { + var content = '<p><span class="ui-icon ui-icon-pencil"></span>'+text+':<br/><input type="text" id="oc-dialog-prompt-input" style="width:90%"></p>'; + OCdialogs.message(content, title, OCdialogs.PROMPT_DIALOG, OCdialogs.OK_CANCEL_BUTTONS, callback); + }, + /** + * prompt user for input with custom form + * fields should be passed in following format: [{text:'prompt text', name:'return name', type:'input type'},...] + * @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) { + var content = '<table>'; + for (var a in fields) { + content += '<tr><td>'+fields[a].text+'</td><td>'; + var type=fields[a].type; + if (type == 'text' || type == 'checkbox' || type == 'password') + content += '<input type="'+type+'" name="'+fields[a].name+'">'; + content += "</td></tr>" + } + content += "</table>"; + OCdialogs.message(content, title, OCdialogs.FORM_DIALOG, OCdialogs.OK_CANCEL_BUTTONS, callback); + }, + message:function(content, title, dialog_type, buttons, callback) { + var c_name = 'oc-dialog-'+OCdialogs.dialogs_counter+'-content'; + var c_id = '#'+c_name; + var d = '<div id="'+c_name+'" title="'+title+'">'+content+'</div>'; + $('body').append(d); + var b = []; + switch (buttons) { + case OCdialogs.YES_NO_BUTTONS: + b[1] = {text: t('dialogs', 'No'), click: function(){ if (callback != undefined) callback(false); $(c_id).dialog('close'); }}; + b[0] = {text: t('dialogs', 'Yes'), click: function(){ if (callback != undefined) callback(true); $(c_id).dialog('close');}}; + break; + case OCdialogs.OK_CANCEL_BUTTONS: + b[1] = {text: t('dialogs', 'Cancel'), click: function(){$(c_id).dialog('close'); }}; + case OCdialogs.OK_BUTTON: // fallthrough + var f; + switch(dialog_type) { + case OCdialogs.ALERT_DIALOG: + f = function(){$(c_id).dialog('close'); }; + 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; + } + b[0] = {text: t('dialogs', 'Ok'), click: f}; + break; + } + $(c_id).dialog({width: 4*$(document).width()/9, height: $(d).height() + 150, modal: false, 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).attr('checked') != undefined; + } + return $(element).val(); + }, + prompt_ok_handler: function(callback, c_id){callback(true, $(c_id + " input#oc-dialog-prompt-input").val()); $(c_id).dialog('close');}, + form_ok_handler: function(callback, c_id) { + var r = []; + var c = 0; + $(c_id + ' input').each(function(i, elem) { + r[c] = {name: $(elem).attr('name'), value: OCdialogs.determineValue(elem)}; + c++; + }); + $(c_id).dialog('close'); + callback(r); + } +}; diff --git a/lib/base.php b/lib/base.php index d4dbdcde9b6..c98477ce15c 100644 --- a/lib/base.php +++ b/lib/base.php @@ -268,6 +268,7 @@ class OC{ OC_Util::addScript( "jquery-showpassword" ); OC_Util::addScript( "jquery.infieldlabel.min" ); OC_Util::addScript( "jquery-tipsy" ); + OC_Util::addScript( "oc-dialogs" ); OC_Util::addScript( "js" ); OC_Util::addScript( "eventsource" ); OC_Util::addScript( "config" ); |