From 5d178b4366da37a7c2a4bff2eb3fb758357b7016 Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Fri, 28 Aug 2015 07:57:47 +0000 Subject: [PATCH] allowed multiple file selection in the new upload dialog of the code folder view. deleted legacy form posting handling from the code folder view and the code controller --- codepot/src/codepot/controllers/code.php | 51 -------------------- codepot/src/codepot/views/code_folder.php | 59 +++++++++++++---------- 2 files changed, 34 insertions(+), 76 deletions(-) diff --git a/codepot/src/codepot/controllers/code.php b/codepot/src/codepot/controllers/code.php index 4ced7a81..f9cc8b3a 100644 --- a/codepot/src/codepot/controllers/code.php +++ b/codepot/src/codepot/controllers/code.php @@ -76,55 +76,6 @@ class Code extends Controller } else { - $popup_error_message = ''; - - $post_new_message = $this->input->post('code_folder_new_message'); - $post_max_item_no = $this->input->post('code_folder_new_item_count'); - $post_unzip = $this->input->post('code_folder_new_item_unzip'); - if ($post_new_message !== FALSE && $post_max_item_no !== FALSE) - { - $import_files = array (); - for ($i = 0; $i < $post_max_item_no; $i++) - { - $d = $this->input->post("code_folder_new_item_dir_$i"); - if (strlen($d) > 0) - { - array_push ($import_files, array ('type' => 'dir', 'name' => $d)); - } - - $d = $this->input->post("code_folder_new_item_empfile_$i"); - if (strlen($d) > 0) - { - array_push ($import_files, array ('type' => 'empfile', 'name' => $d)); - } - - $fid = "code_folder_new_item_file_$i"; - if (array_key_exists($fid, $_FILES) && $_FILES[$fid]['name'] != '') - { - array_push ($import_files, array ('type' => 'file', 'name' => $_FILES[$fid]['name'], 'fid' => $fid, 'unzip' => $post_unzip)); - } - } - - if (count($import_files) > 0 && $this->subversion->importFiles ($projectid, $path, $login['id'], $post_new_message, $import_files, $this->upload) === FALSE) - { - $popup_error_message = $this->subversion->getErrorMessage(); - } - else - { - $refreshed_file = $this->subversion->getFile ($projectid, $path, $rev); - if ($refreshed_file === FALSE) - { - $data['project'] = $project; - $data['message'] = 'Failed to get file'; - $this->load->view ($this->VIEW_ERROR, $data); - return; /* EXIT HERE */ - } - - $file = $refreshed_file; - } - } - - $data['popup_error_message'] = $popup_error_message; if ($file['type'] == 'file') { $head_rev = $this->subversion->getHeadRev ($projectid, $path, $rev); @@ -162,7 +113,6 @@ class Code extends Controller $file['created_tag'] = $this->subversion->getRevProp ($projectid, $file['created_rev'], CODEPOT_SVN_TAG_PROPERTY); if ($file['created_tag'] === FALSE) $file['created_tag'] = ''; - foreach ($file['content'] as &$f) { $exe = $this->subversion->getProp ( @@ -183,7 +133,6 @@ class Code extends Controller } } - $data['project'] = $project; $data['headpath'] = $path; $data['file'] = $file; diff --git a/codepot/src/codepot/views/code_folder.php b/codepot/src/codepot/views/code_folder.php index 6de4ff5d..974cada6 100644 --- a/codepot/src/codepot/views/code_folder.php +++ b/codepot/src/codepot/views/code_folder.php @@ -206,7 +206,10 @@ var rename_last_input = {}; function get_new_item_html(no, type, name) { - return codepot_sprintf ('
  • ', type, name, no, name, no); + return codepot_sprintf ( + '
  • ', + type, name, no, name, no, ((type == 'file')? 'multiple=""': '') + ); } $(function () { @@ -240,8 +243,6 @@ $(function () { 'lang->line('OK')?>': function () { if (import_in_progress) return; - $('#code_folder_mainarea_new_item_count').val (new_item_no + 1); - if (!!window.FormData) { // FormData is supported @@ -250,19 +251,43 @@ $(function () { var form_data = new FormData(); form_data.append ('code_new_message', $('#code_folder_mainarea_new_message').val()); - form_data.append ('code_new_item_count', $('#code_folder_mainarea_new_item_count').val()); form_data.append ('code_new_item_unzip', $('#code_folder_mainarea_new_item_unzip').val()); + + var f_no = 0, d_no = 0, ef_no = 0; for (var i = 0; i <= new_item_no; i++) { - var f = $('#code_folder_mainarea_new_item_file_' + i).get(0).files[0]; - if (f != null) form_data.append ('code_new_item_file_' + i, f); + f = $('#code_folder_mainarea_new_item_file_' + i).get(0); + if (f != null) + { + for (var n = 0; n < f.files.length; n++) + { + if (f.files[n] != null) + { + form_data.append ('code_new_item_file_' + f_no, f.files[n]); + f_no++; + } + } + } var d = $('#code_folder_mainarea_new_item_dir_' + i).val(); - if (d != null && d != '') form_data.append ('code_new_item_dir_' + i, d); + if (d != null && d != '') + { + form_data.append ('code_new_item_dir_' + d_no, d); + d_no++; + } var d = $('#code_folder_mainarea_new_item_empfile_' + i).val(); - if (d != null && d != '') form_data.append ('code_new_item_empfile_' + i, d); + if (d != null && d != '') + { + form_data.append ('code_new_item_empfile_' + ef_no, d); + ef_no++; + } } + var x_no = f_no; + if (d_no > x_no) x_no = d_no; + if (ef_no > x_no) x_no = ef_no; + + form_data.append ('code_new_item_count', x_no); $('#code_folder_mainarea_new_form_div').dialog('disable'); $.ajax({ @@ -299,10 +324,8 @@ $(function () { } else { - $('#code_folder_mainarea_new_form_div').dialog('close'); - $('#code_folder_mainarea_new_form').submit(); + show_alert ('
    NOT SUPPORTED
    ', "lang->line('Error')?>"); } - }, 'lang->line('Cancel')?>': function () { if (import_in_progress) return; @@ -387,7 +410,6 @@ $(function () { { show_alert ('
    NOT SUPPORTED
    ', "lang->line('Error')?>"); } - }, 'lang->line('Cancel')?>': function () { if (delete_in_progress) return; @@ -637,10 +659,6 @@ $(function () { }); render_readme (); - - 0): ?> - show_alert (' . htmlspecialchars($popup_error_message) . ''); ?>, "lang->line('Error')?>"); - }); @@ -1077,13 +1095,6 @@ $this->load->view (
    - 'code_folder_mainarea_new_form'); - // this form posts to the head revision regardless of the revision being shown currently - print form_open_multipart("code/file/{$project->id}/".$this->converter->AsciiToHex($headpath), $attrs); - ?> - -
    lang->line('Message'); ?>:
    @@ -1104,8 +1115,6 @@ $this->load->view (
      - -