Ajout du code du finder ajax depuis le dépôt de FCK.
authorBenoît Pin <pin@cri.ensmp.fr>
Tue, 16 Aug 2011 11:22:13 +0000 (13:22 +0200)
committerBenoît Pin <pin@cri.ensmp.fr>
Tue, 16 Aug 2011 11:22:13 +0000 (13:22 +0200)
skins/ckeditor/config.js
skins/ckeditor/filemanager/browser/mac_finder/_graphics/folderish_icons.psd [new file with mode: 0644]
skins/ckeditor/filemanager/browser/mac_finder/browser.css [new file with mode: 0644]
skins/ckeditor/filemanager/browser/mac_finder/browser.html.dtml [new file with mode: 0644]
skins/ckeditor/filemanager/browser/mac_finder/connectors/plinn/connector.py [new file with mode: 0644]
skins/ckeditor/filemanager/browser/mac_finder/images/folderish-selected.gif [new file with mode: 0644]
skins/ckeditor/filemanager/browser/mac_finder/images/folderish.gif [new file with mode: 0644]
skins/ckeditor/filemanager/browser/mac_finder/images/folderishNode.gif [new file with mode: 0644]

index 9467812..bb14ec7 100644 (file)
@@ -22,5 +22,5 @@ CKEDITOR.editorConfig = function( config )
        ];\r
        \r
        config.height = '500px';\r
-       config.filebrowserBrowseUrl = CKEDITOR.basePath;\r
+       config.filebrowserBrowseUrl = CKEDITOR.basePath + 'filemanager/browser/mac_finder/browser.html?Connector=connectors/plinn/connector';\r
 };
