OSDN Git Service

pull
authoryasushiito <yas@pen-chan.jp>
Sat, 16 May 2015 05:57:31 +0000 (14:57 +0900)
committeryasushiito <yas@pen-chan.jp>
Sat, 16 May 2015 05:57:31 +0000 (14:57 +0900)
29 files changed:
app/assets/javascripts/backbone.fetch-cache.js
app/assets/javascripts/locmare/form/field/tag/file.js.coffee
app/assets/javascripts/models/balloon.js.coffee
app/assets/javascripts/models/panel_picture.js.coffee
app/assets/javascripts/views/original_pictures/form.js.coffee
app/controllers/application_controller.rb
app/controllers/artists_controller.rb
app/controllers/authors_controller.rb
app/controllers/comic_stories_controller.rb
app/controllers/comics_controller.rb
app/controllers/folders_controller.rb
app/controllers/license_groups_controller.rb
app/controllers/licenses_controller.rb
app/controllers/original_pictures_controller.rb
app/controllers/panels_controller.rb
app/controllers/resource_pictures_controller.rb
app/controllers/scroll_panels_controller.rb
app/controllers/scrolls_controller.rb
app/controllers/sheets_controller.rb
app/controllers/speech_balloon_templates_controller.rb
app/controllers/stories_controller.rb
app/controllers/story_sheets_controller.rb
app/controllers/writing_formats_controller.rb
app/models/picture.rb
db/migrate/20150330232549_create_resource_picture_pictures.rb
db/migrate/20150516051015_rpp_id_allow_null.rb [new file with mode: 0644]
lib/peta/binder.rb
lib/peta/leaf.rb
lib/peta/root.rb

index 7bff9aa..ead7c11 100644 (file)
@@ -11,7 +11,7 @@
     define(['underscore', 'backbone', 'jquery'], function (_, Backbone, $) {
       return (root.Backbone = factory(_, Backbone, $));
     });
-  } else if (typeof exports !== 'undefined') {
+  } else if (typeof exports !== 'undefined' && typeof require !== 'undefined') {
     module.exports = factory(require('underscore'), require('backbone'), require('jquery'));
   } else {
     // Browser globals
   }
 
   // Shared methods
