首頁

2013年6月5日 星期三

**源碼分享---六**~^

**源碼分享---六**~^













1).*文本框輸入限制樣本 *
**Textbox input*restriction sample**
*<textbox id="telNo" xmlns:w="client" >
  <attribute w:name="doKeyPress_">
    function(evt){
         if(this.getValue().length > 0 ){
           if (!this._shallIgnore(evt, "0123456789"))
              this.$doKeyPress_(evt);
         }else{
           if (!this._shallIgnore(evt, "05"))
              this.$doKeyPress_(evt);
         }
    }
  </attribute>
</textbox>


***************************************************************

2).*CkEDITOR*源模式啟動**
**ckeditor statup withsource mode**
*<zk xmlns:w="http://www.zkoss.org/2005/zk/client">
 <ckeditor>
  <attribute w:name="bind_">
   function () {
    // set the startup mode
    CKEDITOR.config.startupMode = 'source';
    //call the original method
    this.$bind_();
   }
  </attribute>
 </ckeditor>
</zk>



***********************************************************************


3).*Access all list item**
*訪問所有列表項**
*<?init class="org.zkoss.zkplus.databind.AnnotateDataBinderInit"?>
<zk>
  <div apply="org.zkoss.bind.BindComposer" viewModel="@id('vm') @init('pkg$.test')" onCreate="@command('Cargar')">
 <listbox id="oListBox" model="@load(vm.persons)" height="200px" mold="paging" autopaging="true">
  <listhead>
   <listheader label="First Name" />
   <listheader label="Last Name" />
  </listhead>
          <template name="model" var="item">
  <listitem>
   <listcell label="@load(item.firstName)"/>   
   <listcell label="@load(item.lastName)"/>
  </listitem>  
          </template>
 </listbox>
 <button label="test">
         <attribute name="onClick">
                  StringBuilder sb = new StringBuilder("");
                   oListBox.renderAll();
                  alert("items->"+oListBox.getItemCount());
               for (Object item : oListBox.getItems()) {
         String i = "";
         for (Object cell : ((Listitem) item).getChildren()) {
          //Solo mostramos las celdas que estén visibles
          if(((Listcell)cell).getListheader()!=null){
            if(((Listcell)cell).getListheader().isVisible()){
             i += ((Listcell) cell).getLabel() + ";";
            }
           }
          }
          sb.append(i + "\r\n");
         }
                  lb.setValue(sb.toString());
         </attribute>
 </button>
 <textbox rows="6" width="300px" id="lb" value="message: " />
</div>
</zk>



************************************************************************


**4).*Enable multiple gods on one system** run by non-root users. **~
**在一個系統**啟用多神模式**非root用戶**運行**
*a)))lib/god.rb )
161    # permissions will be used.
162 162    PID_FILE_DIRECTORY_
DEFAULTS =
['/var/run/god', '~/.god/pids']
163 163  
  164 +  # Array of directory paths to be
 used for the socket file. 
  165 +  # This list will be
searched in order
and the first one that has write 
  166 +  # permission will be used.
  167 +  SOCKET_FILE_
DIRECTORY_DEFAULTS
= ['/var/run/god', '~/.god/sockets']
  168 +  
164 169    # The default Integer port
 number for the
DRb communcations channel.
165 170    DRB_PORT_DEFAULT
 = 17165
166 171  
... ... @@ -188,6 +193,7 @@
class << self
188 193                         :allow,
189 194                         :log_buffer_size,
190 195                         :pid_file_directory,
  196 +                       :socket_file_
directory,
191 197                         :log_file,
192 198                         :log_level,
193 199                         :use_events,
... ... @@ -216,6 +222,7 @@
class << self
216 222    self.allow = nil
217 223    self.log_buffer_size = nil
218 224    self.pid_file_directory = nil
  225 +  self.socket_file_directory = nil
219 226    self.log_level = nil
220 227    self.terminate_timeout = nil
221 228    self.socket_user = nil
... ... @@ -629,51 +636,64 @@
 def self.load(glob)
629 636        Kernel.load f
630 637      end
631 638    end
  639 +  
  640 +  # Setup pid and socket
 file directories,
 and log system.
  641 +  #
  642 +  # Returns nothing
  643 +  def self.setup
  644 +    self.setup_special_file_
directory(PID_
FILE_DIRECTORY_
DEFAULTS, :pid_file_directory)
  645 +    self.setup_special_file_
directory(SOCKET_
FILE_DIRECTORY_
DEFAULTS, :socket_file_directory)
  646 +    
  647 +    if God::Logger.syslog
  648 +      LOG.info("Syslog enabled.")
 if self.log_level
  649 +    else
  650 +      LOG.info("Syslog disabled.")
 if self.log_level
  651 +    end
  652 +  end
