客户端CGI——结合javascript、dhtml实现bbs的backoffice(四,完)

发表于:2007-06-30来源:作者:点击数: 标签:
//第六步,修改版主 function On_ChangeMaster() { //如果没有论坛被选中,则退出 if (frmManager.selForumName .selectedIndex == -1) { return 0 ; } if (frmManager.btnChangeMaster .value == 修改) { frmManager.btnChangeName.disabled= true ; frmMana
//第六步,修改版主
function On_ChangeMaster()
    {
      //如果没有论坛被选中,则退出
      if (frmManager.selForumName .selectedIndex == -1)
        {
          return 0 ;
        }
          
      if (frmManager.btnChangeMaster .value == "修改")
        {
          frmManager.btnChangeName  .disabled       = true ;
          frmManager.btnDown .disabled              = true ;
          frmManager.btnUp .disabled                = true ;
          frmManager.btnModifyDescription .disabled = true ;
          frmManager.btnAddForum .disabled          = true ;
          frmManager.btnDeleteForum .disabled       = true ;
          frmManager.btnSubmit .disabled            =true ;
          frmManager.selCategoryName .disabled      = true ;
          frmManager.selForumName .disabled         = true ;
          frmManager.selMaster .disabled            = false ;
          frmManager.btnChangeMaster.value          = "确定" ;
          return 0 ;
        }
      else
        {
          frmManager.btnChangeMaster.value          = "修改" ;
          frmManager.selCategoryName .disabled      = false ;
          frmManager.selForumName .disabled         = false ;
          frmManager.selMaster .disabled            = true ;
          frmManager.btnSubmit .disabled            = false ;
          var intForumIndex ;
          for (var i = 0 ; i < aForum.length ; i ++)
             {
              if (frmManager.selForumName[frmManager.selForumName.selectedIndex].value == aForum[i].CategoryID )
                {
                  intForumIndex = i ;
                  break ;
                }  
             }    
          aForum[i].MasterID = frmManager.selMaster  .value ;
         }
         
         On_ForumChange() ;
   }           


//第七步,增加栏目    
function On_AddCategory()  
   {
     if (frmManager.btnAddCategory .value == "增加")
       {
         //禁止其他表单元素
         frmManager.btnAddCategory .value          = "确定" ;
         frmManager.btnAddForum .disabled          = true ;
         frmManager.btnChangeMaster .disabled      = true ;
         frmManager.btnChangeName .disabled        = true ;
         frmManager.btnDeleteCategory .disabled    = true ;
         frmManager.btnDeleteForum .disabled       = true ;
         frmManager.btnDown .disabled              = true ;
         frmManager.btnModifyDescription .disabled = true ;
         frmManager.btnSubmit .disabled            = true ;
         frmManager.btnUp .disabled                = true ;
         frmManager.selCategoryName .disabled      = true ;
         frmManager.selForumName .disabled         = true ;
         
         //聚焦栏目名称
         frmManager.txtCategoryName .disabled      = false ;
         frmManager.txtCategoryName .value         = "请输入栏目名称" ;
         frmManager.txtCategoryName .focus() ;
         frmManager.txtCategoryName .select() ;
         
         frmManager.selCategoryName .selectedIndex = -1 ;
         
       }
    else
       {
         if (frmManager.txtCategoryName .value == ""
            || frmManager.txtCategoryName .value == "请输入栏目名称" )
           {
             alert("请输入栏目名称") ;
             frmManager.txtCategoryName .focus () ;
             frmManager.txtCategoryName .select ();
             return 0 ;
           }     
         
         
         //增加新的栏目数组成员
         var CategoryID = 1;
         for ( var i = 0 ; i < aCategory.length ; i ++)
            {
              if (aCategory[i].CategoryID > CategoryID)
                {
                  CategoryID = aCategory[i].CategoryID ;
                }
            }      
         CategoryID += 1 ;
         var CategoryName = frmManager.txtCategoryName .value
         var OrderNum     = CategoryID;
         aCategory[aCategory.length] = new MakeCategory(CategoryID , CategoryName , OrderNum);

         //重新生成
         On_Load() ;
         frmManager.btnAddCategory .value     = "增加"
         frmManager.btnSubmit .disabled       = false ;
         frmManager.selCategoryName .disabled = false ;
         frmManager.txtCategoryName .disabled = true ;
         frmManager.selForumName .disabled    = false ;
         
         frmManager.selCategoryName .selectedIndex = frmManager.selCategoryName .options .length - 1 ;
         On_CategoryChange() ;

       
       }    
   }   