-  function getCacheKey(instance, opts) {
-    var url;
-
-    if(opts && opts.url) {
-      url = opts.url;
-    } else {
-      url = _.isFunction(instance.url) ? instance.url() : instance.url;
+  function getCacheKey(key, opts) {
+    if (key && _.isObject(key)) {
+      // If the model has its own, custom, cache key function, use it.
+      if (_.isFunction(key.getCacheKey)) {
+        return key.getCacheKey(opts);
+      }
+      // else, use the URL
+      if (opts && opts.url) {
+        key = opts.url;
+      } else {
+        key = _.isFunction(key.url) ? key.url() : key.url;
+      }
+    } else if (_.isFunction(key)) {
+      return key(opts);
     }
-
-    // Need url to use as cache key so return if we can't get it
-    if(!url) { return; }
-
-    if(opts && opts.data) {
+    if (opts && opts.data) {
       if(typeof opts.data === 'string') {
-        return url + '?' + opts.data;
+        return key + '?' + opts.data;
       } else {
-        return url + '?' + $.param(opts.data);
+        return key + '?' + $.param(opts.data);
       }
     }
-    return url;
+    return key;
   }
 
   function setCache(instance, opts, attrs) {
     opts = (opts || {});
     var key = Backbone.fetchCache.getCacheKey(instance, opts),
-        expires = false;
+        expires = false,
+        lastSync = (opts.lastSync || (new Date()).getTime()),
+        prefillExpires = false;
 
     // Need url to use as cache key so return if we can't get it
     if (!key) { return; }
       expires = (new Date()).getTime() + ((opts.expires || 5 * 60) * 1000);
     }
 
+    if (opts.prefillExpires !== false) {
+      prefillExpires = (new Date()).getTime() + ((opts.prefillExpires || 5 * 60) * 1000);
+    }
+
     Backbone.fetchCache._cache[key] = {
       expires: expires,
+      lastSync : lastSync,
+      prefillExpires: prefillExpires,
       value: attrs
     };
 
     Backbone.fetchCache.setLocalStorage();
   }
 
-  function clearItem(key) {
-    if (_.isFunction(key)) { key = key(); }
+  function getCache(key, opts) {
+    if (_.isFunction(key)) {
+      key = key();
+    } else if (key && _.isObject(key)) {
+      key = getCacheKey(key, opts);
+    }
+
+    return Backbone.fetchCache._cache[key];
+  }
+
+  function getLastSync(key, opts) {
+    return getCache(key).lastSync;
+  }
+
+  function clearItem(key, opts) {
+    if (_.isFunction(key)) {
+      key = key();
+    } else if (key && _.isObject(key)) {
+      key = getCacheKey(key, opts);
+    }
     delete Backbone.fetchCache._cache[key];
     Backbone.fetchCache.setLocalStorage();
   }
+  
+  function reset() {
+    // Clearing all cache items
+    Backbone.fetchCache._cache = {};
+  }
 
   function setLocalStorage() {
     if (!supportLocalStorage || !Backbone.fetchCache.localStorage) { return; }
       localStorage.setItem(Backbone.fetchCache.getLocalStorageKey(), JSON.stringify(Backbone.fetchCache._cache));
     } catch (err) {
       var code = err.code || err.number || err.message;
-      if (code === 22) {
+      if (code === 22 || code === 1014) {
         this._deleteCacheWithPriority();
       } else {
         throw(err);
     }
     opts = _.defaults(opts || {}, { parse: true });
     var key = Backbone.fetchCache.getCacheKey(this, opts),
-        data = Backbone.fetchCache._cache[key],
+        data = getCache(key),
         expired = false,
+        prefillExpired = false,
         attributes = false,
         deferred = new $.Deferred(),
         self = this;
 
+    function isPrefilling() {
+      return opts.prefill && (!opts.prefillExpires || prefillExpired);
+    }
+
     function setData() {
       if (opts.parse) {
         attributes = self.parse(attributes, opts);
       self.trigger('sync', self, attributes, opts);
 
       // Notify progress if we're still waiting for an AJAX call to happen...
-      if (opts.prefill) { deferred.notify(self); }
+      if (isPrefilling()) { deferred.notify(self); }
       // ...finish and return if we're not
       else {
         if (_.isFunction(opts.success)) { opts.success(self, attributes, opts); }
     if (data) {
       expired = data.expires;
       expired = expired && data.expires < (new Date()).getTime();
+      prefillExpired = data.prefillExpires;
+      prefillExpired = prefillExpired && data.prefillExpires < (new Date()).getTime();
       attributes = data.value;
     }
 
         setData();
       }
 
-      if (!opts.prefill) {
+      if (!isPrefilling()) {
         return deferred;
       }
     }
 
     opts = _.defaults(opts || {}, { parse: true });
     var key = Backbone.fetchCache.getCacheKey(this, opts),
-        data = Backbone.fetchCache._cache[key],
+        data = getCache(key),
         expired = false,
+        prefillExpired = false,
         attributes = false,
         deferred = new $.Deferred(),
         self = this;
 
+    function isPrefilling() {
+      return opts.prefill && (!opts.prefillExpires || prefillExpired);
+    }
+
     function setData() {
       self[opts.reset ? 'reset' : 'set'](attributes, opts);
       if (_.isFunction(opts.prefillSuccess)) { opts.prefillSuccess(self); }
       self.trigger('sync', self, attributes, opts);
 
       // Notify progress if we're still waiting for an AJAX call to happen...
-      if (opts.prefill) { deferred.notify(self); }
+      if (isPrefilling()) { deferred.notify(self); }
       // ...finish and return if we're not
       else {
         if (_.isFunction(opts.success)) { opts.success(self, attributes, opts); }
     if (data) {
       expired = data.expires;
       expired = expired && data.expires < (new Date()).getTime();
+      prefillExpired = data.prefillExpires;
+      prefillExpired = prefillExpired && data.prefillExpires < (new Date()).getTime();
       attributes = data.value;
     }
 
         setData();
       }
 
-      if (!opts.prefill) {
+      if (!isPrefilling()) {
         return deferred;
       }
     }
 
   Backbone.fetchCache._superMethods = superMethods;
   Backbone.fetchCache.setCache = setCache;
+  Backbone.fetchCache.getCache = getCache;
   Backbone.fetchCache.getCacheKey = getCacheKey;
+  Backbone.fetchCache.getLastSync = getLastSync;
   Backbone.fetchCache.clearItem = clearItem;
+  Backbone.fetchCache.reset = reset;
   Backbone.fetchCache.setLocalStorage = setLocalStorage;
   Backbone.fetchCache.getLocalStorage = getLocalStorage;
 
index 5445b39..30a15e9 100644 (file)
@@ -1,11 +1,16 @@
 class Locmare.FormModule.FieldModule.TagModule.FileTag extends Locmare.FormModule.FieldModule.TagModule.Base\r
   tagName: 'input'\r
+  events: {\r
+    'change': 'change'\r
+  }\r
   \r
   render: () ->\r
     this.$el.html('')\r
     this.$el.attr(@attr())\r
     this\r
   \r
+  change: (event) ->\r
+  \r
   type: () ->\r
     'file'\r
   \r
index f50e03b..acfae1f 100644 (file)
@@ -55,7 +55,4 @@ class Pettanr.Balloon extends Peta.Element
     super(attr, options)\r
     if @id\r
       @url = @url + @id\r
-    @bind('change:width', () ->\r
-      console.log('cng')\r
-    )\r
   \r
index a06cc14..d46c1ff 100644 (file)
@@ -81,9 +81,6 @@ class Pettanr.PanelPicture extends Peta.Element
     super(attr, options)\r
     if @id\r
       @url = @url + @id\r
-    @bind('change:width', () ->\r
-      console.log('cng')\r
-    )\r
   \r
 class Pettanr.PanelPicture.TraceFromPicture\r
   \r
index 40c739e..0dab4a8 100644 (file)
@@ -21,19 +21,18 @@ class Pettanr.Views.OriginalPicture.Form extends Locmare.Form
       })\r
   \r
   save: () ->\r
-    @listenTo(@item, 'save:success', @success)\r
-    @listenTo(@item, 'save:fail', @fail)\r
-    form_data = new FormData(this.$el.get(0))\r
     attrs = {}\r
-    _.each @fields, (field) =>\r
-      if field.field_manifest.tag.type == 'file'\r
-        form_data.append('original_picture[file]', field.tag.$el[0].files[0])\r
-      else\r
-        form_data.append(field.field_name, field.val())\r
+    form_data = new FormData(this.$el.get(0))\r
     options = {\r
       data: form_data,\r
       processData: false,\r
-      contentType: false\r
+      contentType: false,\r
+      success: (model, response, options) =>\r
+        @item = new Pettanr.OriginalPicture(model)\r
+        @trigger('success', model, response)\r
+      error: (model, response, options) =>\r
+        @item = new Pettanr.OriginalPicture(model)\r
+        @trigger('fail', model, response)\r
     }\r
-    @item.save(null, {}, options)\r
+    Backbone.sync('create', @item, options)\r
   \r
index e79e4f2..9072fb3 100644 (file)
@@ -383,7 +383,7 @@ class ApplicationController < ActionController::Base
     }
   end
   
-  def render_destroy redirect_url = nil
+  def render_destroy redirect_url
     if @item.destroy
       respond_to do |format|
         destroyed_html_format format, redirect_url
@@ -397,6 +397,20 @@ class ApplicationController < ActionController::Base
     end
   end
   
+  def render_destroy_by destroy_method_name, redirect_url = nil
+    if @item.__send__(destroy_method_name)
+      respond_to do |format|
+        destroyed_html_format format, redirect_url
+        destroyed_json_format format
+      end
+    else
+      respond_to do |format|
+        not_destroyed_html_format format
+        not_destroyed_json_format format
+      end
+    end
+  end
+  
   def format_filer format
     format.html {
       @paginate = @@model.list_paginate(@page, @page_size)
index 492e4ce..e5e582d 100644 (file)
@@ -53,12 +53,9 @@ class ArtistsController < ApplicationController
   end
   
   def destroy
-    @artist = Artist.edit(params[:id], @operators)
-    @artist.destroy
-    
-    respond_to do |format|
-      format.html { redirect_to artists_url }
-      format.json { head :ok }
-    end
+    set_model
+    @item = @my_model_class.edit(params[:id], @operators)
+    render_destroy '/home/configure'
   end
+  
 end
index e5e5c46..2b01c91 100644 (file)
@@ -49,4 +49,11 @@ class AuthorsController < ApplicationController
     @item.overwrite @operators
     render_update '/home/configure'
   end
+  
+  def destroy
+    set_model
+    @item = @my_model_class.edit(params[:id], @operators)
+    render_destroy '/home/configure'
+  end
+  
 end
index 839b469..54ac355 100644 (file)
@@ -73,18 +73,10 @@ class ComicStoriesController < ApplicationController
   end
   
   def destroy
-    @comic_story = ComicStory.edit(params[:id], @operators)
-    @comic = Comic.edit(@comic_story.comic_id, @operators) if @comic_story.comic_id
-    respond_to do |format|
-      if @comic_story.destroy_and_shorten
-        flash[:notice] = I18n.t('flash.notice.destroyed', :model => ComicStory.model_name.human)
-        format.html { redirect_to play_comic_path(@comic) }
-        format.json { head :ok }
-      else
-        flash[:notice] = I18n.t('flash.notice.not_destroyed', :model => ComicStory.model_name.human)
-        format.html { redirect_to comic_story_path(@comic_story) }
-        format.json { render json: @comic_story.errors, status: :unprocessable_entity }
-      end
-    end
+    set_model
+    @item = @my_model_class.edit(params[:id], @operators)
+    @binder = @my_model_class.binder_model.edit(@item.binder_id, @operators) if @item.binder_id
+    render_destroy '/home/' + play_comic_path(@item)
   end
+  
 end
index 2b6005c..838d7d8 100644 (file)
@@ -84,17 +84,9 @@ class ComicsController < ApplicationController
   end
   
   def destroy
-    @item = Comic.edit(params[:id], @operators)
-    respond_to do |format|
-      if @item.destroy_with_leafs
-        flash[:notice] = I18n.t('flash.notice.destroyed', :model => Comic.model_name.human)
-        format.html { redirect_to '/home/comics' }
-        format.json { head :ok }
-      else
-        flash[:notice] = I18n.t('flash.notice.not_destroyed', :model => Comic.model_name.human)
-        format.html { redirect_to @item }
-        format.json { render json: @item.errors, status: :unprocessable_entity }
-      end
-    end
+    set_model
+    @item = @my_model_class.edit(params[:id], @operators)
+    render_destroy '/home/' + @item.path_name
   end
+  
 end
index 07ae91a..06f5687 100644 (file)
@@ -74,4 +74,10 @@ class FoldersController < ApplicationController
     list_count
   end
   
+  def destroy
+    set_model
+    @item = @my_model_class.edit(params[:id], @operators)
+    render_destroy @my_model_class.path_name
+  end
+  
 end
index 2b12b4a..e98832d 100644 (file)
@@ -56,4 +56,10 @@ class LicenseGroupsController < ApplicationController
     render_update
   end
   
+  def destroy
+    set_model
+    @item = @my_model_class.edit(params[:id], @operators)
+    render_destroy @my_model_class.path_name
+  end
+  
 end
index f781d0f..66b0423 100644 (file)
@@ -67,11 +67,9 @@ class LicensesController < ApplicationController
   end
   
   def destroy
-    @item = self.class.model.edit(params[:id], @operators)
-    respond_to do |format|
-        flash[:notice] = I18n.t('flash.notice.not_destroyed', :model => self.class.model.model_name.human)
-        format.html { redirect_to @item }
-        format.json { render json: @item.errors, status: :unprocessable_entity }
-    end
+    set_model
+    @item = @my_model_class.edit(params[:id], @operators)
+    render_destroy @my_model_class.path_name
   end
+  
 end
index c902cf9..59c0678 100644 (file)
@@ -63,7 +63,6 @@ class OriginalPicturesController < ApplicationController
   
   def create
     set_model
-    p  params[:file]
     @imager = if params[:original_picture]
       PettanImager.load set_image params[:original_picture][:file]
     else
@@ -106,16 +105,9 @@ class OriginalPicturesController < ApplicationController
   end
   
   def destroy
-    @item = OriginalPicture.edit(params[:id], @operators)
-    
-    respond_to do |format|
-      if @item.destroy_with_resource_picture
-        format.html { redirect_to original_pictures_url }
-        format.json { head :ok }
-      else
-        format.html { redirect_to original_picture_path(@item) }
-        format.json { render json: @item.errors, status: :unprocessable_entity }
-      end
-    end
+    set_model
+    @item = @my_model_class.edit(params[:id], @operators)
+    render_destroy_by 'destroy_with_resource_picture', original_pictures_url
   end
+  
 end
index b748c05..301b774 100644 (file)
@@ -153,20 +153,9 @@ class PanelsController < ApplicationController
   end
   
   def destroy
-    @item = Panel.edit(params[:id], @operators)
-    respond_to do |format|
-      Panel.transaction do
-        if @item.destroy_with_elements
-          flash[:notice] = I18n.t('flash.notice.destroyed', :model => Panel.model_name.human)
-          format.html { redirect_to '/home/panels' }
-          format.json { head :ok }
-        else
-          flash[:notice] = I18n.t('flash.notice.not_destroyed', :model => Panel.model_name.human)
-          format.html { redirect_to @item }
-          format.json { render json: @item.errors, status: :unprocessable_entity }
-        end
-      end
-    end
+    set_model
+    @item = @my_model_class.edit(params[:id], @operators)
+    render_destroy '/home/' + @item.path_name
   end
   
 end
index 437ae21..27b1b31 100644 (file)
@@ -94,19 +94,9 @@ class ResourcePicturesController < ApplicationController
   end
   
   def destroy
-    @resource_picture = ResourcePicture.edit(params[:id], @operators)
-
-    respond_to do |format|
-      if @resource_picture.unpublish
-        format.html { redirect_to :controller => '/home', :action => :resource_pictures }
-        format.json {
-          render json: '{}', status: :ok
-        }
-      else
-        format.html { redirect_to resource_picture_path(@resource_picture) }
-        format.json { render json: @resource_picture.errors, status: :unprocessable_entity }
-      end
-    end
+    set_model
+    @item = @my_model_class.edit(params[:id], @operators)
+    render_destroy_by 'unpublish', '/home/' + @item.path_name
   end
   
   def count
index 17532a7..ffcee61 100644 (file)
@@ -69,18 +69,10 @@ class ScrollPanelsController < ApplicationController
   end
   
   def destroy
-    @scroll_panel = ScrollPanel.edit(params[:id], @operators)
-    @scroll = Scroll.edit(@scroll_panel.scroll_id, @operators) if @scroll_panel.scroll_id
-    respond_to do |format|
-      if @scroll_panel.destroy_and_shorten
-        flash[:notice] = I18n.t('flash.notice.destroyed', :model => ScrollPanel.model_name.human)
-        format.html { redirect_to play_scroll_path(@scroll) }
-        format.json { head :ok }
-      else
-        flash[:notice] = I18n.t('flash.notice.not_destroyed', :model => ScrollPanel.model_name.human)
-        format.html { redirect_to scroll_panel_path(@scroll_panel) }
-        format.json { render json: @scroll_panel.errors, status: :unprocessable_entity }
-      end
-    end
+    set_model
+    @item = @my_model_class.edit(params[:id], @operators)
+    @binder = @my_model_class.binder_model.edit(@item.binder_id, @operators) if @item.binder_id
+    render_destroy '/home/' + play_scroll_path(@item)
   end
+  
 end
index f95ade4..246411f 100644 (file)
@@ -83,4 +83,5 @@ class ScrollsController < ApplicationController
     @item = @my_model_class.edit(params[:id], @operators)
     render_destroy '/home/' + @item.path_name
   end
+  
 end
index 0132a9d..f0a1455 100644 (file)
@@ -138,17 +138,9 @@ class SheetsController < ApplicationController
   end
   
   def destroy
-    @sheet = Sheet.edit(params[:id], @operators)
-    respond_to do |format|
-      if @sheet.destroy_with_sheet_panel
-        flash[:notice] = I18n.t('flash.notice.destroyed', :model => Sheet.model_name.human)
-        format.html { redirect_to '/home/sheets' }
-        format.json { head :ok }
-      else
-        flash[:notice] = I18n.t('flash.notice.not_destroyed', :model => Sheet.model_name.human)
-        format.html { redirect_to @sheet }
-        format.json { render json: @sheet.errors, status: :unprocessable_entity }
-      end
-    end
+    set_model
+    @item = @my_model_class.edit(params[:id], @operators)
+    render_destroy '/home/' + @item.path_name
   end
+  
 end
index 42b1724..8fffffd 100644 (file)
@@ -44,12 +44,9 @@ class SpeechBalloonTemplatesController < ApplicationController
   end
   
   def destroy
-    @item = SpeechBalloonTemplate.find(params[:id])
-    @item.destroy
-
-    respond_to do |format|
-      format.html { redirect_to :action => :list }
-      format.json { head :ok }
-    end
+    set_model
+    @item = @my_model_class.edit(params[:id], @operators)
+    render_destroy @my_model_class.path_name
   end
+  
 end
index 22a4b19..67ba22a 100644 (file)
@@ -87,18 +87,9 @@ class StoriesController < ApplicationController
   end
   
   def destroy
-    @item = Story.edit(params[:id], @operators)
-    respond_to do |format|
-      if @item.destroy_with_leafs
-        flash[:notice] = I18n.t('flash.notice.destroyed', :model => Story.model_name.human)
-        format.html { redirect_to '/home/stories' }
-        format.json { head :ok }
-      else
-        flash[:notice] = I18n.t('flash.notice.not_destroyed', :model => Story.model_name.human)
-        format.html { redirect_to @item }
-        format.json { render json: @item.errors, status: :unprocessable_entity }
-      end
-    end
+    set_model
+    @item = @my_model_class.edit(params[:id], @operators)
+    render_destroy '/home/' + @item.path_name
   end
   
 end
index ac40f9b..887f4e8 100644 (file)
@@ -69,18 +69,10 @@ class StorySheetsController < ApplicationController
   end
   
   def destroy
-    @story_sheet = StorySheet.edit(params[:id], @operators)
-    @story = Story.edit(@story_sheet.story_id, @operators) if @story_sheet.story_id
-    respond_to do |format|
-      if @story_sheet.destroy_and_shorten
-        flash[:notice] = I18n.t('flash.notice.destroyed', :model => StorySheet.model_name.human)
-        format.html { redirect_to play_story_path(@story) }
-        format.json { head :ok }
-      else
-        flash[:notice] = I18n.t('flash.notice.not_destroyed', :model => StorySheet.model_name.human)
-        format.html { redirect_to story_sheet_path(@story_sheet) }
-        format.json { render json: @story_sheet.errors, status: :unprocessable_entity }
-      end
-    end
+    set_model
+    @item = @my_model_class.edit(params[:id], @operators)
+    @binder = @my_model_class.binder_model.edit(@item.binder_id, @operators) if @item.binder_id
+    render_destroy '/home/' + play_story_path(@item)
   end
+  
 end
index cdb27e5..d215aec 100644 (file)
@@ -58,12 +58,9 @@ class WritingFormatsController < ApplicationController
   end
   
   def destroy
-    @item = self.class.model.edit(params[:id], @operators)
-    respond_to do |format|
-        flash[:notice] = I18n.t('flash.notice.not_destroyed', :model => self.class.model.model_name.human)
-        format.html { redirect_to @item }
-        format.json { render json: @item.errors, status: :unprocessable_entity }
-    end
+    set_model
+    @item = @my_model_class.edit(params[:id], @operators)
+    render_destroy @my_model_class.path_name
   end
   
 end
index 901fd3b..39645a7 100644 (file)
@@ -6,7 +6,7 @@ class Picture < Peta::Content
   belongs_to :system_picture
   belongs_to :artist
   has_one :resource_picture
-  has_one :resource_picture_pictures
+  has_one :resource_picture_picture
   
   validates :original_picture_id, :presence => true, :numericality => true, :existence => {:both => false}
   validates :revision, :presence => true, :numericality => true
@@ -206,6 +206,7 @@ class Picture < Peta::Content
   end
   
   def unpublish
+    self.boosts 'post'
     imager = PettanImager.load(File.open(Rails.root + 'app/assets/images/error.png', 'rb').read)
     return false unless imager
     self.store imager
index 4d8cf34..1d90366 100644 (file)
@@ -2,7 +2,7 @@ class CreateResourcePicturePictures < ActiveRecord::Migration
   def change
     create_table :resource_picture_pictures do |t|
       t.integer :original_picture_id, :null => false, :default => 0
-      t.integer :resource_picture_id, :default => nil
+      t.integer :resource_picture_id, :null => false, :default => 0
       t.integer :picture_id, :null => false, :default => 0
 
       t.timestamps
diff --git a/db/migrate/20150516051015_rpp_id_allow_null.rb b/db/migrate/20150516051015_rpp_id_allow_null.rb
new file mode 100644 (file)
index 0000000..370ddca
--- /dev/null
@@ -0,0 +1,11 @@
+class RppIdAllowNull < ActiveRecord::Migration
+  def up
+    change_column_null :resource_picture_pictures, :original_picture_id, true
+    change_column_null :resource_picture_pictures, :resource_picture_id, true
+    change_column_default :resource_picture_pictures, :original_picture_id, nil
+    change_column_default :resource_picture_pictures, :resource_picture_id, nil
+  end
+
+  def down
+  end
+end
index efedd65..51afc8f 100644 (file)
@@ -74,7 +74,7 @@ module Peta
       res = false
       self.class.transaction do
         self.leafs_items.each do |leaf|
-          raise ActiveRecord::Rollback unless leaf.destroy_and_shorten
+          raise ActiveRecord::Rollback unless leaf.destroy
         end
         res = super
         raise ActiveRecord::Rollback unless res
index 6d987c6..0245766 100644 (file)
@@ -182,14 +182,14 @@ module Peta
       res
     end
     
-    def destroy_and_shorten
+    def destroy
       res = false
       self.class.transaction do
         self.class.update_all('t = t - 1', 
           [self.binder_key + ' = ? and (t > ?)', self.binder_id, self.t]
         )
-        raise ActiveRecord::Rollback unless self.destroy
-        res = true
+        res = super
+        raise ActiveRecord::Rollback unless res
       end
       res
     end
index 379ad0a..4a93924 100644 (file)
@@ -133,14 +133,14 @@ module Peta
       res
     end
     
-    def destroy_with_elements
+    def destroy
       res = false
       self.class.transaction do
         self.parts_element.each do |element|
           raise ActiveRecord::Rollback unless element.destroy
         end
-        raise ActiveRecord::Rollback unless self.destroy
-        res = true
+        res = super
+        raise ActiveRecord::Rollback unless res
       end
       res
     end