/**
 * Created with JetBrains WebStorm.
 * User: pengshen
 * Date: 14-11-17
 * Time: 下午4:16
 * To change this template use File | Settings | File Templates.
 */
define(function(require, exports) {
    var commands =   require('editor/assert/js/utils/commands').commands
    var AppContext=require('../../../../share/assert/js/appcontext').AppContext;
    var IO = require('../../../../share/assert/js/ioutil_desktop.js').IOUtil;
    fabric.Gif.prototype.showEditDialog=function(opt, finishcallback){
        var _that = this,phtml='',tablecot=null;
        var info = null;
        var _folder =  AppContext.joinPath(Global.CurrentSlide.c.getCurMediaPath(), _that.id);
        var _thumbPath = AppContext.joinPath(_folder,'thumbnail.png');
        IO.writeIMG(_thumbPath,_that.toDataURL()).done(function(e){    //生成png图片，用于在编辑状态显示（因为直接加载gif显示有问题）
            _that._element.src = _thumbPath;    //src更新为显示生成的静态图片
            var _mjson = {cardtype: 'gif', imgSrc:opt.imgSrc, thumbnail:'thumbnail.png', title:''};
            //如果是新建添加一个rid
            if (!_that.rid) {
                info = {
                    "src":  AppContext.joinPath("media", _that.id), "title": "动态图", "des": "", "type": 'dir'
                };
                //push到Relation中避免重复创建
                _that.rid = Global.CurrentSlide.c.addRelationInfo(info);
                _that.setRelInfo(info);
            }
            IO.mkdirp(_folder).done(function (e) {
                if (e) {
                    IO.writeFile(AppContext.joinPath(_folder,'meta.json'), JSON.stringify(_mjson)).done(function (e) {});
                }
            })
            finishcallback && finishcallback.call(_that,null);
        });
    }
    fabric.Gif.prototype.showEditButton = function(opt,finishcallback){
        commands.usePropertyCtrlArea('image');
    }
    fabric.Gif.prototype.hidePropertyButton = function(){
        commands.usePropertyCtrlArea(null);
    }

})