//第八步,增加论坛   
function On_AddForum()  
   {
     if (frmManager.btnAddForum  .value == "增加")
       {
         //禁止其他表单元素
         frmManager.btnAddForum .value          = "确定" ;
         frmManager.btnAddCategory .disabled          = true ;
         frmManager.btnChangeMaster .disabled      = true ;
         frmManager.btnChangeName .disabled        = true ;
         frmManager.btnDeleteCategory .disabled    = true ;
         frmManager.btnDeleteForum .disabled       = true ;
         frmManager.btnDown .disabled              = true ;
         frmManager.btnModifyDescription .disabled = true ;
         frmManager.btnSubmit .disabled            = true ;
         frmManager.btnUp .disabled                = true ;
         frmManager.selCategoryName .disabled      = true ;
         frmManager.selForumName .disabled         = true ;
         
         //聚焦栏目名称
         frmManager.txtForumName .disabled      = false ;
         frmManager.txtForumName .value         = "请输入论坛名称" ;
         frmManager.txtForumName .focus() ;
         frmManager.txtForumName .select() ;
         
         frmManager.selForumName .selectedIndex = -1 ;
         frmManager.txtDescription .value = "" ;
         frmManager.selMaster .disabled = false ;
         frmManager.txtDescription .disabled = false ;
         frmManager.selMaster.selectedIndex = -1 ;
         
       }
    else
       {
         if (frmManager.txtForumName .value == ""
            || frmManager.txtForumName .value == "请输入论坛名称" )
           {
             alert("请输入论坛名称") ;
             frmManager.txtForumName .focus () ;
             frmManager.txtForumName .select ();
             return 0 ;
           }     
         
         var ForumName = frmManager.txtForumName .value ;
         
         //增加新的论坛数组成员
         
         //求相关栏目的id
         var RootCategoryID ,CategoryID , OrderNum ;
         for (var i = 0 ; i < aCategory.length ; i ++)
            {
              if ( aCategory[i].CategoryID = frmManager.selCategoryName [frmManager.selCategoryName .selectedIndex ].value )
                {
                    RootCategoryID = aCategory[i].CategoryID ;
                 }
            }
         alert(RootCategoryID) ;
         
        //求CategoryID,取现有数组中最大值
        CategoryID = 0 ;       //赋一个初值
        for (var i = 0 ; i < aForum.length ; i ++)
           {
             if (aForum[i].CategoryID > CategoryID)
               {
                 CategoryID = aForum[i].CategoryID ;
               }
           }
        CategoryID = CategoryID + 1 ;
        
        //求OrderNum , 取现有数组中最大值
        OrderNum = 0 ;
        for (var i = 0 ; i<aForum.length ; i ++)
           {
             if (aForum[i].RootCategoryID == RootCategoryID && aForum[i].OrderNum > OrderNum)
               {

                 OrderNum = aForum[i].OrderNum ;
               }  
           }
        OrderNum = OrderNum + 1 ;
         
        //求版主
        var MasterID = frmManager.selMaster .value ;
        if (MasterID < 1)
          {
            alert("请选择版主。") ;
            frmManager.selMaster .focus() ;
            return false ;
          }  
        //求description
        var Description = frmManager.txtDescription .value ;
        if (Description == "")
           {
             alert("请填写论坛描述。") ;
             frmManager.txtDescription .focus() ;
             return false ;
           }
                     
       
       aForum[aForum.length] = new MakeForum(CategoryID , ForumName , OrderNum , RootCategoryID , Description , MasterID)         
        

         //重新生成
         frmManager.btnAddForum .value     = "增加"
         frmManager.btnSubmit .disabled       = false ;
         frmManager.txtForumName .disabled    = true ;
         frmManager.selMaster .disabled       = true ;
         frmManager.selCategoryName .disabled = false ;
         frmManager.selForumName .disabled    = false ;
         On_CategoryChange() ;

       
       }    
   }   


//第九步,删除论坛   
function On_DeleteForum()
   {
    if (frmManager.selForumName .selectedIndex == -1 )
      {
        return false ;
      }
      
    var bMessage = confirm("真的删除吗?")
    if (!bMessage)
      {
       return false ;
      }
      
    var aTemp = new Array();
    var intForumIndex ;
    var j = 0 ;
    for (var i = 0 ; i < aForum.length ; i ++)
       {
          
         if (aForum[i].CategoryID != frmManager.selForumName [frmManager.selForumName .selectedIndex ].value )
           {
             aTemp[j] = aForum[i] ;            
             j ++ ;     
           }
          
       }
    aForum = aTemp.slice(0) ;
    frmManager.selForumName .selectedIndex = -1 ;
    On_CategoryChange() ;    
         
   }
  

//第十步,删除栏目
function On_DeleteCategory()
   {
     if (frmManager.selCategoryName .selectedIndex == -1)
       {
         return false ;
       }     
     var bMessage = window.confirm ("真的删除这个栏目吗?下面的论坛也会被一起删除!") ;
     if (!bMessage)
        {
          return false ;
        }
     var aTemp = new Array() ;   
     var intCategoryIndex , j ,CategoryID;
     
     //删除栏目
     j = 0 ;
     for (var i = 0 ; i < aCategory.length ; i ++)
        {
          if (aCategory[i].CategoryID == frmManager.selCategoryName [frmManager.selCategoryName . selectedIndex].value )    
            {
              intCategoryIndex = i ;
              CategoryID = aCategory[i].CategoryID ;
            }
          else
            {
                
             aTemp[j] = aCategory[i] ;
             j ++ ;
            }
                
        }
        
      aCategory = aTemp.slice(0) ;        

     //删除相应的论坛
     j = 0 ;
     var aTemp1 = new Array();
     for (var i = 0 ; i < aForum.length ; i ++)
        {
          if (aForum[i].RootCategoryID != CategoryID )
            {
              aTemp1[j] = aForum[i] ;
              j ++ ;
            }
        }      


     aForum = aTemp1.slice(0) ;  
     On_Load() ;   
     On_CategoryChange () ;  

   }    

原文转自:http://www.ltesting.net