Gitlab CSE Unil

Commit 83fa9e62 authored by Julien Furrer's avatar Julien Furrer
Browse files

Added a readonly behavior to Tools

Updated Lock button too 
parent f68eea76
...@@ -175,7 +175,7 @@ define([ ...@@ -175,7 +175,7 @@ define([
attributes.init(); attributes.init();
ui.init(); ui.init({ro:config.annotable.locked});
io.loadData(config.api.annotables + config.annotable.id + '/'); // + '?mode=' + config.mode); io.loadData(config.api.annotables + config.annotable.id + '/'); // + '?mode=' + config.mode);
......
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
*/ */
define([ define([
"underscore",
"signals", "signals",
// ----- app // ----- app
...@@ -33,11 +34,13 @@ define([ ...@@ -33,11 +34,13 @@ define([
"tools/arrow" "tools/arrow"
// "tools/arrow1" // "tools/arrow1"
], ],
function(Signal){ function(_, Signal){
// ----- Locale variables ----------------------------- // ----- Locale variables -----------------------------
var _tools = {}; // A dictionary of the active tools, using the name as key var _tools = {}, // A dictionary of the active tools, using the name as key
var _activeTool = null; // The name of the current active tool _activeTool = null, // The name of the current active tool
_ro = false, // Local ReadOnly value
_noop = function(){}; // A no-op function;
var _events = { var _events = {
activated: new Signal(), activated: new Signal(),
...@@ -46,7 +49,7 @@ function(Signal){ ...@@ -46,7 +49,7 @@ function(Signal){
annotationSelected: new Signal() annotationSelected: new Signal()
}; };
var _noop = function(){};
// ----- Initialisations ------------------------------ // ----- Initialisations ------------------------------
...@@ -64,6 +67,7 @@ function(Signal){ ...@@ -64,6 +67,7 @@ function(Signal){
tool: t.tool, tool: t.tool,
importJSON: t.importJSON || defaultImportJson, importJSON: t.importJSON || defaultImportJson,
exportJSON: t.exportJSON || defaultExportJson, exportJSON: t.exportJSON || defaultExportJson,
setRo: t.setRo || _noop,
listeners: t.listeners || {} listeners: t.listeners || {}
}; };
...@@ -162,6 +166,17 @@ function(Signal){ ...@@ -162,6 +166,17 @@ function(Signal){
return exporter.call(item, $.extend({asString:true},param) ); return exporter.call(item, $.extend({asString:true},param) );
} }
/**
* Set ReadOnly state for all tools
* @param {boolean} ro - The ReadOnly value, true == ReadOnly or false == Writable
*/
function setRo(ro) {
if (ro === _ro) {
return;
}
_ro = ro;
_.invoke(_tools, 'setRo', ro);
}
// ----- Returned Module ------------------------------ // ----- Returned Module ------------------------------
...@@ -174,7 +189,8 @@ function(Signal){ ...@@ -174,7 +189,8 @@ function(Signal){
activateTool: activateTool, activateTool: activateTool,
getActiveTool: getActiveTool, getActiveTool: getActiveTool,
serializeItem: serializeItem serializeItem: serializeItem,
setRo: setRo
}; };
}); });
define(["paper"], function (paper) { define(["paper"], function (paper) {
// ----- Const ---------------------------------------- // ----- Const ----------------------------------------
var TOOL_TYPE = 'arrow'; var TOOL_TYPE = 'arrow';
var _ro = false;
// ----- Local variables ------------------------------ // ----- Local variables ------------------------------
...@@ -17,7 +18,6 @@ define(["paper"], function (paper) { ...@@ -17,7 +18,6 @@ define(["paper"], function (paper) {
fill: true fill: true
}; };
var _transparent = new paper.Color([0,0,0,0]); var _transparent = new paper.Color([0,0,0,0]);
// ----- Serialization --------------------------------- // ----- Serialization ---------------------------------
...@@ -266,6 +266,7 @@ define(["paper"], function (paper) { ...@@ -266,6 +266,7 @@ define(["paper"], function (paper) {
function itemMouseDown(event) { function itemMouseDown(event) {
if (!this.selected) return; if (!this.selected) return;
if (_ro) return;
_dragMode = DRAG_MODES.FULL_DRAG; _dragMode = DRAG_MODES.FULL_DRAG;
var toPt = this.data.to; var toPt = this.data.to;
...@@ -288,6 +289,8 @@ define(["paper"], function (paper) { ...@@ -288,6 +289,8 @@ define(["paper"], function (paper) {
function itemMouseDrag(event) { function itemMouseDrag(event) {
if (_ro) return;
_dragModified = true; _dragModified = true;
var param = { var param = {
from: this.data.from, from: this.data.from,
...@@ -467,6 +470,7 @@ define(["paper"], function (paper) { ...@@ -467,6 +470,7 @@ define(["paper"], function (paper) {
var _creatingArrow = null; var _creatingArrow = null;
var toolDef = { var toolDef = {
onMouseDown: function(event) { onMouseDown: function(event) {
if (_ro) return;
var hitAnnot; var hitAnnot;
_create = false; _create = false;
_creatingArrow = null; _creatingArrow = null;
...@@ -483,6 +487,7 @@ define(["paper"], function (paper) { ...@@ -483,6 +487,7 @@ define(["paper"], function (paper) {
}, },
onMouseDrag: function(event) { onMouseDrag: function(event) {
if (_ro) return;
if (_create && _creatingArrow) { if (_create && _creatingArrow) {
drawArrow(_creatingArrow, {from: _startPoint, to:event.point}); drawArrow(_creatingArrow, {from: _startPoint, to:event.point});
_creatingArrow.visible = true; _creatingArrow.visible = true;
...@@ -505,10 +510,17 @@ define(["paper"], function (paper) { ...@@ -505,10 +510,17 @@ define(["paper"], function (paper) {
}; };
function _setRo(ro) {
if (ro !== _ro)
_ro = ro;
return _ro;
}
// ----- Returned Module ------------------------------ // ----- Returned Module ------------------------------
return { return {
name: TOOL_TYPE, name: TOOL_TYPE,
tool: new paper.Tool(toolDef), tool: new paper.Tool(toolDef),
setRo: _setRo,
registerEvent: function(eventName, evt) { _events[eventName] = evt; }, registerEvent: function(eventName, evt) { _events[eventName] = evt; },
exportJSON: exportJSON, exportJSON: exportJSON,
importJSON: importJSON, importJSON: importJSON,
......
...@@ -4,6 +4,7 @@ define(["paper"], function (paper) { ...@@ -4,6 +4,7 @@ define(["paper"], function (paper) {
// ----- Local variables ----------------------------- // ----- Local variables -----------------------------
var _path = null; var _path = null;
var _ro = false;
// Events // Events
var _events = { var _events = {
...@@ -39,6 +40,8 @@ define(["paper"], function (paper) { ...@@ -39,6 +40,8 @@ define(["paper"], function (paper) {
item.onPropertyChange = itemPropertyChange; item.onPropertyChange = itemPropertyChange;
item.onDoubleClick = function(event) { item.onDoubleClick = function(event) {
if (_ro) return;
this.selected = false; this.selected = false;
this.fullySelected = true; this.fullySelected = true;
paper.view.draw(); paper.view.draw();
...@@ -47,14 +50,7 @@ define(["paper"], function (paper) { ...@@ -47,14 +50,7 @@ define(["paper"], function (paper) {
function itemPropertyChange(property, value) { function itemPropertyChange(property, value) {
if (property === 'confidence') { if (property === 'fill') {
this.style = confidenceStyle[value];
paper.view.draw();
}
else if (property === 'processus') {
//
}
else if (property === 'fill') {
this.closed = value; this.closed = value;
paper.view.draw(); paper.view.draw();
} }
...@@ -136,10 +132,17 @@ define(["paper"], function (paper) { ...@@ -136,10 +132,17 @@ define(["paper"], function (paper) {
} }
}; };
function _setRo(ro) {
if (ro !== _ro)
_ro = ro;
return _ro;
}
// ----- Returned Module ------------------------------ // ----- Returned Module ------------------------------
return { return {
name: TOOL_TYPE, name: TOOL_TYPE,
tool: new paper.Tool(toolDef), tool: new paper.Tool(toolDef),
setRo: _setRo,
registerEvent: function(eventName, evt) { _events[eventName] = evt; }, registerEvent: function(eventName, evt) { _events[eventName] = evt; },
exportJSON: exportJSON, exportJSON: exportJSON,
importJSON: importJSON importJSON: importJSON
......
...@@ -28,8 +28,9 @@ define([ ...@@ -28,8 +28,9 @@ define([
var hitItem = null; var hitItem = null;
var itemModified = false; var itemModified = false;
var _ro = false; // ReadOnly status
var _tool = null; // this paper.Tool (will be referenced after creation) var _tool; // this paper.Tool (will be referenced after creation)
var _tools = null; // a reference of the tools module var _tools = null; // a reference of the tools module
// Events // Events
...@@ -449,9 +450,16 @@ define([ ...@@ -449,9 +450,16 @@ define([
}; };
_tool = new paper.Tool(toolDef); _tool = new paper.Tool(toolDef);
function _setRo(ro) {
_selectAllLayers = ro;
_editing = !ro;
return ro;
}
return { return {
name: TOOL_TYPE, name: TOOL_TYPE,
tool: _tool, tool: _tool,
setRo: _setRo,
registerEvent: function(eventName, evt) { _events[eventName] = evt; }, registerEvent: function(eventName, evt) { _events[eventName] = evt; },
_tools: null _tools: null
}; };
......
...@@ -9,6 +9,8 @@ define(["paper", "jquery"], function (paper, $) { ...@@ -9,6 +9,8 @@ define(["paper", "jquery"], function (paper, $) {
var input = null; // the input helper var input = null; // the input helper
var overlay = null; // the overlay div used to catch mouse click when input is active var overlay = null; // the overlay div used to catch mouse click when input is active
var _ro = false; // local value of ReadOnly Status
// Events // Events
var _events = { var _events = {
annotationAdded: null, annotationAdded: null,
...@@ -107,6 +109,7 @@ define(["paper", "jquery"], function (paper, $) { ...@@ -107,6 +109,7 @@ define(["paper", "jquery"], function (paper, $) {
function _startEdit(myText) { function _startEdit(myText) {
if (edit) { _terminateEdit(false); } if (edit) { _terminateEdit(false); }
if (_ro) return;
edit = true; edit = true;
if (!input) { if (!input) {
...@@ -250,6 +253,7 @@ define(["paper", "jquery"], function (paper, $) { ...@@ -250,6 +253,7 @@ define(["paper", "jquery"], function (paper, $) {
// ----- Tool Def ------------------------------------- // ----- Tool Def -------------------------------------
var toolDef = { var toolDef = {
onMouseDown: function(event){ onMouseDown: function(event){
if (_ro) return;
var hitResult = paper.project.activeLayer.hitTest(event.point, hitOptions); var hitResult = paper.project.activeLayer.hitTest(event.point, hitOptions);
if (hitResult) { if (hitResult) {
...@@ -355,12 +359,18 @@ define(["paper", "jquery"], function (paper, $) { ...@@ -355,12 +359,18 @@ define(["paper", "jquery"], function (paper, $) {
return json; return json;
} }
function _setRo(ro) {
if (ro !== _ro)
_ro = ro;
return _ro;
}
// ----- Returned Module ------------------------------ // ----- Returned Module ------------------------------
return { return {
name: TOOL_TYPE, name: TOOL_TYPE,
tool: new paper.Tool(toolDef), tool: new paper.Tool(toolDef),
setRo: _setRo,
exportJSON: exportJSON, exportJSON: exportJSON,
importJSON: importJSON, importJSON: importJSON,
registerEvent: function(eventName, evt) { _events[eventName] = evt; } registerEvent: function(eventName, evt) { _events[eventName] = evt; }
......
...@@ -98,6 +98,8 @@ function($, _, Signal, paper, config, view, io, tools, attributes, Users, export ...@@ -98,6 +98,8 @@ function($, _, Signal, paper, config, view, io, tools, attributes, Users, export
_annotationListCtnr = $("#annotation-list-container"); _annotationListCtnr = $("#annotation-list-container");
_canvasCtnrTop = _canvasCtnr.offset().top + _canvasToolBar.outerHeight(); _canvasCtnrTop = _canvasCtnr.offset().top + _canvasToolBar.outerHeight();
window.DBG = tools;
//$("#annotation-property-panel").remove(); //$("#annotation-property-panel").remove();
//$("body").addClass("mode-"+config.mode); //$("body").addClass("mode-"+config.mode);
...@@ -612,6 +614,7 @@ function($, _, Signal, paper, config, view, io, tools, attributes, Users, export ...@@ -612,6 +614,7 @@ function($, _, Signal, paper, config, view, io, tools, attributes, Users, export
// Reset tool to select, to avoid having an editing tool active in review mode // Reset tool to select, to avoid having an editing tool active in review mode
tools.activateTool('select'); tools.activateTool('select');
tools.setRo(config.annotable.locked || (mode === 'review'));
if (mode === 'review') { if (mode === 'review') {
if (navTabs.data('loaded')) { if (navTabs.data('loaded')) {
...@@ -682,6 +685,7 @@ function($, _, Signal, paper, config, view, io, tools, attributes, Users, export ...@@ -682,6 +685,7 @@ function($, _, Signal, paper, config, view, io, tools, attributes, Users, export
function initTools(param) { function initTools(param) {
param = $.extend({}, {disabled: false}, param || {}); param = $.extend({}, {disabled: false}, param || {});
tools.setRo(param.disabled);
$("[data-tool-name]").each(function(){ $("[data-tool-name]").each(function(){
var $toolBtn = $(this); var $toolBtn = $(this);
...@@ -700,7 +704,7 @@ function($, _, Signal, paper, config, view, io, tools, attributes, Users, export ...@@ -700,7 +704,7 @@ function($, _, Signal, paper, config, view, io, tools, attributes, Users, export
tools.activateTool(toolName); tools.activateTool(toolName);
}); });
} }
if ($(this).data("toolName")===config.ui.initial_tool) { if ($(this).data("toolName") === config.ui.initial_tool) {
$(this).click(); $(this).click();
} }
}); });
......
...@@ -132,8 +132,18 @@ define([ ...@@ -132,8 +132,18 @@ define([
this.sharingPropEl this.sharingPropEl
.toggleClass("aom-prop-locked", locked) .toggleClass("aom-prop-locked", locked)
.toggleClass("aom-prop-unlocked", !locked); .toggleClass("aom-prop-unlocked", !locked);
this.propListEl
.toggleClass("aom-prop-locked", locked)
.toggleClass("aom-prop-unlocked", !locked);
this.sharingPropEl.find("[name=aom-prop-shared]").val([sharingMode]); var sharingModeSelect = this.sharingPropEl.find("[name=aom-prop-shared]");
console.log("sharingMode", sharingMode);
if (_.isUndefined(sharingMode) || sharingMode === "" ) {
sharingModeSelect.attr("disabled", "disabled");
} else {
sharingModeSelect.removeAttr("disabled");
}
sharingModeSelect.val([sharingMode]);
this.publicPublishEl.val([publicPublish]); this.publicPublishEl.val([publicPublish]);
this.propShMdParamsAll.addClass("hidden"); this.propShMdParamsAll.addClass("hidden");
if (sharingMode) { if (sharingMode) {
......
...@@ -1633,6 +1633,47 @@ canvas.cursor-tool-arrow2 { ...@@ -1633,6 +1633,47 @@ canvas.cursor-tool-arrow2 {
letter-spacing: 1px; letter-spacing: 1px;
font-size: 10px; font-size: 10px;
} }
.aom-info-panel .panel-body .aom-prop-lock-but {
margin-top: -5px;
}
.aom-info-panel .panel-body .aom-prop-unlocked-status,
.aom-info-panel .panel-body .aom-prop-locked-status {
display: none;
}
.aom-info-panel .panel-body .aom-prop-unlocked .aom-prop-unlocked-status {
display: inline;
}
.aom-info-panel .panel-body .aom-prop-unlocked .aom-prop-locked-status {
display: none;
}
.aom-info-panel .panel-body .aom-prop-locked .aom-prop-unlocked-status {
display: none;
}
.aom-info-panel .panel-body .aom-prop-locked .aom-prop-locked-status {
display: inline;
}
.aom-info-panel .panel-body .aom-prop-locked .aom-prop-locked-status.alert {
display: block;
margin: 5px 15px 10px;
padding: 10px;
}
.aom-info-panel .panel-body .aom-prop-locked .popover {
color: #333333;
font-size: 12px;
}
.aom-info-panel .panel-body .aom-prop-locked .popover-title {
font-size: 12px;
font-weight: bold;
}
.aom-info-panel .panel-body .aom-prop-locked .help-block {
display: none;
}
.aom-info-panel .panel-body .aom-prop-locked-info {
cursor: pointer;
}
.aom-info-panel .panel-body .aom-prop-locked-info:hover {
text-decoration: underline;
}
.aom-info-panel .panel-body .aom-info-share h5 { .aom-info-panel .panel-body .aom-info-share h5 {
margin: 10px 15px; margin: 10px 15px;
} }
...@@ -1661,41 +1702,6 @@ canvas.cursor-tool-arrow2 { ...@@ -1661,41 +1702,6 @@ canvas.cursor-tool-arrow2 {
font-style: italic; font-style: italic;
color: #6f6f6f; color: #6f6f6f;
} }
.aom-info-panel .panel-body .aom-info-share .aom-prop-lock-but {
margin-top: -5px;
}
.aom-info-panel .panel-body .aom-info-share .aom-prop-unlocked-status,
.aom-info-panel .panel-body .aom-info-share .aom-prop-locked-status {
display: none;
}
.aom-info-panel .panel-body .aom-info-share.aom-prop-unlocked .aom-prop-unlocked-status {
display: inline;
}
.aom-info-panel .panel-body .aom-info-share.aom-prop-unlocked .aom-prop-locked-status {
display: none;
}
.aom-info-panel .panel-body .aom-info-share.aom-prop-locked .aom-prop-unlocked-status {
display: none;
}
.aom-info-panel .panel-body .aom-info-share.aom-prop-locked .aom-prop-locked-status {
display: inline;
}
.aom-info-panel .panel-body .aom-info-share.aom-prop-locked .aom-prop-locked-status.alert {
display: block;
margin: 5px 15px 10px;
padding: 10px;
}
.aom-info-panel .panel-body .aom-info-share.aom-prop-locked .popover {
color: #333333;
font-size: 12px;
}
.aom-info-panel .panel-body .aom-info-share.aom-prop-locked .popover-title {
font-size: 12px;
font-weight: bold;
}
.aom-info-panel .panel-body .aom-info-share.aom-prop-locked .help-block {
display: none;
}
.aom-info-panel .panel-body .aom-info-share form { .aom-info-panel .panel-body .aom-info-share form {
position: relative; position: relative;
overflow: hidden; overflow: hidden;
...@@ -1710,12 +1716,6 @@ canvas.cursor-tool-arrow2 { ...@@ -1710,12 +1716,6 @@ canvas.cursor-tool-arrow2 {
width: 100%; width: 100%;
z-index: 100; z-index: 100;
} }
.aom-info-panel .panel-body .aom-info-share .aom-prop-locked-info {
cursor: pointer;
}
.aom-info-panel .panel-body .aom-info-share .aom-prop-locked-info:hover {
text-decoration: underline;
}
#aom-shared-images-list .aom-list-item .btn-toolbar .aom-item-sh-status { #aom-shared-images-list .aom-list-item .btn-toolbar .aom-item-sh-status {
display: none; display: none;
} }
......
...@@ -179,6 +179,47 @@ ...@@ -179,6 +179,47 @@
letter-spacing: 1px; letter-spacing: 1px;
font-size: 10px; font-size: 10px;
} }
.aom-info-panel .panel-body .aom-prop-lock-but {
margin-top: -5px;
}
.aom-info-panel .panel-body .aom-prop-unlocked-status,
.aom-info-panel .panel-body .aom-prop-locked-status {
display: none;
}
.aom-info-panel .panel-body .aom-prop-unlocked .aom-prop-unlocked-status {
display: inline;