2010-11-29 5 views
0

저는 jQuery와 JavaScript가 완전히 새롭기 때문에 일부 코드를 수정해야합니다. 이 대화 상자에 체크 박스를 추가하고 선택에 따라 결정을 내려야합니다. 어떤 제안? 대화 상자의 몸에 대한 모든 코드가 존재하는jQuery의 대화 상자에 확인란을 추가하십시오.

function deleteFacets() 
{ 
    // button click 
    $("#b_facetsDelete").button().click(function(){ 
     // selected fIds 
     var $fIds=checkSfALOneSelectedFId(); 
     if(!$fIds) 
     { 
      return; 
     } 
     $('#deleteFacetsDialog').dialog('open');   
     return; 

    }); 

    // dialog 
    $("#deleteFacetsDialog").dialog({ 
     autoOpen: false, 
     resizable: false, 
     height:160, 
     modal: true, 
     buttons: { 
      "Cancel": function() { 
       $(this).dialog('close'); 
      }, 
      "Delete selected facets": function() { 
       $(this).dialog('close'); 

       // get the selected fIds 
       var $fIds=getSfSelectedFIds(); 

       //update database 
       $.ajax({ 
        url: 'ajax/ajax_facetsDelete.php', 
        type: 'POST', 
        data: {"fIds":$fIds}, 
        async: false, 
        dataType: 'xml', 
        error: function(){ 
         alert('Error loading XML document'); 
        }, 
        success: function(data){ 
         //check error 
         var $error=$(data).find('error').text(); 
         if($error!="0") 
         { 
          messageBox("Error",$error); 
          return; 
         } 
         //content 
         var $content=$(data).find('content').text(); 
         //refresh source facets tab 
         var $srcTabIndex=$("#srcFacetsTab").tabs('option', 'selected'); 
         if($content=="0") 
         { 
          messageBox("Succeed!","Delete successfully!"); 
          if($srcTabIndex==0) 
          { // for navigation 
           sfNavRefreshUntilParent(); 
          } 
          else if($srcTabIndex==1) 
          { //for search 
           sfSearchGridRefreshAll(); 
          } 
         } 
         else 
         {              
          messageBox("Warning!", $content+" can not be deleted since they have child facets or terms. <br/>Please empty them first(Move the child facets and move all the terms)."); 
          if($srcTabIndex==0) 
          { // for navigation (refresh and highlight the invalid fIds) 
           sfNavRefreshWithHighlightFIds($content); 
          } 
          else if($srcTabIndex==1) 
          { //for search 
           sfSearchGridRefreshWithHighlightFIds($content); 
          } 
         } 
        } 
       }); 
       return; 
      } 
     } 
    }); 

} 

HTML

<!-- delete facets confirmation dialog --> 
<div id="deleteFacetsDialog" title="Sure to delete?"> 
    <p><span class="ui-icon ui-icon-alert" style="float:left; margin:0 7px 20px 0;"></span>These facets will be permanently deleted and cannot be recovered. Are you sure?</p> 
</div> 
+0

ID가 '# deleteFacetsDialog'인 섹션과 함께이 HTML을 표시해야 할 수도 있습니다. – Orbling

+0

수정했습니다. 그 맞습니까? –

답변

1

당신이 deleteFacetsDialog에 .dialog 호출하고있는 ID이다. 그래서 당신이해야 할 일은 HTML 소스에서 그 ID를 찾아 그 안에 체크 박스를 추가하는 것입니다 (그리고 그것을 둘러싸는 데 필요한 텍스트/레이블).

그런 다음 삭제 기능 콜백에서 해당 체크 박스에 액세스하고, 값을 찾고, 선택에 따라 if/else 논리를 수행 할 수 있습니다.

<div id="deleteFacetsDialog"> 
... 
<label><input type="checkbox" id="permaDelete" />Perminantly delete this facet?</label> 
... 
</div> 

그리고 : : 예를 들어

... 
"Delete selected facets": function() { 
    ... 
    if ($('#permaDelete').is(':checked')) { 

    } else { 

    } 
    ... 
} 

그냥 당신이 JS에서 부르는와 입력 라인까지의 HTML에서 사용하는 확인 ID를 확인합니다.

+0

마지막 질문은 코드의 마지막 부분입니까? 내가 그 논리를 쓰게 될 것인가? –

+0

.Dialog 호출에서 "선택한 패싯 삭제"는 기존 코드의 일부입니다. 그 경우 익명의 기능을 수행합니다. – Parrots

관련 문제