@ -1034,46 +1034,28 @@ define([
if ( ! hashes || ( ! hashes . editHash && ! hashes . viewHash ) ) { return ; }
if ( ! hashes || ( ! hashes . editHash && ! hashes . viewHash ) ) { return ; }
var rights = h ( 'div' , [
var parsed = Hash . parsePadUrl ( pathname ) ;
var canPresent = [ 'code' , 'slide' ] . indexOf ( parsed . type ) !== - 1 ;
var rights = h ( 'div.msg' , [
h ( 'label' , Messages . share _linkAccess ) ,
h ( 'label' , Messages . share _linkAccess ) ,
h ( 'br' ) ,
h ( 'br' ) ,
UI . createRadio ( 'accessRights' , 'cp-share-editable-false' ,
UI . createRadio ( 'accessRights' , 'cp-share-editable-false' ,
Messages . share _linkView , true , { mark : { tabindex : 1 } } ) ,
Messages . share _linkView , true , { mark : { tabindex : 1 } } ) ,
UI. createRadio ( 'accessRights' , 'cp-share-present' ,
canPresent ? UI. createRadio ( 'accessRights' , 'cp-share-present' ,
Messages . share _linkPresent , false , { mark : { tabindex : 1 } } ) , // XXX only show this if code or slide pad
Messages . share _linkPresent , false , { mark : { tabindex : 1 } } ) : undefined ,
UI . createRadio ( 'accessRights' , 'cp-share-editable-true' ,
UI . createRadio ( 'accessRights' , 'cp-share-editable-true' ,
Messages . share _linkEdit , false , { mark : { tabindex : 1 } } ) ,
Messages . share _linkEdit , false , { mark : { tabindex : 1 } } ) ,
h ( 'br' ) ,
h ( 'br' ) ,
] ) ;
] ) ;
// Share link tab
var content = [ ] ;
var sfContent = [
h ( 'label' , Messages . sharedFolders _share ) ,
h ( 'br' ) ,
] ;
var padContent = [
UI . createCheckbox ( 'cp-share-embed' , Messages . share _linkEmbed , false , { mark : { tabindex : 1 } } ) ,
h ( 'br' ) ,
] ;
if ( config . sharedFolder ) { Array . prototype . push . apply ( content , sfContent ) ; }
Array . prototype . push . apply ( content ) ;
if ( ! config . sharedFolder ) { Array . prototype . push . apply ( content , padContent ) ; }
content . push ( UI . dialog . selectable ( '' , { id : 'cp-share-link-preview' , tabindex : 1 } ) ) ;
// XXX remove LESS code for cp-share-columns if not using anymore
//var mainShareColumn = h('div.cp-share-column.contains-nav', content);
var link = h ( 'div.cp-share-modal' , content ) ;
var saveValue = function ( ) {
var saveValue = function ( ) {
var edit = Util . isChecked ( $ ( rights ) . find ( '#cp-share-editable-true' ) ) ;
var edit = Util . isChecked ( $ ( rights ) . find ( '#cp-share-editable-true' ) ) ;
var embed = Util . isChecked ( $ ( link ) . find ( '#cp-share-embed' ) ) ;
var present = Util . isChecked ( $ ( rights ) . find ( '#cp-share-present' ) ) ;
var present = Util . isChecked ( $ ( rights ) . find ( '#cp-share-present' ) ) ;
common . setAttribute ( [ 'general' , 'share' ] , {
common . setAttribute ( [ 'general' , 'share' ] , {
edit : edit ,
edit : edit ,
embed : embed ,
present : present
present : present
} ) ;
} ) ;
} ;
} ;
@ -1081,7 +1063,7 @@ define([
var getLinkValue = function ( initValue ) {
var getLinkValue = function ( initValue ) {
var val = initValue || { } ;
var val = initValue || { } ;
var edit = val . edit !== undefined ? val . edit : Util . isChecked ( $ ( rights ) . find ( '#cp-share-editable-true' ) ) ;
var edit = val . edit !== undefined ? val . edit : Util . isChecked ( $ ( rights ) . find ( '#cp-share-editable-true' ) ) ;
var embed = val . embed !== undefined ? val . embed : Util . isChecked ( $ ( link ) . find ( '#cp-share-embed' ) ) ;
var embed = val . embed ;
var present = val . present !== undefined ? val . present : Util . isChecked ( $ ( rights ) . find ( '#cp-share-present' ) ) ;
var present = val . present !== undefined ? val . present : Util . isChecked ( $ ( rights ) . find ( '#cp-share-present' ) ) ;
var hash = ( ! hashes . viewHash || ( edit && hashes . editHash ) ) ? hashes . editHash : hashes . viewHash ;
var hash = ( ! hashes . viewHash || ( edit && hashes . editHash ) ) ? hashes . editHash : hashes . viewHash ;
var href = origin + pathname + '#' + hash ;
var href = origin + pathname + '#' + hash ;
@ -1096,6 +1078,18 @@ define([
keys : [ 27 ] } ;
keys : [ 27 ] } ;
} ;
} ;
// Share link tab
var linkContent = config . sharedFolder ? [
h ( 'label' , Messages . sharedFolders _share ) ,
h ( 'br' ) ,
] : [
UI . createCheckbox ( 'cp-share-embed' , Messages . share _linkEmbed , false , { mark : { tabindex : 1 } } ) ,
h ( 'br' ) ,
] ;
linkContent . push ( UI . dialog . selectable ( '' , { id : 'cp-share-link-preview' , tabindex : 1 } ) ) ;
var link = h ( 'div.cp-share-modal' , linkContent ) ;
var linkButtons = [
var linkButtons = [
makeCancelButton ( ) ,
makeCancelButton ( ) ,
! config . sharedFolder && {
! config . sharedFolder && {
@ -1103,7 +1097,9 @@ define([
name : Messages . share _linkOpen ,
name : Messages . share _linkOpen ,
onClick : function ( ) {
onClick : function ( ) {
saveValue ( ) ;
saveValue ( ) ;
var v = getLinkValue ( ) ;
var v = getLinkValue ( {
embed : Util . isChecked ( $ ( link ) . find ( '#cp-share-embed' ) )
} ) ;
window . open ( v ) ;
window . open ( v ) ;
} ,
} ,
keys : [ [ 13 , 'ctrl' ] ]
keys : [ [ 13 , 'ctrl' ] ]
@ -1113,7 +1109,9 @@ define([
name : Messages . share _linkCopy ,
name : Messages . share _linkCopy ,
onClick : function ( ) {
onClick : function ( ) {
saveValue ( ) ;
saveValue ( ) ;
var v = getLinkValue ( ) ;
var v = getLinkValue ( {
embed : Util . isChecked ( $ ( link ) . find ( '#cp-share-embed' ) )
} ) ;
var success = Clipboard . copy ( v ) ;
var success = Clipboard . copy ( v ) ;
if ( success ) { UI . log ( Messages . shareSuccess ) ; }
if ( success ) { UI . log ( Messages . shareSuccess ) ; }
} ,
} ,
@ -1121,23 +1119,14 @@ define([
}
}
] ;
] ;
// update values for link preview when radio btns change
// disable edit share options if you don't have edit rights
if ( ! hashes . editHash ) {
$ ( rights ) . find ( '#cp-share-editable-false' ) . attr ( 'checked' , true ) ;
$ ( rights ) . find ( '#cp-share-editable-true' ) . removeAttr ( 'checked' ) . attr ( 'disabled' , true ) ;
} else if ( ! hashes . viewHash ) {
$ ( rights ) . find ( '#cp-share-editable-false' ) . removeAttr ( 'checked' ) . attr ( 'disabled' , true ) ;
$ ( rights ) . find ( '#cp-share-present' ) . removeAttr ( 'checked' ) . attr ( 'disabled' , true ) ;
$ ( rights ) . find ( '#cp-share-editable-true' ) . attr ( 'checked' , true ) ;
}
$ ( link ) . find ( '#cp-share-link-preview' ) . val ( getLinkValue ( ) ) ;
$ ( link ) . find ( '#cp-share-link-preview' ) . val ( getLinkValue ( ) ) ;
$ ( link ) . find ( 'input[type="radio"], input[type="checkbox"]' ) . on ( 'change' , function ( ) {
$ ( rights ) . find ( 'input[type="radio"]' ) . on ( 'change' , function ( ) {
$ ( link ) . find ( '#cp-share-link-preview' ) . val ( getLinkValue ( ) ) ;
} ) ;
$ ( link ) . find ( 'input[type="checkbox"]' ) . on ( 'change' , function ( ) {
$ ( link ) . find ( '#cp-share-link-preview' ) . val ( getLinkValue ( ) ) ;
$ ( link ) . find ( '#cp-share-link-preview' ) . val ( getLinkValue ( ) ) ;
} ) ;
} ) ;
// $link.append(UI.dialog.getButtons(shareButtons, config.onClose));
var frameLink = UI . dialog . customModal ( link , {
var frameLink = UI . dialog . customModal ( link , {
buttons : linkButtons ,
buttons : linkButtons ,
@ -1149,39 +1138,34 @@ define([
var hasFriends = Object . keys ( config . friends || { } ) . length !== 0 ;
var hasFriends = Object . keys ( config . friends || { } ) . length !== 0 ;
var onFriendShare = Util . mkEvent ( ) ;
var onFriendShare = Util . mkEvent ( ) ;
var friendsObject = hasFriends ? createShareWithFriends ( config , onFriendShare ) : {
var friendsObject = hasFriends ? createShareWithFriends ( config , onFriendShare ) : {
content : h ( 'p' , Messages . share _noContacts )
content : h ( 'p' , Messages . share _noContacts ) ,
button : { }
} ;
} ;
var friendsList = friendsObject . content ;
var friendsList = friendsObject . content ;
onFriendShare . reg ( saveValue ) ;
onFriendShare . reg ( saveValue ) ;
// XXX Don't display access rights if no contacts
// XXX Don't display access rights if no contacts
/// var contactsAccessRights = hasFriends ? createAccessRights('contact-rights') : '';
/// var contactsAccessRights = hasFriends ? createAccessRights('contact-rights') : '';
var contacts = h ( 'div.cp-share-modal' ) ;
var contactsContent = h ( 'div.cp-share-modal' ) ;
var $contacts = $ ( contacts ) ;
$ ( contactsContent ) . append ( friendsList ) ;
$ ( friendsList ) . appendTo ( $contacts ) ;
var contactButtons = [ makeCancelButton ( ) ,
var contactButtons = [ makeCancelButton ( ) ,
friendsObject . button ] ;
friendsObject . button ] ;
var frameContacts = UI . dialog . customModal ( contacts , {
var frameContacts = UI . dialog . customModal ( contacts Content , {
buttons : contactButtons ,
buttons : contactButtons ,
onClose : config . onClose ,
onClose : config . onClose ,
} ) ;
} ) ;
// Embed tab
// Embed tab
var getEmbedValue = function ( ) {
var getEmbedValue = function ( ) {
var hash = hashes . viewHash || hashes . editHash ;
var url = getLinkValue ( {
var href = origin + pathname + '#' + hash ;
embed : true
var parsed = Hash . parsePadUrl ( href ) ;
} ) ;
var url = origin + parsed . getUrl ( { embed : true , present : true } ) ;
return '<iframe src="' + url + '"></iframe>' ;
return '<iframe src="' + url + '"></iframe>' ;
} ;
} ;
var embed = h ( 'div.cp-share-modal' , [
var embed Content = h ( 'div.cp-share-modal' , [
h ( 'p' , Messages . viewEmbedTag ) ,
h ( 'p' , Messages . viewEmbedTag ) ,
h ( 'br' ) ,
h ( 'br' ) ,
UI . dialog . selectable ( getEmbedValue ( ) )
UI . dialog . selectable ( getEmbedValue ( ) )
@ -1191,15 +1175,13 @@ define([
className : 'primary' ,
className : 'primary' ,
name : Messages . share _linkCopy ,
name : Messages . share _linkCopy ,
onClick : function ( ) {
onClick : function ( ) {
var v = getLinkValue ( {
var v = getEmbedValue ( ) ;
embed : true
} ) ;
var success = Clipboard . copy ( v ) ;
var success = Clipboard . copy ( v ) ;
if ( success ) { UI . log ( Messages . shareSuccess ) ; }
if ( success ) { UI . log ( Messages . shareSuccess ) ; }
} ,
} ,
keys : [ 13 ]
keys : [ 13 ]
} ] ;
} ] ;
var frameEmbed = UI . dialog . customModal ( embed , {
var frameEmbed = UI . dialog . customModal ( embed Content , {
buttons : embedButtons ,
buttons : embedButtons ,
onClose : config . onClose ,
onClose : config . onClose ,
} ) ;
} ) ;
@ -1224,19 +1206,36 @@ define([
}
}
var modal = UI . dialog . tabs ( tabs ) ;
var modal = UI . dialog . tabs ( tabs ) ;
$ ( modal ) . find ( '.alertify-tabs-titles' ) . after ( rights ) ;
// XXX
// disable edit share options if you don't have edit rights
if ( ! hashes . editHash ) {
$ ( rights ) . find ( '#cp-share-editable-false' ) . attr ( 'checked' , true ) ;
$ ( rights ) . find ( '#cp-share-editable-true' ) . removeAttr ( 'checked' ) . attr ( 'disabled' , true ) ;
} else if ( ! hashes . viewHash ) {
$ ( rights ) . find ( '#cp-share-editable-false' ) . removeAttr ( 'checked' ) . attr ( 'disabled' , true ) ;
$ ( rights ) . find ( '#cp-share-present' ) . removeAttr ( 'checked' ) . attr ( 'disabled' , true ) ;
$ ( rights ) . find ( '#cp-share-editable-true' ) . attr ( 'checked' , true ) ;
}
common . getAttribute ( [ 'general' , 'share' ] , function ( err , val ) {
common . getAttribute ( [ 'general' , 'share' ] , function ( err , val ) {
val = val || { } ;
val = val || { } ;
if ( ( val . edit === false && hashes . viewHash ) || ! hashes . editHash ) {
if ( val . present && canPresent ) {
$ ( link ) . find ( '#cp-share-editable-false' ) . prop ( 'checked' , true ) ;
$ ( rights ) . find ( '#cp-share-editable-false' ) . prop ( 'checked' , false ) ;
$ ( link ) . find ( '#cp-share-editable-true' ) . prop ( 'checked' , false ) ;
$ ( rights ) . find ( '#cp-share-editable-true' ) . prop ( 'checked' , false ) ;
$ ( rights ) . find ( '#cp-share-present' ) . prop ( 'checked' , true ) ;
} else if ( ( val . edit === false && hashes . viewHash ) || ! hashes . editHash ) {
$ ( rights ) . find ( '#cp-share-editable-false' ) . prop ( 'checked' , true ) ;
$ ( rights ) . find ( '#cp-share-editable-true' ) . prop ( 'checked' , false ) ;
$ ( rights ) . find ( '#cp-share-present' ) . prop ( 'checked' , false ) ;
} else {
} else {
$ ( link ) . find ( '#cp-share-editable-true' ) . prop ( 'checked' , true ) ;
$ ( rights ) . find ( '#cp-share-editable-true' ) . prop ( 'checked' , true ) ;
$ ( link ) . find ( '#cp-share-editable-false' ) . prop ( 'checked' , false ) ;
$ ( rights ) . find ( '#cp-share-editable-false' ) . prop ( 'checked' , false ) ;
$ ( rights ) . find ( '#cp-share-present' ) . prop ( 'checked' , false ) ;
}
}
if ( val . embed ) { $ ( link ) . find ( '#cp-share-embed' ) . prop ( 'checked' , true ) ; }
if ( val . present ) { $ ( link ) . find ( '#cp-share-present' ) . prop ( 'checked' , true ) ; }
if ( config . sharedFolder ) {
delete val . embed ;
delete val . embed ;
if ( ! canPresent ) {
delete val . present ;
delete val . present ;
}
}
$ ( link ) . find ( '#cp-share-link-preview' ) . val ( getLinkValue ( val ) ) ;
$ ( link ) . find ( '#cp-share-link-preview' ) . val ( getLinkValue ( val ) ) ;