(function($){
    var $document = $(document);

    $document.off('initCreatedDesignsOnBuilder');
    $document.on('initCreatedDesignsOnBuilder', function() {
            $document.trigger('getCreatedDesignsByProductId');
    });

    $document.off('getCreatedDesignsByProductId');
    $document.on('getCreatedDesignsByProductId', function(){
        var views_ids = [];
        $document.trigger('builder.getAreaViewsIds', [views_ids]);

        if (views_ids.length > 0) {
            $.coreUtilites.ajaxRequest(
                {
                    subject: 'builder',
                    action: 'get_created_designs',
                    params: {
                        view_ids: views_ids
                    }
                },
                function(data){
                    if (data.status == 'success') {
                        $document.trigger('builder.predesign.recreate', [data.message]);
                    }
                }
            );
        }
    });

})(SWjQuery);