Enables resource duplication via new form.

 - Adds a duplicate action button.
 - Preloads a duplicated resource on `:new` to pre-fill the form fields.

 No return.
167035
def enable_resource_duplication_via_form
      action_item(*compatible_action_item_parameters) do
        if controller.action_methods.include?('new') && authorized?(ActiveAdmin::Auth::CREATE, active_admin_config.resource_class)
          link_to(I18n.t(:duplicate_model, default: "Duplicate %{model}", scope: [:active_admin], model: active_admin_config.resource_label), action: :new, _source_id: resource.id)
        end
      end

      controller do
        before_action only: :new do
          if !params[:_source_id].blank?
            source = resource_class.find(params[:_source_id])
            @resource ||= source.amoeba_dup if source
          end
        end
      end
    end
357183
def add(value, options = {})
      # Set defaults
      options[:duplication_filter] = :do_not_add unless options.key?(:duplication_filter)

      # Get path
      path = get_array

      # Check duplicates
      if path.member?(value)
        case options[:duplication_filter]
        when :do_not_add, :deny
          # do nothing, we already have one in the list
          return
        when :remove_existing
          path.delete!(value)
        when :none
          # just pass through
        else
          raise WrongOptionError, "Unknown :duplication_filter!"
        end
      end

      # Change path array
      case options[:where]
      when :start, :left
        path.unshift value
      when :end, :right
        path.push value
      else
        raise WrongOptionError, "Unknown :where!"
      end

      # Save new array
      set_array(path)
    end
658312
public function duplicateUnderlyingFile()
    {
        $app = Application::getFacadeApplication();
        $importer = new Importer();
        $cf = $app->make('helper/concrete/file');
        $filesystem = $this->getFile()->getFileStorageLocationObject()->getFileSystemObject();
        $fileName = $this->getFileName();
        do {
            $prefix = $importer->generatePrefix();
            $path = $cf->prefix($prefix, $fileName);
        } while ($filesystem->has($path));
        $fileContents = $this->getFileResource()->read();
        $mimeType = Util::guessMimeType($fileName, $fileContents);
        $filesystem->write(
            $path,
            $fileContents,
            [
                'visibility' => AdapterInterface::VISIBILITY_PUBLIC,
                'mimetype' => $mimeType,
            ]
        );
        $this->updateFile($fileName, $prefix);
    }
75210
public function duplicate()
    {
        $record = $this->initExistingItem();

        $record->duplicate();

        $url = $this->getAfterUrl(
            "after-duplicate",
            $this->getModelManager()->getURL()
        );

        $flashName = $this->getAfterFlashName(
            "after-duplicate",
            $this->getModelManager()->getController()
        );

        $this->flashRedirect(
            $this->getModelManager()->getMessage('duplicate'),
            $url,
            'success',
            $flashName
        );
    }
122302
def duplicate(self):
        '''
        
        '''
        return self.__class__(self.method, self.status, self.date, self.ref)
1269680
def register_callback_duplicate(self, func, serialised=True):
        
        self.__add_callback(_CB_DUPLICATE, func, serialised_if_crud=serialised)
1331868
def add_view(self, request, **kwargs):
        
        try:
            return super(ClonedRepoAdmin, self).add_view(request, **kwargs)
        except ValidationError:
            # Rerender the form, having messaged the user.
            return redirect(request.path)
190401
def new(attributes = {})
      resource = repository.scope { model.new(attributes) }
      self << resource
      resource
    end
28139
def create
      @entry = @resource.model.new(resource_params)

      if @entry.save
        redirect_to polymorphic_path(@resource.model),
                    notice: t(
                      'adminable.resources.created',
                      resource: @resource.model.model_name.human
                    )
      else
        flash.now[:alert] = @entry.errors.full_messages.first
        render :new
      end
    end
1304214
def add_resource(self, name, file_path, ind_obj):
        """"""
        new_resource = Resource(name=name, individual=ind_obj, path=file_path)
        self.session.add(new_resource)
        self.save()
        return new_resource
901697
function it_retains_the_original_state_of_the_instance_duplicated_with_new_scheme()
    {
        $original_uri = (string) $this->getWrappedObject();

        $new_scheme = $this->withScheme("http");

        $this->__toString()->shouldReturn($original_uri);
    }
493052
function it_retains_the_original_state_of_the_instance_duplicated_with_new_path()
    {
        $original_uri = (string) $this->getWrappedObject();

        $new_path = $this->withPath("/quux/quuz");

        $this->__toString()->shouldReturn($original_uri);
    }
677061
function createResource(url, params, methods) {
      var resource;

      params = _.defaults({}, params, defaultParams);
      methods = _.defaults({}, methods, defaultMethods);
      resource = $resource(url, params, methods);

      // overwrite $save to automatically call $create or $update
      resource.prototype.$save = function save() {
        if (!this._id) {
          return this.$create();
        }

        return this.$update();
      };

      return resource;
    }
520622
function Duplicator() {

    this.duplicateComponent = function(component) {
        const visitor = new DuplicatingVisitor();
        component.acceptVisitor(visitor);
        return visitor.result;
    };

    return this;
}
881212
public function deduplicate()
	{
		if ($this->useCount > 1)
		{
			$this->isDeduplicated = true;
			$this->decrementUseCount($this->useCount - 1);
		}
	}
816780
def duplicate(self, contributor=None, inherit_collections=False):
        """"""
        duplicate = Entity.objects.get(id=self.id)
        duplicate.pk = None
        duplicate.slug = None
        duplicate.name = 'Copy of {}'.format(self.name)
        duplicate.duplicated = now()
        if contributor:
            duplicate.contributor = contributor

        duplicate.save(force_insert=True)

        assign_contributor_permissions(duplicate)

        # Override fields that are automatically set on create.
        duplicate.created = self.created
        duplicate.save()

        # Duplicate entity's data objects.
        data = get_objects_for_user(contributor, 'view_data', self.data.all())  # pylint: disable=no-member
        duplicated_data = data.duplicate(contributor)
        duplicate.data.add(*duplicated_data)

        if inherit_collections:
            collections = get_objects_for_user(
                contributor,
                'add_collection',
                self.collections.all()  # pylint: disable=no-member
            )
            for collection in collections:
                collection.entity_set.add(duplicate)
                copy_permissions(collection, duplicate)
                collection.data.add(*duplicated_data)
                for datum in duplicated_data:
                    copy_permissions(collection, datum)

        return duplicate
1240725
def new
      if params[:duplicate_id] && banner_dup = Banner.find(params[:duplicate_id])
        @banner = banner_dup.dup
        @banner.name += " (copy)"
        @banner.confirmed = false

        banner_dup.helper_items.each do |hi|
          @banner.helper_items << hi.dup
        end

      else
        @banner = Banner.new
        @banner.start_time = Time.now.at_midnight
        @banner.end_time = 1.week.from_now.end_of_day
      end

      respond_to do |format|
        format.html # new.html.erb
        format.json { render :json => @banner }
      end
    end