\ No newline at end of file
diff --git a/skins/ckeditor/filemanager/browser/mac_finder/_graphics/folderish_icons.psd b/skins/ckeditor/filemanager/browser/mac_finder/_graphics/folderish_icons.psd
new file mode 100644 (file)
index 0000000..69fe1b3
Binary files /dev/null and b/skins/ckeditor/filemanager/browser/mac_finder/_graphics/folderish_icons.psd differ
diff --git a/skins/ckeditor/filemanager/browser/mac_finder/browser.css b/skins/ckeditor/filemanager/browser/mac_finder/browser.css
new file mode 100644 (file)
index 0000000..cf93b14
--- /dev/null
@@ -0,0 +1,68 @@
+body {
+       margin:0;
+       padding:0;
+/*     overflow-x : scroll;*/
+}
+#finder {
+       position : relative;
+       border : none;
+       vertical-align : top;
+       font-family : Arial, Helvetica, Geneva, Swiss, SunSans-Regular, sans-serif;
+       font-size : small;
+}
+
+
+#finder td {
+/*     width : 200px;*/
+       padding : 0;
+}
+
+#finder ul {
+/*     float : left;*/
+       list-style : none;
+       margin : 0;
+       padding : 0;
+       overflow-y : scroll;
+}
+#finder li {
+       padding-left : 5px;
+       margin : 2px 0;
+       cursor : default;
+/*     vertical-align : middle*/
+}
+
+#finder li.contentish {
+       /* nothing special */
+}
+
+#finder li.contentish-selected {
+       background-color : #3875d7;
+       color : white;
+}
+
+
+#finder li.folderish {
+       background : url(images/folderish.gif) center right no-repeat;
+}
+
+#finder li.folderish-selected {
+       background : url(images/folderish-selected.gif) center right no-repeat #3875d7 ;
+       color : white;
+}
+
+
+#finder img {
+       margin-right : 3px;
+       vertical-align : middle;
+}
+
+.finder_preview {
+       font-size : 95%;
+}
+.finder_preview th {
+       color : #7f7f7f;
+       text-align : right;
+}
+.finder_preview .thumbnail {
+       text-align:center;
+}
\ No newline at end of file
diff --git a/skins/ckeditor/filemanager/browser/mac_finder/browser.html.dtml b/skins/ckeditor/filemanager/browser/mac_finder/browser.html.dtml
new file mode 100644 (file)
index 0000000..be15cd2
--- /dev/null
@@ -0,0 +1,351 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+       "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html>
+       <head>
+               <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
+               <title>Site browser</title>
+               <link rel="stylesheet" href="browser.css" type="text/css" media="screen" title="Browser style" charset="utf-8" />
+               <script type="text/javascript" language="javascript" charset="utf-8" src="epoz_script_detect.js"></script>
+               <script type="text/javascript" language="javascript" charset="utf-8" src="javascript_events_api.js"></script>
+               <script type="text/javascript" language="javascript" charset="utf-8" src="sarissa.js"></script>
+               <script type="text/javascript" language="javascript" charset="utf-8">
+               // <![CDATA[
+               /* keyboard keycodes */
+               var keyLeft = 37, keyUp = 38, keyRight = 39, keyDown = 40, keyEnter = 13;
+               
+               /* globals variables */
+               var finder, finderContent, cellWidth, currentColumn;
+               var scrollbarPlaceholder_offset = 0;
+               var scrollXStep = 25, scrollTimeStep = 10;
+               var ressourceType = GetUrlParam('Type');
+               var sConnUrl = GetUrlParam( 'Connector' ) ;
+               var baseDepth = 0;
+               if ( sConnUrl.substr(0,1) != '/' && sConnUrl.indexOf( '://' ) < 0 )
+                       sConnUrl = window.location.href.replace( /browser.html.*$/, '' ) + sConnUrl ;
+               var getWindowWidth = (window.innerWidth != undefined) ? function(){return window.innerWidth;} : function(){return document.body.parentElement.clientWidth;};
+               var getWindowHeight = (window.innerHeight != undefined) ? function(){return window.innerHeight;} : function(){return document.body.parentElement.clientHeight;};
+
+               
+               function _initBrowser(){
+                       finder = document.getElementById('finder');
+                       finder.colCpt = 3; // column counter;
+                       finderContent = document.getElementById('finderContent');
+                       cellWidth = Math.floor(getWindowWidth() / 3);
+                       
+                       addListener(window, 'resize', resizeBrowser);
+                       addListener(finder, 'click', onClickHandler);
+                       addListener(finder, 'dblclick', onDblClickHandler);
+                       var path = GetUrlParam('path');
+                       path = (path) ? path : '/';
+                       var level = -1;
+                       for (var i = 0 ; i<path.length ; i++){
+                               if (path.charAt(i) == '/')
+                                       level += 1;
+                       }
+                       baseDepth = level;
+
+                       populateBrowser('ls', path);
+                       
+                       if (browser.isGecko)
+                               document.body.style.overflowX = 'scroll';
+                       resizeBrowser();
+                       scrollbarPlaceholder_offset = (window.scrollMaxY) ? window.scrollMaxY : document.body.offsetHeight - document.body.clientHeight;
+                       resizeBrowser();
+                       finder.style.width = cellWidth * 3 + "px";
+               }
+               addListener(window, 'load', _initBrowser);
+               addListener(document, 'keydown', onKeydownHandler);
+               
+               function onClickHandler(evt) {
+                       var li = getTargetedObject(evt);
+                       switch (li.tagName) {
+                               case 'IMG':
+                                       if (li.width != 16) // this img is a preview thumbnail.
+                                               return;
+                                       li = li.parentNode;
+                               case 'LI':
+                                 // click on the current selected row
+                                 if (currentColumn == li.parentNode && currentColumn.currentRow == li)
+                                   return;
+                                   
+                                       currentColumn = li.parentNode;
+                                       // hightlight row
+                                       if (currentColumn.currentRow) {
+                                               currentColumn.currentRow.className = currentColumn.currentRow.className.replace('-selected', '');
+                                       }
+                                       var command = li.className == 'folderish' ? 'ls' : 'info';
+                                       li.className += '-selected';
+                                       currentColumn.currentRow = li;
+
+                                       populateBrowser(command, li.path);
+                       }
+               }
+               
+               function onDblClickHandler(evt) {
+                 var li = getTargetedObject(evt);
+                 
+                 if(li.tagName != 'LI') {
+                     if (li.tagName == 'IMG' && li.parentNode.tagName == 'LI')
+                       li = t.parentNode;
+                     else
+                       return;
+                 }
+                 switch(window.parent.name) {
+               case 'FCKeditorDialog_PlinnImage' :
+                   if (li.className == 'contentish-selected') {
+                                               window.parent.updateOrInsertImage(li.link);
+                                               window.close();
+                                     }
+                                           break;
+                                 case 'FCKBrowseWindow' :
+                                                       window.opener.SetUrl(li.link);
+                                                       window.close();
+                                                       break;
+           }
+               }
+
+               function onKeydownHandler(evt) {
+                       evt = (evt) ? evt : window.event;
+                       if(!currentColumn) currentColumn = finder.getElementsByTagName('ul')[0];
+                       if(!currentColumn.currentRow) {
+                               raiseMouseEvent(currentColumn.firstChild,'click');
+                               return;
+                       }
+                       
+                       var ob, evtType='click';
+                       switch (evt.keyCode) {
+                               case keyUp :
+                                       ob = currentColumn.currentRow.previousSibling;
+                                       break;
+                               case keyDown :
+                                       ob = currentColumn.currentRow.nextSibling;
+                                       break;
+                               case keyLeft :
+                                       var currentLevel = parseInt(currentColumn.parentNode.id.slice(6));
+                                       if (currentLevel) {
+                                               ob = document.getElementById('level-' + (currentLevel - 1)).firstChild;
+                                               if (ob.nodeType == 3) // text node
+                                                       ob = ob.nextSibling
+                                               ob = ob.currentRow;
+                                       }
+                                       break;
+                               case keyRight :
+                                       if(currentColumn.currentRow.className != 'folderish-selected')
+                                               return;
+                                       ob = document.getElementById('level-' + (parseInt(currentColumn.parentNode.id.slice(6)) + 1)).firstChild.firstChild;
+                                       break;
+                               case keyEnter :
+                                 ob = currentColumn.currentRow;
+                                 evtType = 'dblclick'
+                                 break;
+                       };
+                       if (ob)
+                               raiseMouseEvent(ob, evtType);
+               }
+               
+               function resizeBrowser() {
+                       var columns = finder.getElementsByTagName('ul');
+                       var col;
+                       for (var i=0 ; i<columns.length ; i++) {
+                               col = columns[i];
+                               col.style.height = getWindowHeight() - scrollbarPlaceholder_offset + "px";;
+                               
+                       }
+                       //document.body.style.width = getWindowWidth();
+               }
+               
+               /* from fck default browser */
+               function GetUrlParam( paramName )
+               {
+                       var oRegex = new RegExp( '[\?&]' + paramName + '=([^&]+)', 'i' ) ;
+                       var oMatch = oRegex.exec( window.location.search ) ;
+
+                       if ( oMatch && oMatch.length > 1 )
+                               return unescape(oMatch[1]) ;
+                       else
+                               return '' ;
+               }
+               
+
+               
+               function populateBrowser(command, path) {
+                       var prevColNum = finder.colCpt;
+                       var level = -1;
+                       for (var i = 0 ; i<path.length ; i++){
+                               if (path.charAt(i) == '/')
+                                       level += 1;
+                       }
+                       level = level - baseDepth;
+                       
+                       // prepare / cleanup columns
+                       var cellLevel, startCleanup = 3;
+                       switch (level) {
+                               case 0 : // initialization case
+                                       startCleanup = 0;
+                                       cellLevel = document.getElementById('level-0');
+                                       cellLevel.style.width = cellWidth + "px";
+                                       // remove default content
+                                       cellLevel.removeChild(cellLevel.firstChild);
+                                       
+                                       // cosmetic: display the second col with a scrollbar
+                                       var c1 = document.createElement('td');
+                                       c1.id = "level-1";
+                                       c1.style.width = cellWidth + "px";
+                                       c1.appendChild(document.createElement('ul'));
+                                       finderContent.appendChild(c1);
+                                       
+                                       // cosmetic: display the third col without scrollbar
+                                       var c2 = document.createElement('td');
+                                       c2.id = "level-2";
+                                       c2.style.width = cellWidth + "px";
+                                       finderContent.appendChild(c2);
+                                       break;
+
+                               case 1 :
+                                       cellLevel = document.getElementById("level-1");
+                                       cellLevel.removeChild(cellLevel.firstChild);
+                                       var c2 = document.getElementById("level-2");
+                                       var ul = c2.firstChild;
+                                       if (ul)
+                                               c2.removeChild(ul);
+                                       break;
+
+                               case 2 :
+                                       cellLevel = document.getElementById("level-2");
+                                       var ul = cellLevel.firstChild;
+                                       if (ul) {
+                                               cellLevel.removeChild(ul);
+                                       }
+                                       break;
+                                       
+                               default :
+                                       cellLevel = document.getElementById("level-" + level);
+                                       if (!cellLevel) {
+                                               cellLevel = document.createElement('td');
+                                               cellLevel.id = "level-" + level;
+                                               cellLevel.style.width = cellWidth + "px";
+                                               finderContent.appendChild(cellLevel);
+                                               startCleanup = 0;
+                                               finder.colCpt += 1;
+                                       }
+                                       else {
+                                               cellLevel.removeChild(cellLevel.firstChild);
+                                               startCleanup = level + 1
+                                       }
+                       }
+                       if (startCleanup) {
+                               var nextColumn = document.getElementById("level-" + startCleanup);
+                               while (nextColumn) {
+                                       finderContent.removeChild(nextColumn);
+                                       finder.colCpt -= 1;
+                                       nextColumn = document.getElementById("level-" + ++startCleanup);
+                               }
+                       }
+                       
+                       // request
+                       var req = new XMLHttpRequest();
+                       req.open("POST", sConnUrl, false); // synchrone
+                       req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=utf-8");
+                       req.send("command=" + command + "&path="+escape(path) + "&Type=" + ressourceType);
+                       var respDom = req.responseXML.documentElement;
+                       
+                       
+                       var list = document.createElement('UL');
+                       list.style.height= getWindowHeight() - scrollbarPlaceholder_offset + "px";
+                       cellLevel.appendChild(list);
+                       
+                       switch (respDom.tagName) {
+                               case 'ls' :
+                                       // import listing
+                                       var rows = respDom.getElementsByTagName('row');
+                                       var row, listItem, icon;
+                       
+                                       for (var i = 0 ; i<rows.length ; i++){
+                                               row = rows[i];
+                                               listItem = document.createElement('li');
+                                               if (row.getAttribute('folderish') != "0")
+                                                       listItem.className = 'folderish';
+                                               else
+                                                       listItem.className = 'contentish';
+                               
+                                               icon = document.createElement('img');
+                                               with (icon) {
+                                                       src = row.getAttribute('icon');
+                                                       width = "16";
+                                                       height = "16";
+                                                       border = "0";
+                                               }
+                               
+                                               listItem.path = row.getAttribute('path');
+                                               listItem.link = row.getAttribute('link');
+                                               listItem.appendChild(icon);
+                                               listItem.appendChild(document.createTextNode(row.firstChild.nodeValue));
+                                               list.appendChild(listItem);
+                                       }
+                                       break;
+                               case 'info' :
+                                       var li = document.createElement('li');
+                                       list.appendChild(li);
+                                       li.innerHTML = respDom.firstChild.nodeValue;
+                                       
+                                       // add create link button
+                                       li = document.createElement('li');
+                                       li.style.textAlign = 'center';
+                                       var createLinkBtn = document.createElement('button');
+                                       var text = (ressourceType == 'Image') ? 'Insert' : 'Create link';
+                                       createLinkBtn.appendChild(document.createTextNode(text));
+                                       
+                                       createLinkBtn.onclick = function(){
+                                           var url = respDom.lastChild.firstChild.nodeValue;
+                                           switch(window.parent.name) {
+                                               case 'FCKeditorDialog_PlinnImage' :
+                                                           window.parent.updateOrInsertImage(url);
+                                                             break;
+                                                 case 'FCKBrowseWindow' :
+                                                 default:
+                                                               window.opener.SetUrl(url);
+                                                               break;
+                                           }
+                                           window.close();
+                                       };
+                                       
+                                       list.appendChild(li);
+                                       li.appendChild(createLinkBtn);
+                                       break;
+                       }
+                       
+                       if (prevColNum != finder.colCpt) {
+                               var finderWidth = finder.colCpt * cellWidth;
+                               finder.style.width = finderWidth + "px";
+                               if (finder.colCpt - prevColNum > 0) {
+                                       var start = (window.scrollX) ? window.scrollX : document.body.scrollLeft;
+                                       var stop = finder.colCpt * cellWidth - getWindowWidth();
+                                       smoothScroll(start, stop);
+                               }
+                       }
+               }
+               
+               function smoothScroll(start, stop) {
+                       start += scrollXStep;
+                       window.scroll(start, 0);
+                       if (start < stop) {
+                               setTimeout('smoothScroll(' + start + ', ' + stop + ')', scrollTimeStep);
+                       }
+               }
+
+               
+               // ]]>
+               </script>
+       </head>
+       <body>
+       <table  id="finder" cellspacing="0">
+       <tr id="finderContent">
+       <td id="level-0"><ul>
+                       <li class="folderish">Folder</li>
+                       <li class="contentish">Content</li>
+               </ul>
+       </td>
+       </tr>
+       </table>
+  </body>
+</html>
\ No newline at end of file
diff --git a/skins/ckeditor/filemanager/browser/mac_finder/connectors/plinn/connector.py b/skins/ckeditor/filemanager/browser/mac_finder/connectors/plinn/connector.py
new file mode 100644 (file)
index 0000000..61d0eae
--- /dev/null
@@ -0,0 +1,73 @@
+##parameters=command, path, Type=None
+from Products.CMFCore.utils import getToolByName
+from Products.CMFCore.permissions import View
+mtool = getToolByName(context, 'portal_membership')
+checkView = lambda o : mtool.checkPermission(View, o)
+utool = getToolByName(context, 'portal_url')
+portal = utool.getPortalObject()
+
+def replaceXMLEntities(text) :
+       for c, ent in (('<', '&lt;'), ('>', '&gt;'), ('&', '&amp;')) :
+               text = text.replace(c, ent)
+       return text
+
+ob = portal
+path = path.replace('\\', '/')
+path = path.strip('/')
+
+if path :
+       for name in path.split('/') :
+               ob = getattr(ob, name)
+
+if command == 'ls' :
+       objects = []
+       if ob.isPrincipiaFolderish :
+               if Type == 'Image' : filter = {'portal_type' : ['Plinn Folder', 'Portfolio', 'Photo']}
+               else : filter = {}
+               objects = ob.listNearestFolderContents(contentFilter = filter)
+               objects = sequence.sort( objects, (('title_or_id', 'nocase', 'asc'),) )
+
+       # xml printing
+       print '<ls>'
+       for o in objects :
+               path = o.getPhysicalPath()
+               encodedPath = ''
+               partObject = portal
+               for name in path[1:] :
+                       partObject = getattr(partObject, name)
+                       sep = checkView(partObject) and '/' or '\\'
+                       encodedPath += sep+name
+               
+               row = '<row path="%(path)s" folderish="%(folderish)s" icon="%(icon)s" link="%(link)s">%(title)s</row>' % {
+                       'path' : encodedPath,
+                       'folderish' : o.isPrincipiaFolderish,
+                       'icon' : o.getIcon(),
+                       'title' : replaceXMLEntities(o.title_or_id()),
+                       'link' : o.absolute_url()
+                       }
+               print row
+       print '</ls>'
+
+elif command == 'info':
+       #linkFunction = (Type == 'Image') and (lambda o : o.absolute_url() + '/index_html') or (lambda o : o.absolute_url())
+       linkFunction = lambda o : o.absolute_url()
+       ti = ob.getTypeInfo()
+       method_id = ti.queryMethodID('info')
+       meth = method_id and getattr(ob, method_id) or (lambda:'Not implemented')
+       lines = []
+       pr = lines.append
+       pr('<info>')
+       # print info summary in a CDATA section
+       pr('<![CDATA[')
+       pr(meth())
+       pr(']]>')
+       # print the url link in a <link> tag
+       pr('<link>')
+       pr(linkFunction(ob))
+       pr('</link>')
+       pr('</info>')
+       print ''.join(lines)
+
+
+context.REQUEST.RESPONSE.setHeader('content-type', 'text/xml; charset=utf-8')
+return printed
\ No newline at end of file
diff --git a/skins/ckeditor/filemanager/browser/mac_finder/images/folderish-selected.gif b/skins/ckeditor/filemanager/browser/mac_finder/images/folderish-selected.gif
new file mode 100644 (file)
index 0000000..ebad9f6
Binary files /dev/null and b/skins/ckeditor/filemanager/browser/mac_finder/images/folderish-selected.gif differ
diff --git a/skins/ckeditor/filemanager/browser/mac_finder/images/folderish.gif b/skins/ckeditor/filemanager/browser/mac_finder/images/folderish.gif
new file mode 100644 (file)
index 0000000..c359a8f
Binary files /dev/null and b/skins/ckeditor/filemanager/browser/mac_finder/images/folderish.gif differ
diff --git a/skins/ckeditor/filemanager/browser/mac_finder/images/folderishNode.gif b/skins/ckeditor/filemanager/browser/mac_finder/images/folderishNode.gif
new file mode 100644 (file)
index 0000000..2cb7b83
Binary files /dev/null and b/skins/ckeditor/filemanager/browser/mac_finder/images/folderishNode.gif differ