Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Tried to use MasterFile.type

  • Loading branch information...
commit 1e328fbc50371cc00a84306c3884969b7de40964 1 parent 10ffcb9
@phuongdh phuongdh authored
View
2  app/assets/javascripts/application.js
@@ -23,5 +23,5 @@
// Required by Blacklight
//= require jquery-ui
//= require_directory .
-//
+//= require jquery.ui.nestedSortable
//= require_self
View
4 app/assets/stylesheets/hydrant.css.less
@@ -13,6 +13,10 @@
margin-bottom: 18px;
}
+.sortable {
+ cursor: move;
+}
+
/** Use half of a line height for a more subtle offset */
.whitespace-half {
margin-bottom: 9px;
View
11 app/controllers/derivatives_controller.rb
@@ -3,6 +3,7 @@
class DerivativesController < ApplicationController
# before_filter :enforce_access_controls
+ load_and_authorize_resource
skip_before_filter :verify_authenticity_token, :only => [:create]
before_filter :authenticate_user!, :only => [:create]
@@ -12,11 +13,11 @@ class DerivativesController < ApplicationController
# * the File Asset will use RELS-EXT to assert that it's a part of the specified container
# * the method will redirect to the container object's edit view after saving
def create
- if cannot? :create, Derivative
- flash[:notice] = "You do not have sufficient privileges to add derivative files"
- redirect_to root_path
- return
- end
+ # if cannot? :create, Derivative
+ # flash[:notice] = "You do not have sufficient privileges to add derivative files"
+ # redirect_to root_path
+ # return
+ # end
masterfile = MasterFile.find(params[:id])
if cannot? :edit, masterfile.container.pid
View
6 app/controllers/master_files_controller.rb
@@ -66,6 +66,8 @@ def create
end
@master_files << master_file = saveOriginalToHydrant(file)
+ master_file.type = @upload_format
+
if master_file.save
master_file = sendOriginalToMatterhorn(master_file, file, @upload_format)
media_object = MediaObject.find(master_file.container.pid)
@@ -113,7 +115,7 @@ def saveOriginalToHydrant file
FileUtils.cp file.tempfile, new_file_path
master_file = create_master_file_from_temp_path(new_file_path[public_dir_path.length - 1, new_file_path.length - 1])
-
+
notice = []
apply_depositor_metadata(master_file)
@@ -155,8 +157,8 @@ def sendOriginalToMatterhorn(master_file, file, upload_format)
def create_master_file_from_temp_path(path)
master_file = MasterFile.new
filename = path.split(/\//).last
- master_file.label = filename
master_file.url = path
+ master_file.label = File.basename(filename, File.extname(filename))
#master_file.description = "Original file uploaded"
return master_file
View
1  app/models/master_file.rb
@@ -6,6 +6,7 @@ class MasterFile < FileAsset
delegate :description, to: :descMetadata
delegate :url, to: :descMetadata, at: [:identifier]
delegate :size, to: :descMetadata, at: [:extent]
+ delegate :type, to: :descMetadata
def derivatives_append(der)
der.add_relationship(:is_derivation_of, self)
View
52 app/views/media_objects/_file_upload.html.erb
@@ -3,26 +3,36 @@
<legend>File Upload</legend>
<% unless @masterfiles.nil? %>
-
+ <% if @masterfiles.count > 1 %>
+ <p>You have multiple files for this item. Are they sequential, versional or hierarchical?</p>
+ <div class="btn-group">
+ <button class="btn btn-success">Sequence</button>
+ <button class="btn">Versions</button>
+ <button class="btn">Hierarchy</button>
+ </div>
+ <p>
+ <% end %>
+
<table class="table table-striped">
- <thead>
- <th></th>
- <th>Title</th>
- <th>Filename</th>
- <th>Filesize</th>
- <th>Action</th>
- </thead>
- <tbody>
+ <thead>
+ <th></th>
+ <th>Title</th>
+ <th>Filename</th>
+ <th>Filesize</th>
+ <th>Action</th>
+ </thead>
+ <tbody class="sortable">
<% @masterfiles.each do |masterfile| %>
<tr>
<td>
<i class="icon-volume-up"></i>
+ <%= masterfile.type %>
</td>
<td>
- <%= text_field_tag "title", masterfile.descMetadata.title[0] %>
+ <%= text_field_tag "title", masterfile.label %>
</td>
<td>
- <a href="<%= masterfile.descMetadata.identifier[0] %>"><%= masterfile.descMetadata.title[0] %></a>
+ <a href="<%= masterfile.descMetadata.identifier[0] %>"><%= File.basename(masterfile.url.first) %></a>
</td>
<td>
<strong>(<%= number_to_human_size(masterfile.size) %>)</strong>
@@ -33,11 +43,11 @@
<% # On a Rails level this needs to be folded into the masterfiles
# controller's destroy method to help remove more vestiges of the
# catalog controller %>
- <%= button_to("Delete file",
+ <%= button_to("Delete",
master_file_path(masterfile.id),
:data => { :confirm => "Are you sure you want to delete this file?" },
:method => :delete,
- :class => "delete-button btn") %>
+ :class => "delete-button btn btn-mini btn-danger") %>
<% end %>
</td>
</tr>
@@ -77,5 +87,21 @@
<script>
/* Hide the alert dialog on the page loading if Javascript is enabled */
<% unless flash[:upload] %>$('#upload_format').hide();<% end %>
+ $('.sortable').sortable();
+ $('.sortable').disableSelection();
+
+ // $(".sortable").nestedSortable({
+ // placeholder: 'dropPlaceHolder',
+ // forcePlaceholderSize:true,
+ // handle: 'div',
+ // helper: 'clone',
+ // listType: 'tbody',
+ // items: 'tr',
+ // opacity: .6,
+ // revert: 250,
+ // tabSize: 25,
+ // tolerance: 'pointer',
+ // toleranceElement: '> div'
+ // }).disableSelection();
</script>
<% end %>
View
356 vendor/assets/javascripts/jquery.ui.nestedSortable.js
@@ -0,0 +1,356 @@
+/*
+ * jQuery UI Nested Sortable
+ * v 1.3.4 / 28 apr 2011
+ * http://mjsarfatti.com/sandbox/nestedSortable
+ *
+ * Depends:
+ * jquery.ui.sortable.js 1.8+
+ *
+ * License CC BY-SA 3.0
+ * Copyright 2010-2011, Manuele J Sarfatti
+ */
+
+(function($) {
+
+ $.widget("ui.nestedSortable", $.extend({}, $.ui.sortable.prototype, {
+
+ options: {
+ tabSize: 20,
+ disableNesting: 'ui-nestedSortable-no-nesting',
+ errorClass: 'ui-nestedSortable-error',
+ listType: 'ol',
+ maxLevels: 0,
+ noJumpFix: 0
+ },
+
+ _create: function(){
+ if (this.noJumpFix == false)
+ this.element.height(this.element.height());
+ this.element.data('sortable', this.element.data('nestedSortable'));
+ return $.ui.sortable.prototype._create.apply(this, arguments);
+ },
+
+
+
+ _mouseDrag: function(event) {
+
+ //Compute the helpers position
+ this.position = this._generatePosition(event);
+ this.positionAbs = this._convertPositionTo("absolute");
+
+ if (!this.lastPositionAbs) {
+ this.lastPositionAbs = this.positionAbs;
+ }
+
+ //Do scrolling
+ if(this.options.scroll) {
+ var o = this.options, scrolled = false;
+ if(this.scrollParent[0] != document && this.scrollParent[0].tagName != 'HTML') {
+
+ if((this.overflowOffset.top + this.scrollParent[0].offsetHeight) - event.pageY < o.scrollSensitivity)
+ this.scrollParent[0].scrollTop = scrolled = this.scrollParent[0].scrollTop + o.scrollSpeed;
+ else if(event.pageY - this.overflowOffset.top < o.scrollSensitivity)
+ this.scrollParent[0].scrollTop = scrolled = this.scrollParent[0].scrollTop - o.scrollSpeed;
+
+ if((this.overflowOffset.left + this.scrollParent[0].offsetWidth) - event.pageX < o.scrollSensitivity)
+ this.scrollParent[0].scrollLeft = scrolled = this.scrollParent[0].scrollLeft + o.scrollSpeed;
+ else if(event.pageX - this.overflowOffset.left < o.scrollSensitivity)
+ this.scrollParent[0].scrollLeft = scrolled = this.scrollParent[0].scrollLeft - o.scrollSpeed;
+
+ } else {
+
+ if(event.pageY - $(document).scrollTop() < o.scrollSensitivity)
+ scrolled = $(document).scrollTop($(document).scrollTop() - o.scrollSpeed);
+ else if($(window).height() - (event.pageY - $(document).scrollTop()) < o.scrollSensitivity)
+ scrolled = $(document).scrollTop($(document).scrollTop() + o.scrollSpeed);
+
+ if(event.pageX - $(document).scrollLeft() < o.scrollSensitivity)
+ scrolled = $(document).scrollLeft($(document).scrollLeft() - o.scrollSpeed);
+ else if($(window).width() - (event.pageX - $(document).scrollLeft()) < o.scrollSensitivity)
+ scrolled = $(document).scrollLeft($(document).scrollLeft() + o.scrollSpeed);
+
+ }
+
+ if(scrolled !== false && $.ui.ddmanager && !o.dropBehaviour)
+ $.ui.ddmanager.prepareOffsets(this, event);
+ }
+
+ //Regenerate the absolute position used for position checks
+ this.positionAbs = this._convertPositionTo("absolute");
+
+ //Set the helper position
+ if(!this.options.axis || this.options.axis != "y") this.helper[0].style.left = this.position.left+'px';
+ if(!this.options.axis || this.options.axis != "x") this.helper[0].style.top = this.position.top+'px';
+
+ //Rearrange
+ for (var i = this.items.length - 1; i >= 0; i--) {
+
+ //Cache variables and intersection, continue if no intersection
+ var item = this.items[i], itemElement = item.item[0], intersection = this._intersectsWithPointer(item);
+ if (!intersection) continue;
+
+ if(itemElement != this.currentItem[0] //cannot intersect with itself
+ && this.placeholder[intersection == 1 ? "next" : "prev"]()[0] != itemElement //no useless actions that have been done before
+ && !$.contains(this.placeholder[0], itemElement) //no action if the item moved is the parent of the item checked
+ && (this.options.type == 'semi-dynamic' ? !$.contains(this.element[0], itemElement) : true)
+ //&& itemElement.parentNode == this.placeholder[0].parentNode // only rearrange items within the same container
+ ) {
+
+ this.direction = intersection == 1 ? "down" : "up";
+
+ if (this.options.tolerance == "pointer" || this._intersectsWithSides(item)) {
+ this._rearrange(event, item);
+ } else {
+ break;
+ }
+
+ // Clear emtpy ul's/ol's
+ this._clearEmpty(itemElement);
+
+ this._trigger("change", event, this._uiHash());
+ break;
+ }
+ }
+
+ var parentItem = (this.placeholder[0].parentNode.parentNode && $(this.placeholder[0].parentNode.parentNode).closest('.ui-sortable').length) ? $(this.placeholder[0].parentNode.parentNode) : null;
+ var level = this._getLevel(this.placeholder);
+ var childLevels = this._getChildLevels(this.helper);
+ var previousItem = this.placeholder[0].previousSibling ? $(this.placeholder[0].previousSibling) : null;
+ if (previousItem != null) {
+ while (previousItem[0].nodeName.toLowerCase() != 'li' || previousItem[0] == this.currentItem[0]) {
+ if (previousItem[0].previousSibling) {
+ previousItem = $(previousItem[0].previousSibling);
+ } else {
+ previousItem = null;
+ break;
+ }
+ }
+ }
+
+ newList = document.createElement(o.listType);
+
+ this.beyondMaxLevels = 0;
+
+ // If the item is moved to the left, send it to its parent level
+ if (parentItem != null && this.positionAbs.left < parentItem.offset().left) {
+ parentItem.after(this.placeholder[0]);
+ this._clearEmpty(parentItem[0]);
+ this._trigger("change", event, this._uiHash());
+ }
+ // If the item is below another one and is moved to the right, make it a children of it
+ else if (previousItem != null && this.positionAbs.left > previousItem.offset().left + o.tabSize) {
+ this._isAllowed(previousItem, level+childLevels+1);
+ if (!previousItem.children(o.listType).length) {
+ previousItem[0].appendChild(newList);
+ }
+ previousItem.children(o.listType)[0].appendChild(this.placeholder[0]);
+ this._trigger("change", event, this._uiHash());
+ }
+ else {
+ this._isAllowed(parentItem, level+childLevels);
+ }
+
+ //Post events to containers
+ this._contactContainers(event);
+
+ //Interconnect with droppables
+ if($.ui.ddmanager) $.ui.ddmanager.drag(this, event);
+
+ //Call callbacks
+ this._trigger('sort', event, this._uiHash());
+
+ this.lastPositionAbs = this.positionAbs;
+ return false;
+
+ },
+
+ _mouseStop: function(event, noPropagation) {
+
+ // If the item is in a position not allowed, send it back
+ if (this.beyondMaxLevels) {
+ var parent = this.placeholder.parent().closest(this.options.items);
+
+ for (var i = this.beyondMaxLevels - 1; i > 0; i--) {
+ parent = parent.parent().closest(this.options.items);
+ }
+
+ this.placeholder.removeClass(this.options.errorClass);
+ parent.after(this.placeholder);
+ this._trigger("change", event, this._uiHash());
+ }
+
+ $.ui.sortable.prototype._mouseStop.apply(this, arguments);
+
+ },
+
+ serialize: function(o) {
+
+ var items = this._getItemsAsjQuery(o && o.connected);
+ var str = []; o = o || {};
+
+ $(items).each(function() {
+ var res = ($(o.item || this).attr(o.attribute || 'id') || '').match(o.expression || (/(.+)[-=_](.+)/));
+ var pid = ($(o.item || this).parent(o.listType).parent('li').attr(o.attribute || 'id') || '').match(o.expression || (/(.+)[-=_](.+)/));
+ if(res) str.push((o.key || res[1]+'['+(o.key && o.expression ? res[1] : res[2])+']')+'='+(pid ? (o.key && o.expression ? pid[1] : pid[2]) : 'root'));
+ });
+
+ if(!str.length && o.key) {
+ str.push(o.key + '=');
+ }
+
+ return str.join('&');
+
+ },
+
+ toHierarchy: function(o) {
+
+ o = o || {};
+ var sDepth = o.startDepthCount || 0;
+ var ret = [];
+
+ $(this.element).children('li').each(function() {
+ var level = _recursiveItems($(this));
+ ret.push(level);
+ });
+
+ return ret;
+
+ function _recursiveItems(li) {
+ var id = ($(li).attr(o.attribute || 'id') || '').match(o.expression || (/(.+)[-=_](.+)/));
+ if (id != null) {
+ var item = {"id" : id[2]};
+ if ($(li).children(o.listType).children('li').length > 0) {
+ item.children = [];
+ $(li).children(o.listType).children('li').each(function () {
+ var level = _recursiveItems($(this));
+ item.children.push(level);
+ });
+ }
+ return item;
+ }
+ }
+ },
+
+ toArray: function(o) {
+
+ o = o || {};
+ var sDepth = o.startDepthCount || 0;
+ var ret = [];
+ var left = 2;
+
+ ret.push({"item_id": 'root', "parent_id": 'none', "depth": sDepth, "left": '1', "right": ($('li', this.element).length + 1) * 2});
+
+ $(this.element).children('li').each(function () {
+ left = _recursiveArray(this, sDepth + 1, left);
+ });
+
+ function _sortByLeft(a,b) {
+ return a['left'] - b['left'];
+ }
+ ret = ret.sort(_sortByLeft);
+
+ return ret;
+
+ function _recursiveArray(item, depth, left) {
+
+ right = left + 1;
+
+ if ($(item).children(o.listType).children('li').length > 0) {
+ depth ++;
+ $(item).children(o.listType).children('li').each(function () {
+ right = _recursiveArray($(this), depth, right);
+ });
+ depth --;
+ }
+
+ id = ($(item).attr(o.attribute || 'id')).match(o.expression || (/(.+)[-=_](.+)/));
+
+ if (depth === sDepth + 1) pid = 'root';
+ else {
+ parentItem = ($(item).parent(o.listType).parent('li').attr('id')).match(o.expression || (/(.+)[-=_](.+)/));
+ pid = parentItem[2];
+ }
+
+ if (id != null) {
+ ret.push({"item_id": id[2], "parent_id": pid, "depth": depth, "left": left, "right": right});
+ }
+
+ return left = right + 1;
+ }
+
+ },
+
+ _clear: function(event, noPropagation) {
+
+ $.ui.sortable.prototype._clear.apply(this, arguments);
+
+ // Clean last empty ul/ol
+ for (var i = this.items.length - 1; i >= 0; i--) {
+ var item = this.items[i].item[0];
+ this._clearEmpty(item);
+ }
+ return true;
+
+ },
+
+ _clearEmpty: function(item) {
+
+ if (item.children[1] && item.children[1].children.length == 0) {
+ item.removeChild(item.children[1]);
+ }
+
+ },
+
+ _getLevel: function(item) {
+
+ var level = 1;
+
+ if (this.options.listType) {
+ var list = item.closest(this.options.listType);
+ while (!list.is('.ui-sortable')/* && level < this.options.maxLevels*/) {
+ level++;
+ list = list.parent().closest(this.options.listType);
+ }
+ }
+
+ return level;
+ },
+
+ _getChildLevels: function(parent, depth) {
+ var self = this,
+ o = this.options,
+ result = 0;
+ depth = depth || 0;
+
+ $(parent).children(o.listType).children(o.items).each(function (index, child) {
+ result = Math.max(self._getChildLevels(child, depth + 1), result);
+ });
+
+ return depth ? result + 1 : result;
+ },
+
+ _isAllowed: function(parentItem, levels) {
+ var o = this.options
+ // Are we trying to nest under a no-nest or are we nesting too deep?
+ if (parentItem == null || !(parentItem.hasClass(o.disableNesting))) {
+ if (o.maxLevels < levels && o.maxLevels != 0) {
+ this.placeholder.addClass(o.errorClass);
+ this.beyondMaxLevels = levels - o.maxLevels;
+ } else {
+ this.placeholder.removeClass(o.errorClass);
+ this.beyondMaxLevels = 0;
+ }
+ } else {
+ this.placeholder.addClass(o.errorClass);
+ if (o.maxLevels < levels && o.maxLevels != 0) {
+ this.beyondMaxLevels = levels - o.maxLevels;
+ } else {
+ this.beyondMaxLevels = 1;
+ }
+ }
+ }
+
+ }));
+
+ $.ui.nestedSortable.prototype.options = $.extend({}, $.ui.sortable.prototype.options, $.ui.nestedSortable.prototype.options);
+})(jQuery);
Please sign in to comment.
Something went wrong with that request. Please try again.