dojox/editor/plugins/AutoSave.js

  • Provides:

    • dojox.editor.plugins.AutoSave
  • dojox.editor.plugins._AutoSaveSettingDialog

    • type
      Function
    • chains:
      • dijit._Widget: (prototype)
      • dijit._Widget: (call)
      • dijit._Templated: (call)
    • mixins:
      • dijit._Templated.prototype: (prototype)
    • summary
  • dojox.editor.plugins._AutoSaveSettingDialog.dialogTitle

    • summary
  • dojox.editor.plugins._AutoSaveSettingDialog.dialogDescription

    • summary
  • dojox.editor.plugins._AutoSaveSettingDialog.paramName

    • summary
  • dojox.editor.plugins._AutoSaveSettingDialog.paramLabel

    • summary
  • dojox.editor.plugins._AutoSaveSettingDialog.btnOk

    • summary
  • dojox.editor.plugins._AutoSaveSettingDialog.btnCancel

    • summary
  • dojox.editor.plugins._AutoSaveSettingDialog.widgetsInTemplate

    • summary
  • dojox.editor.plugins._AutoSaveSettingDialog.templateString

    • summary
  • dojox.editor.plugins._AutoSaveSettingDialog.postMixInProperties

    • type
      Function
    • source: [view]
        this.id = dijit.getUniqueId(this.declaredClass.replace(/\./g,"_"));
        this.dialogId = this.id + "_dialog";
        this.textBoxId = this.id + "_textBox";
    • summary
  • dojox.editor.plugins._AutoSaveSettingDialog.show

    • type
      Function
    • source: [view]
        if(this._value == ""){
         this._value = 0;
         this.intBox.set("value", 0);
        }else{
         this.intBox.set("value", this._value);
        }
        this.dialog.show();
        dijit.selectInputText(this.intBox.focusNode);
    • summary
      Display the setting dialog. If the internal interval value is ""
      set it to zero
    • tags:
  • dojox.editor.plugins._AutoSaveSettingDialog.hide

    • type
      Function
    • source: [view]
      define("dojox/editor/plugins/AutoSave", ["dojo", "dijit", "dojox", "dojo/string", "dojo/date/locale", "dijit/Dialog", "dijit/MenuItem", "dijit.Menu", "dijit/form/Button", "dijit/form/ComboBox", "dijit/form/TextBox", "dijit/TooltipDialog", "dijit/_editor/_Plugin", "dijit/form/Button", "dojo/i18n", "dojox/editor/plugins/Save", "i18n!dojox/editor/plugins/nls/AutoSave"], function(dojo, dijit, dojox) {


      dojo.experimental("dojox.editor.plugins.AutoSave");


      dojo.declare("dojox.editor.plugins._AutoSaveSettingDialog", [dijit._Widget, dijit._Templated], {

       
       // dialogTitle [public] String
       //  The tile of the Auto-Save setting dialog
       dialogTitle: "",

       
       // dialogDescription [public] String
       //  The description of the Auto-Save setting dialog
       dialogDescription: "",

       
       // paramName [public] String
       //  The name of the parameter (Auto-Save Interval)
       paramName: "",

       
       // paramLabel [public] String
       //  Minute
       paramLabel: "",

       
       // btnOk [public] String
       //  The label of the OK button
       btnOk: "",

       
       // btnCancel [public] String
       //  The label of the Cancel button
       btnCancel: "",

       
       widgetsInTemplate: true,

       
       templateString:
        "" +
         "
          "class='dijitEditorAutoSaveSettingDialog'>" +
          "
      ${dialogDescription}
      " +
          "
      ${paramName}
      " +
          "
      " +
           "      "selectOnClick='true' required='true' dojoAttachPoint='intBox' " +
            "dojoAttachEvent='onKeyDown: _onKeyDown, onChange: _onChange'/>" +
           "" +
          "
      " +
          "
      " +
           "" +
           "" +
          "
      " +
         "
      " +
        "
      ",

       
       postMixInProperties: function(){
        this.id = dijit.getUniqueId(this.declaredClass.replace(/\./g,"_"));
        this.dialogId = this.id + "_dialog";
        this.textBoxId = this.id + "_textBox";
       },

       
       show: function(){
        // summary:
        //  Display the setting dialog. If the internal interval value is ""
        //  set it to zero
        // tags:
        //  public
        if(this._value == ""){
         this._value = 0;
         this.intBox.set("value", 0);
        }else{
         this.intBox.set("value", this._value);
        }
        this.dialog.show();
        dijit.selectInputText(this.intBox.focusNode);
       },

       
       hide: function(){
        // summray:
        //  Hide the setting dialog.
        // tags:
        //  public
        this.dialog.hide();
    • summary
  • dojox.editor.plugins._AutoSaveSettingDialog.onOk

    • type
      Function
    • source: [view]
        this.dialog.hide();
    • summary
      Handle the OK event and close the dialog.
    • tags:
  • dojox.editor.plugins._AutoSaveSettingDialog.onCancel

    • type
      Function
    • source: [view]
        this.dialog.hide();
    • summary
      Handle the Cancel event and close the dialog.
    • tags:
  • dojox.editor.plugins._AutoSaveSettingDialog._onKeyDown

    • type
      Function
    • parameters:
      • evt: (typeof )
    • source: [view]
        if(evt.keyCode == dojo.keys.ENTER){
         this.onOk();
        }
    • summary
      Handle the keydown event
    • tags:
  • dojox.editor.plugins._AutoSaveSettingDialog._onChange

    • type
      Function
    • parameters:
      • val: (typeof String)
    • source: [view]
        if(this._isValidValue(val)){
         this._value = val;
        }else{
         this.intBox.set("value", this._value);
        }
    • summary
      Check if the value is between 1 - 999.
    • tags:
  • dojox.editor.plugins._AutoSaveSettingDialog._setValueAttr

    • type
      Function
    • parameters:
      • val: (typeof String)
        The invertal value
    • source: [view]
        if(this._isValidValue(val)){
         this._value = val;
        }
    • summary
      Set the value attribute if it is acceptable
    • tags:
  • dojox.editor.plugins._AutoSaveSettingDialog._getValueAttr

    • type
      Function
    • source: [view]
        return this._value;
    • summary
      Get the interval value
    • tags:
  • dojox.editor.plugins._AutoSaveSettingDialog._isValidValue

    • type
      Function
    • parameters:
      • val: (typeof String)
    • source: [view]
        var regExp = /^\d{0,3}$/,
         _v = String(val);
        return Boolean(_v.match ? _v.match(regExp) : "");
    • summary
      Check if this value between 1- 999
    • tags:
  • dojox.editor.plugins._AutoSaveSettingDialog.id

    • summary
  • dojox.editor.plugins._AutoSaveSettingDialog.dialogId

    • summary
  • dojox.editor.plugins._AutoSaveSettingDialog.textBoxId

    • summary
  • dojox.editor.plugins._AutoSaveSettingDialog._value

    • summary
  • dojox.editor.plugins.AutoSave

    • type
      Function
    • chains:
      • dojox.editor.plugins.Save: (prototype)
      • dojox.editor.plugins.Save: (call)
    • summary
      This plugin provides the auto save capability to the editor. The
      plugin saves the content of the editor in interval. When
      the save action is performed, the document in the editor frame
      will be posted to the URL provided, or none, if none provided.
      
      url [public]	String
      The URL to POST the content back to.  Used by the save function.
  • dojox.editor.plugins.AutoSave.url

    • summary
  • dojox.editor.plugins.AutoSave.logResults

    • summary
  • dojox.editor.plugins.AutoSave.interval

    • summary
  • dojox.editor.plugins.AutoSave._iconClassPrefix

    • summary
  • dojox.editor.plugins.AutoSave._MIN

    • summary
  • dojox.editor.plugins.AutoSave._setIntervalAttr

    • type
      Function
    • parameters:
      • val: (typeof The)
        interval value.
    • source: [view]
        this.interval = val;
    • summary
      Set the interval value.
      Delay the boundary check to _isValidValue of the dialog class
    • tags:
  • dojox.editor.plugins.AutoSave._getIntervalAttr

    • type
      Function
    • source: [view]
        return this._interval;
    • summary
      Get the interval value
    • tags:
  • dojox.editor.plugins.AutoSave.setEditor

    • type
      Function
    • parameters:
      • editor: (typeof Object)
        The editor to configure for this plugin to use.
    • source: [view]
        this.editor = editor;
        this._strings = dojo.i18n.getLocalization("dojox.editor.plugins", "AutoSave");
        this._initButton();

        
        this._saveSettingDialog = new dojox.editor.plugins._AutoSaveSettingDialog({
         "dialogTitle": this._strings["saveSettingdialogTitle"],
         "dialogDescription": this._strings["saveSettingdialogDescription"],
         "paramName": this._strings["saveSettingdialogParamName"],
         "paramLabel": this._strings["saveSettingdialogParamLabel"],
         "btnOk": this._strings["saveSettingdialogButtonOk"],
         "btnCancel": this._strings["saveSettingdialogButtonCancel"]
        });
        this.connect(this._saveSettingDialog, "onOk", "_onDialogOk");

        
        var pd = this._promDialog = new dijit.TooltipDialog();
        pd.startup();
        pd.set("content", "");
    • summary
      Over-ride for the setting of the editor. No toggle button for
      this plugin. And start to save the content of the editor in
      interval
  • dojox.editor.plugins.AutoSave._initButton

    • type
      Function
    • source: [view]
        var menu = new dijit.Menu({
          style: "display: none"
         }),
         menuItemSave = new dijit.MenuItem({
          iconClass: this._iconClassPrefix + "Default " + this._iconClassPrefix,
          label: this._strings["saveLabel"]
         }),
         menuItemAutoSave = this._menuItemAutoSave = new dijit.MenuItem({
          iconClass: this._iconClassPrefix + "Setting " + this._iconClassPrefix,
          label: this._strings["saveSettingLabelOn"]
         });

         
        menu.addChild(menuItemSave);
        menu.addChild(menuItemAutoSave);
        this.button = new dijit.form.ComboButton({
         label: this._strings["saveLabel"],
         iconClass: this._iconClassPrefix + "Default " + this._iconClassPrefix,
         showLabel: false,
         dropDown: menu
        });

        
        this.connect(this.button, "onClick", "_save");
        this.connect(menuItemSave, "onClick", "_save");
        this._menuItemAutoSaveClickHandler = dojo.connect(menuItemAutoSave, "onClick", this, "_showAutSaveSettingDialog");
    • summary
  • dojox.editor.plugins.AutoSave._showAutSaveSettingDialog

    • type
      Function
    • source: [view]
        var dialog = this._saveSettingDialog;
        dialog.set("value", this.interval);
        dialog.show();
    • summary
      Show the setting dialog
    • tags:
  • dojox.editor.plugins.AutoSave._onDialogOk

    • type
      Function
    • source: [view]
        var interval = this.interval = this._saveSettingDialog.get("value") * this._MIN;
        if(interval > 0){
         this._setSaveInterval(interval);
         // Change the menu "Set Auto-Save Interval..." to "Turn off Auto-Save"
         // Connect it to another handler that terminates the auto-save.
         dojo.disconnect(this._menuItemAutoSaveClickHandler);
         this._menuItemAutoSave.set("label", this._strings["saveSettingLabelOff"]);
         this._menuItemAutoSaveClickHandler = dojo.connect(this._menuItemAutoSave, "onClick", this, "_onStopClick");
         // Change the icon of the main button to auto-save style
         this.button.set("iconClass", this._iconClassPrefix + "Setting " + this._iconClassPrefix);
        }
    • summary
      If the interval is set (larger than 0), enable auto-save.
    • tags:
  • dojox.editor.plugins.AutoSave._onStopClick

    • type
      Function
    • source: [view]
        this._clearSaveInterval();
        // Change the menu "Turn off Auto-Save" to "Set Auto-Save Interval...".
        // Connect it to another handler that show the setting dialog.
        dojo.disconnect(this._menuItemAutoSaveClickHandler);
        this._menuItemAutoSave.set("label", this._strings["saveSettingLabelOn"]);
        this._menuItemAutoSaveClickHandler = dojo.connect(this._menuItemAutoSave, "onClick", this, "_showAutSaveSettingDialog");
        // Change the icon of the main button
        this.button.set("iconClass", this._iconClassPrefix + "Default " + this._iconClassPrefix);
    • summary
      Stop auto-save
    • tags:
  • dojox.editor.plugins.AutoSave._setSaveInterval

    • type
      Function
    • parameters:
      • interval: (typeof Number)
    • source: [view]
        if(interval <= 0){
         return;
        }
        this._clearSaveInterval();
        this._intervalHandler = setInterval(dojo.hitch(this, function(){
               if(!this._isWorking && !this.get("disabled")){
                // If the plugin is not disabled (ViewSource, etc.)
                // and not working. Do saving!
                this._isWorking = true;
                this._save();
               }
              }), interval);
    • summary
      Function to trigger saving of the editor document
    • tags:
  • dojox.editor.plugins.AutoSave._clearSaveInterval

    • type
      Function
    • source: [view]
        if(this._intervalHandler){
         clearInterval(this._intervalHandler);
         this._intervalHandler = null;
        }
    • summary
  • dojox.editor.plugins.AutoSave.onSuccess

    • type
      Function
    • parameters:
      • resp: (typeof The)
        response from the server, if any, in text format.
      • ioargs: (typeof )
    • source: [view]
        this.button.set("disabled", false);
        // Show the successful message
        this._promDialog.set("content", dojo.string.substitute(
           this._strings["saveMessageSuccess"], {"0": dojo.date.locale.format(new Date(), {selector: "time"})}));
          dijit.popup.open({popup: this._promDialog, around: this.button.domNode});
          this._promDialogTimeout = setTimeout(dojo.hitch(this, function(){
           clearTimeout(this._promDialogTimeout);
           this._promDialogTimeout = null;
           dijit.popup.close(this._promDialog);
          }), 3000);
        this._isWorking = false;
        if(this.logResults){
         console.log(resp);
        }
    • summary
      User over-ridable save success function for editor content.
    • tags:
  • dojox.editor.plugins.AutoSave.onError

    • type
      Function
    • parameters:
      • error: (typeof )
      • ioargs: (typeof )
    • source: [view]
        this.button.set("disabled", false);
        // Show the failure message
        this._promDialog.set("content", dojo.string.substitute(
           this._strings["saveMessageFail"], {"0": dojo.date.locale.format(new Date(), {selector: "time"})}));
          dijit.popup.open({popup: this._promDialog, around: this.button.domNode});
          this._promDialogTimeout = setTimeout(dojo.hitch(this, function(){
           clearTimeout(this._promDialogTimeout);
           this._promDialogTimeout = null;
           dijit.popup.close(this._promDialog);
          }), 3000);
        this._isWorking = false;
        if(this.logResults){
         console.log(error);
        }
    • summary
      User over-ridable save success function for editor content.
      resp:
      The response from the server, if any, in text format.
    • tags:
  • dojox.editor.plugins.AutoSave.destroy

    • type
      Function
    • source: [view]
        this.inherited(arguments);

        
        this._menuItemAutoSave = null;

        
        if(this._promDialogTimeout){
         clearTimeout(this._promDialogTimeout);
         this._promDialogTimeout = null;
         dijit.popup.close(this._promDialog);
        }

        
        this._clearSaveInterval();

        
        if(this._saveSettingDialog){
         this._saveSettingDialog.destroyRecursive();
         this._destroyRecursive = null;
        }

        
        if(this._menuItemAutoSaveClickHandler){
         dojo.disconnect(this._menuItemAutoSaveClickHandler);
         this._menuItemAutoSaveClickHandler = null;
        }
    • summary
      Cleanup of our plugin.
  • dojox.editor.plugins.AutoSave.editor

    • summary
  • dojox.editor.plugins.AutoSave._strings

    • summary
  • dojox.editor.plugins.AutoSave._saveSettingDialog

    • summary
  • dojox.editor.plugins.AutoSave._promDialog

    • summary
  • dojox.editor.plugins.AutoSave.setEditor.editor

    • type
      Object
    • summary
      The editor to configure for this plugin to use.
  • dojox.editor.plugins.AutoSave._menuItemAutoSave

    • summary
  • dojox.editor.plugins.AutoSave.button

    • summary
  • dojox.editor.plugins.AutoSave._menuItemAutoSaveClickHandler

    • summary
  • dojox.editor.plugins.AutoSave._intervalHandler

    • summary
  • dojox.editor.plugins.AutoSave._isWorking

    • summary
  • dojox.editor.plugins.AutoSave._promDialogTimeout

    • summary
  • dojox.editor.plugins.AutoSave._destroyRecursive

    • summary
  • name

    • summary
  • o.plugin

    • summary
  • dojox.editor.plugins

    • type
      Object
    • summary
  • dojox.editor

    • type
      Object
    • summary
  • dojox

    • type
      Object
    • summary