632 653  
633   -  # Setup pid file directory
and log system.
  654 +  # Setup special file directory
(pid and socket
at this point)
  655 +  # Requires an array of
directories to try, and
a symbol for the 
  656 +  # corresponding attribute
on this class object.
634 657    #
635 658    # Returns nothing.
636   -  def self.setup
637   -    if self.pid_file_directory
638   -      # Pid file dir was
specified, ensure it is
created and writable.
639   -      unless File.exist?
(self.pid_file_directory)
  659 +  def self.setup_
special_file_directory
(default_directories,
special_file_directory_attribute)
  660 +    special_file_directory =
self.send(special_file_
directory_attribute)
  661 +    nice_directory_text =
 special_file_directory_
attribute.to_s.gsub("_"," ")
  662 +    
  663 +    if special_file_directory
  664 +      # Special file dir was
 specified, ensure it is
 created and writable.
  665 +      unless File.exist?
(special_file_directory)
640 666          begin
641   -          FileUtils.mkdir_p
(self.pid_file_directory)
  667 +          FileUtils.mkdir_p
(special_file_directory)
642 668          rescue Errno::EACCES => e
643   -          abort "Failed to create

pid file directory:
 #{e.message}"
  669 +          abort "Failed to create #
{nice_directory_text}:
 #{e.message}"
644 670          end
645 671        end
646 672  
647   -      unless File.writable?
(self.pid_file_directory)
648   -        abort "The pid file directory
 (#{self.pid_file_directory}) is
not writable by #{Etc.getlogin}"
  673 +      unless File.writable?(special
_file_directory)
  674 +        abort "The pid file directory
 (#{special_file_directory}) is
not writable by #{Etc.getlogin}"
649 675        end
650 676      else
651   -      # No pid file dir specified, try defaults.
652   -      PID_FILE_DIRECTORY_
DEFAULTS.each do |idir|
  677 +      # No special file dir specified,
 try defaults.
  678 +      default_directories.each do |idir|
653 679          dir = File.expand_path(idir)
654 680          begin
655 681            FileUtils.mkdir_p(dir)
656 682            if File.writable?(dir)
657   -            self.pid_file_directory = dir
  683 +            self.send("#{special_
file_directory_
attribute}=".to_sym,dir)
658 684              break
659 685            end
660 686          rescue Errno::EACCES => e
661 687          end
662 688        end
663 689  
664   -      unless self.pid_file_directory
665   -        dirs = PID_FILE_DIRECTORY_
DEFAULTS.map { |x| File.
expand_path(x) }
666   -        abort "No pid file directory exists,
could be created, or is writable
 at any of #{dirs.join(', ')}"
  690 +      unless self.send(special_file_
directory_attribute)
  691 +        dirs = default_directories.map

 { |x| File.expand_path(x) }
  692 +        abort "No #{nice_directory_text}
exists, could be
created, or is writable at any
 of #{dirs.join(', ')}"
667 693        end
668 694      end
669   -
670   -    if God::Logger.syslog
671   -      LOG.info("Syslog enabled.")
672   -    else
673   -      LOG.info("Syslog disabled.")
674   -    end
675   -
676   -    applog(nil, :info, "Using pid
 file directory: #{self.pid_file_directory}")
  695 +    
  696 +    applog(nil, :info, "Using #{nice_
directory_text}: #{self.send(special_file_directory_attribute)}")
if self.log_level
677 697    end
678 698  
679 699    # Initialize and startup the
 machinery that makes god work.


*********************&&& next b

**b*lib/god.rb *
*
... ... @@ -11,10 +11,10 @@ def initialize(command, options, args)
11 11        end
12 12  
13 13        def setup
  14 +        God.setup #necessary to set the proper socket file.
14 15          # connect to drb unix socket
15 16          DRb.start_service("druby://127.0.0.1:0")
16 17          @server = DRbObject.new(nil, God::
Socket.socket(@options[:port]))
17   -
18 18          # ping server to ensure that it is responsive
19 19          begin
20 20            @server.ping

**lib/god.rb *
... ... @@ -11,7 +11,7 @@ class Socket
11 11      #
12 12      # Returns String (file location)
13 13      def self.socket_file(port)
14   -      "/tmp/god.#{port}.sock"
  14 +      "#{God.socket_file_directory}/god.#{port}.sock"
15 15      end
16 16  
17 17      # The address of the socket for a given port


*****************************************************************************************
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&







沒有留言:

張貼留言


if you like make fds, wellcome you here~~anytime***

my free place for everyones who want the good software,

come & download them~ wellcome!!