Changeset 5736


Ignore:
Timestamp:
Apr 9, 2010, 4:04:51 PM (10 years ago)
Author:
plg
Message:

bug 1555: UploadForm, before starting upload (html/multiple modes), check if
the category is correctly set and if there is at least 1 photo selected.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/admin/themes/default/template/photos_add_direct.tpl

    r5493 r5736  
    11{known_script id="jquery" src=$ROOT_URL|@cat:"themes/default/js/jquery.packed.js"}
    22
     3{if $upload_mode eq 'multiple'}
     4<script type="text/javascript" src="{$uploadify_path}/swfobject.js"></script>
     5<script type="text/javascript" src="{$uploadify_path}/jquery.uploadify.v2.1.0.min.js"></script>
     6{/if}
     7
    38{literal}
    4 <script>
    5 $(document).ready(function(){
     9<script type="text/javascript">
     10jQuery(document).ready(function(){
     11  function checkUploadStart() {
     12    var nbErrors = 0;
     13    $("#formErrors li").hide();
     14
     15    if ($("input[name=category_type]:checked").val() == "new" && $("input[name=category_name]").val() == "") {
     16      $("#formErrors #emptyCategoryName").show();
     17      nbErrors++;
     18    }
     19
     20    var nbFiles = 0;
     21    if ($("uploadBoxes").size() == 1) {
     22      $("input[name^=image_upload]").each(function() {
     23        if ($(this).val() != "") {
     24          nbFiles++;
     25        }
     26      });
     27    }
     28    else {
     29      nbFiles = $(".uploadifyQueueItem").size();
     30    }
     31
     32    if (nbFiles == 0) {
     33      $("#formErrors #noPhoto").show();
     34      nbErrors++;
     35    }
     36
     37    if (nbErrors != 0) {
     38      $("#formErrors").show();
     39      return false;
     40    }
     41    else {
     42      return true;
     43    }
     44
     45  }
    646
    747  $("input[name=category_type]").click(function () {
     
    949    $("#category_type_"+$(this).attr("value")).show();
    1050  });
    11 });
    12 </script>
     51
     52  $("#hideErrors").click(function() {
     53    $("#formErrors").hide();
     54    return false;
     55  });
     56
    1357{/literal}
    14 
    1558{if $upload_mode eq 'html'}
    1659{literal}
    17 <script type="text/javascript">
    18 $(document).ready(function(){
    1960  function addUploadBox() {
    2061    var uploadBox = '<p class="file"><input type="file" size="60" name="image_upload[]" /></p>';
     
    2768    addUploadBox();
    2869  });
    29 });
    30 </script>
     70
     71  $("#uploadForm").submit(function() {
     72    return checkUploadStart();
     73  });
    3174{/literal}
    32 
    3375{elseif $upload_mode eq 'multiple'}
    34 <script type="text/javascript" src="{$uploadify_path}/swfobject.js"></script>
    35 <script type="text/javascript" src="{$uploadify_path}/jquery.uploadify.v2.1.0.min.js"></script>
    36 
    37 <script type="text/javascript">
     76
    3877var uploadify_path = '{$uploadify_path}';
    3978var upload_id = '{$upload_id}';
     
    4382
    4483{literal}
    45 jQuery(document).ready(function() {
    4684  jQuery("#uploadify").uploadify({
    4785    'uploader'       : uploadify_path + '/uploadify.swf',
     
    5896    'buttonText'     : buttonText,
    5997    'multi'          : true,
     98    'fileDesc'       : 'Photo files (*.jpg,*.jpeg)',
     99    'fileExt'        : '*.jpg;*.JPG;*.jpeg;*.JPEG',
    60100    'onAllComplete'  : function(event, data) {
    61101      if (data.errors) {
     
    67107    }
    68108  });
     109
     110  $("input[type=button]").click(function() {
     111    if (!checkUploadStart()) {
     112      return false;
     113    }
     114
     115    $("#uploadify").uploadifyUpload();
     116  });
     117
     118{/literal}
     119{/if}
    69120});
    70 {/literal}
    71121</script>
    72 {/if}
    73122
    74123<div class="titrePage">
     
    102151{/if}
    103152
     153<div id="formErrors" class="errors" style="display:none">
     154  <ul>
     155    <li id="emptyCategoryName">{'The name of a category should not be empty'|@translate}</li>
     156    <li id="noPhoto">{'Select at least one picture'|@translate}</li>
     157  </ul>
     158  <div class="hideButton" style="text-align:center"><a href="#" id="hideErrors">{'Hide'|@translate}</a></div>
     159</div>
    104160
    105161<form id="uploadForm" enctype="multipart/form-data" method="post" action="{$F_ACTION}" class="properties">
     
    180236    </fieldset>
    181237    <p>
    182       <input class="submit" type="button" value="{'Upload'|@translate}" onclick="javascript:jQuery('#uploadify').uploadifyUpload()"/>
     238      <input class="submit" type="button" value="{'Upload'|@translate}"/>
    183239      <input type="submit" name="submit_upload" style="display:none"/>
    184240    </p>
Note: See TracChangeset for help on using the changeset viewer.