123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146 |
- if(!dojo._hasResource["dojox.editor.plugins.Save"]){
- dojo._hasResource["dojox.editor.plugins.Save"] = true;
- dojo.provide("dojox.editor.plugins.Save");
- dojo.require("dijit.form.Button");
- dojo.require("dijit._editor._Plugin");
- dojo.require("dojo.i18n");
- dojo.requireLocalization("dojox.editor.plugins", "Save", null, "ROOT,ar,bg,ca,cs,da,de,el,es,fi,fr,he,hr,hu,it,ja,kk,ko,nb,nl,pl,pt,pt-pt,ro,ru,sk,sl,sv,th,tr,zh,zh-tw");
- dojo.declare("dojox.editor.plugins.Save",dijit._editor._Plugin,{
-
-
-
-
-
-
-
-
-
- iconClassPrefix: "dijitAdditionalEditorIcon",
-
-
- url: "",
-
-
-
- logResults: true,
- _initButton: function(){
-
-
- var strings = dojo.i18n.getLocalization("dojox.editor.plugins", "Save");
- this.button = new dijit.form.Button({
- label: strings["save"],
- showLabel: false,
- iconClass: this.iconClassPrefix + " " + this.iconClassPrefix + "Save",
- tabIndex: "-1",
- onClick: dojo.hitch(this, "_save")
- });
- },
-
- updateState: function(){
-
-
- this.button.set("disabled", this.get("disabled"));
- },
- setEditor: function(editor){
-
-
-
-
- this.editor = editor;
- this._initButton();
- },
- _save: function(){
-
-
-
-
- var content = this.editor.get("value");
- this.save(content);
- },
- save: function(content){
-
-
-
-
-
-
-
-
- var headers = {
- "Content-Type": "text/html"
- };
- if(this.url){
- var postArgs = {
- url: this.url,
- postData: content,
- headers: headers,
- handleAs: "text"
- };
- this.button.set("disabled", true);
- var deferred = dojo.xhrPost(postArgs);
- deferred.addCallback(dojo.hitch(this, this.onSuccess));
- deferred.addErrback(dojo.hitch(this, this.onError));
- }else{
- console.log("No URL provided, no post-back of content: " + content);
- }
- },
- onSuccess: function(resp, ioargs){
-
-
-
-
-
-
-
- this.button.set("disabled", false);
- if(this.logResults){
- console.log(resp);
- }
- },
- onError: function(error, ioargs){
-
-
-
-
-
-
-
- this.button.set("disabled", false);
- if(this.logResults){
- console.log(error);
- }
- }
- });
- dojo.subscribe(dijit._scopeName + ".Editor.getPlugin",null,function(o){
- if(o.plugin){ return; }
- var name = o.args.name.toLowerCase();
- if(name === "save"){
- o.plugin = new dojox.editor.plugins.Save({
- url: ("url" in o.args)?o.args.url:"",
- logResults: ("logResults" in o.args)?o.args.logResults:true
- });
- }
- });
- }
|