//The build will inline common dependencies into this file. //For any third party dependencies, like jQuery, place them in the lib folder. //Configure loading modules from the lib directory, //except for 'app' ones, which are in a sibling directory. require.config({ // The shim config allows us to configure dependencies for // scripts that do not call define() to register a module shim: { underscore: { exports: '_' }, backbone: { deps: [ 'underscore', 'jquery' ], exports: 'Backbone' }, }, paths: { 'jquery': 'lib/jquery', 'jquery.ui.core': 'lib/jquery.ui.core', 'jquery.ui.widget': 'lib/jquery.ui.widget.1.11.1', 'jquery.ui.progressbar': 'lib/jquery.ui.progressbar', 'jquery.ui.tabs': 'lib/jquery.ui.tabs', 'tmpl': 'lib/tmpl.min', 'jquery.iframe-transport': 'lib/jquery.iframe-transport.1.4', 'jquery.fileupload': 'lib/jquery.fileupload.5.42.1', 'jquery.fileupload-process': 'lib/jquery.fileupload.file-processing.1.3.0', 'jquery.fileupload-validate': 'lib/jquery.fileupload.validation.1.1.2', 'jquery.fileupload-ui': 'lib/jquery.fileupload.ui.9.6.0', simplemodal: 'lib/jquery.simplemodal.1.4.4.min', jstree: 'lib/jstree.1.0', select2: 'lib/select2-3.5.2', underscore: 'lib/underscore', backbone: 'lib/backbone', text: 'lib/text' } }); define([ 'jquery', 'underscore', 'text', // Workaround for r.js, otherwise text.js will not be included ], function($, _, text) { return { INFO_TIMEOUT: 10000, // 10 secs for info msg SUCCESS_TIMEOUT: 3000, // 3 secs for success msg ERROR_TIMEOUT: 3000, // 3 secs for error msg getUrl: function(options) { var siteRoot = app.config.siteRoot; switch (options.name) { case 'list_lib_dir': return siteRoot + 'ajax/lib/' + options.repo_id + '/dir/'; case 'star_file': return siteRoot + 'ajax/repo/' + options.repo_id + '/file/star/'; case 'unstar_file': return siteRoot + 'ajax/repo/' + options.repo_id + '/file/unstar/'; case 'del_dir': return siteRoot + 'ajax/repo/' + options.repo_id + '/dir/delete/'; case 'del_file': return siteRoot + 'ajax/repo/' + options.repo_id + '/file/delete/'; case 'rename_dir': return siteRoot + 'ajax/repo/' + options.repo_id + '/dir/rename/'; case 'rename_file': return siteRoot + 'ajax/repo/' + options.repo_id + '/file/rename/'; case 'mv_dir': return siteRoot + 'ajax/repo/' + options.repo_id + '/dir/mv/'; case 'cp_dir': return siteRoot + 'ajax/repo/' + options.repo_id + '/dir/cp/'; case 'mv_file': return siteRoot + 'ajax/repo/' + options.repo_id + '/file/mv/'; case 'cp_file': return siteRoot + 'ajax/repo/' + options.repo_id + '/file/cp/'; case 'new_dir': return siteRoot + 'ajax/repo/' + options.repo_id + '/dir/new/'; case 'new_file': return siteRoot + 'ajax/repo/' + options.repo_id + '/file/new/'; case 'del_dirents': return siteRoot + 'ajax/repo/' + options.repo_id + '/dirents/delete/'; case 'mv_dirents': return siteRoot + 'ajax/repo/' + options.repo_id + '/dirents/move/'; case 'cp_dirents': return siteRoot + 'ajax/repo/' + options.repo_id + '/dirents/copy/'; case 'get_file_op_url': return siteRoot + 'ajax/repo/' + options.repo_id + '/file_op_url/'; case 'get_dirents': return siteRoot + 'ajax/repo/' + options.repo_id + '/dirents/'; case 'thumbnail_create': return siteRoot + 'thumbnail/' + options.repo_id + '/create/'; case 'unenc_rw_repos': return siteRoot + 'ajax/unenc-rw-repos/'; case 'get_cp_progress': return siteRoot + 'ajax/cp_progress/'; case 'cancel_cp': return siteRoot + 'ajax/cancel_cp/'; case 'ajax_repo_remove_share': return siteRoot + 'share/ajax/repo_remove_share/'; case 'get_user_contacts': return siteRoot + 'ajax/contacts/'; case 'get_shared_download_link': return siteRoot + 'share/ajax/get-download-link/'; case 'delete_shared_download_link': return siteRoot + 'share/ajax/link/remove/'; case 'send_shared_download_link': return siteRoot + 'share/link/send/'; case 'send_shared_upload_link': return siteRoot + 'share/upload_link/send/'; case 'delete_shared_upload_link': return siteRoot + 'share/ajax/upload_link/remove/'; case 'get_share_upload_link': return siteRoot + 'share/ajax/get-upload-link/'; case 'private_share_dir': return siteRoot + 'share/ajax/private-share-dir/'; case 'private_share_file': return siteRoot + 'share/ajax/private-share-file/'; case 'get_popup_notices': return siteRoot + 'ajax/get_popup_notices/'; case 'set_notices_seen': return siteRoot + 'ajax/set_notices_seen/'; case 'get_unseen_notices_num': return siteRoot + 'ajax/unseen-notices-count/'; case 'set_notice_seen_by_id': return siteRoot + 'ajax/set_notice_seen_by_id/'; } }, showConfirm: function(title, content, yesCallback) { var $popup = $("#confirm-popup"); var $cont = $('#confirm-con'); var $container = $('#simplemodal-container'); var $yesBtn = $('#confirm-yes'); $cont.html('
' + content + '
'); $popup.modal({appendTo: '#main'}); $container.css({'height':'auto'}); $yesBtn.click(yesCallback); }, closeModal: function() { $.modal.close(); }, feedback: function(con, type, time) { var time = time || 5000; if ($('.messages')[0]) { $('.messages').html('' + error + '
'); } else { $('.error', popup).removeClass('hide'); } } } }); } }); _this = this; $(document).click(function(e) { _this.closePopup(e, $('#user-info-popup'), $('#my-info')); }); }, initNoticePopup: function() { var _this = this, notice_popup = $('#notice-popup'), loading_tip = $('#notice-popup .loading-tip'), notice_icon = $('#notice-icon'), notice_list = $('#notice-list'), msg_count = $('#msg-count'), num = $('#msg-count .num'), orig_doc_title = document.title, countUnseenNotices = function() { // for login page, and pages without 'header' such as 'file view' page. if (msg_count.length == 0) { return false; } var success_callback = function(data) { var count = data['count']; if (count > 0) { num.removeClass('hide'); num.html(count); document.title = '(' + count + ')' + orig_doc_title; } else { num.addClass('hide'); document.title = orig_doc_title; } }; _this.ajaxGet({ 'get_url': _this.getUrl({name: 'get_unseen_notices_num'}), 'after_op_success': success_callback }); }; countUnseenNotices(); setInterval(countUnseenNotices, 30*1000); notice_icon.on('click', function() { if (notice_popup.hasClass('hide')) { notice_popup.removeClass('hide'); var success_callback = function(data) { loading_tip.hide(); notice_list.html(data['notice_html']).show(); $(document).click(function(e) { _this.closePopup(e, notice_popup, notice_icon); }); $('.unread a', notice_list).click(function() { var notice_id = $(this).parents('.unread').data('id'), link_href = $(this).attr('href'); $.ajax({ url: _this.getUrl({name: 'set_notice_seen_by_id'}) + '?notice_id=' + e(notice_id), dataType:'json', }); location.href = link_href; return false; }); $('.detail', notice_list).click(function() { location.href = $('.brief a', $(this).parent()).attr('href'); }); }; _this.ajaxGet({ 'get_url': _this.getUrl({name: 'get_popup_notices'}), 'after_op_success': success_callback }); } else { notice_popup.addClass('hide'); loading_tip.show(); notice_list.hide(); } }); $('.close', notice_popup).on('click', function() { notice_popup.addClass('hide'); loading_tip.show(); notice_list.hide(); if ($('li', notice_list).hasClass('unread')) { var success_callback = function(data) { num.html(0).hide(); document.title = orig_doc_title; }; _this.ajaxGet({ 'get_url': _this.getUrl({name: 'set_notices_seen'}), 'after_op_success': success_callback }); } }); $(window).resize(function() { if (!notice_popup.hasClass('hide')) { $('.con', notice_popup).css({'max-height':$(window).height() - $('#header').outerHeight() - $('.hd', notice_popup).outerHeight() - 3}); } }); }, fileSizeFormat: function(bytes, precision) { var kilobyte = 1024; var megabyte = kilobyte * 1024; var gigabyte = megabyte * 1024; var terabyte = gigabyte * 1024; var precision = precision || 0; if ((bytes >= 0) && (bytes < kilobyte)) { return bytes + ' B'; } else if ((bytes >= kilobyte) && (bytes < megabyte)) { return (bytes / kilobyte).toFixed(precision) + ' KB'; } else if ((bytes >= megabyte) && (bytes < gigabyte)) { return (bytes / megabyte).toFixed(precision) + ' MB'; } else if ((bytes >= gigabyte) && (bytes < terabyte)) { return (bytes / gigabyte).toFixed(precision) + ' GB'; } else if (bytes >= terabyte) { return (bytes / terabyte).toFixed(precision) + ' TB'; } else { return bytes + ' B'; } } } });