[app] Workin2gether - support request

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
12 messages Options
Reply | Threaded
Open this post in threaded view
|

[app] Workin2gether - support request

Hoffmann, Patrick

Hello,

 

currently I’m making an app for my cloud to prevent changes on files by multiple people at the same time.

The idea was:

-          Adding a fileaction for „lock“ the file.

-          See the lock status on mouseover

-          Forbid any actions with the locked file (deleting, renaming,replacing)

 

Currently I made some progress, but I think there is a lack of knowledge about the Owncloud constants.

At the moment I have the problem to really lock the line of the file in the OC filelist, showing the lockstatus automatically on page load, and lock files which have been shared from someones other share.

 

Is it possible to add the fileaction here called „Dateisperre“ with php and not js and can I somehow let the staus load automatically?

atm it’s showing the status after the first click and then after the second click it toggles the lockstate.

 

 

 

I’ve attached the full app project. Here are the important 2 files in my project:

[workin2gether.js]

 

$(document).ready(function(){

 

                        var text = "file lock";

                       

                        $.ajax({

        url: OC.filePath('files_w2g','ajax','l10n.php'),

        type: "post",

        data: { rawtext: text},

                                               async: false,

        success: function(data){text = data;},

    });

                       

    if (typeof FileActions !== 'undefined' && $('#dir').length>0) {

                                              

       

            FileActions.register('file',text,OC.PERMISSION_READ,function(){return OC.imagePath('files_w2g','w2g.svg')},function(filename){

                workin(filename,text);

            });

           

            FileActions.register('dir',text,OC.PERMISSION_READ,function(){return OC.imagePath('files_w2g','w2g.svg')},function(filename){

                workin(filename,text);

            });

    }

                       

});

 

 

function workin(filename,text)

{

    oc_dir = $('#dir').val();

    oc_path = oc_dir +'/'+filename;

                       

                        var _safe = "";

                       

                        if($('tr').filterAttr('data-file',filename).find('td.filename').find('a.name').find('span.fileactions').find("a.action").filterAttr('data-action',text).html().indexOf(text)!=-1)

                        {_safe = "true";}

                        else{_safe = "false";}

 

                        $.ajax({

        url: OC.filePath('files_w2g','ajax','workin2gether.php'),

        type: "post",

        data: { path: oc_path, safe: _safe},

        success: function(data){postmode(filename,data,text)},

    });

 

}

 

function postmode(filename,data,text)

{

                                               var html = '<img class="svg" src="'+OC.imagePath('files_w2g','w2g.svg')+'"></img> '+data;

                                               $('tr').filterAttr('data-file',filename).find('td.filename').find('a.name').find('span.fileactions').find("a.action").filterAttr('data-action',text).html(html);

}

 

 

[workin2gether.php]

<?php

 

/*

19.02.2014 Patrick Hoffmann

AGPL free to use :-)

*/

 

 

//Init translations

$l = \OCP\Util::getL10N('files_w2g');

 

//Requirements check

OCP\JSON::checkLoggedIn();

OCP\JSON::checkAppEnabled('files_w2g');

 

 

//Default path for lock files

$apath = "C:/xampp/htdocs/apps/files_w2g/lock/";

$storage = "D:/";

 

//Vars

$path = stripslashes($_POST['path']) ;

@$safe = @$_POST['safe'];

$ppath = lockname($path);

 

 

if(cleanPath($path)=="/Shared")

{                      //Exit if you want to lock the Share folder

                        echo "Forbidden";

                        return 1;

}

 

 

if(substr(cleanPath($path),0,7)=="/Shared")

{

                        // /Shared/...

                        $relpath = substr(cleanPath($path),7,strlen($path)-7);

                        $relpath = explode('/',$relpath);

                        $relative_path = '/'.$relpath[count($relpath)-1];

 

                        $backcount = 0;

 

                        do

                        {

                                               $query = OCP\DB::prepare("SELECT X.uid_owner, Y.path FROM *PREFIX*share X INNER JOIN *PREFIX*filecache Y ON X.file_source = Y.fileid where X.share_with = ? and X.file_target = ? LIMIT 1");

                                               $result = $query->execute(array(OCP\USER::getUser(),'/'.$relpath[count($relpath)-1-$backcount]))->fetchAll();

                                               $backcount+=1;

                        }while(count($result)<1);

 

                        $realpath = $storage.$result[0]['uid_owner'].'/'.$result[0]['path'];

                       

                        $backcount-=1;

                        for($i=$backcount;$i>0;$i-=1)

                        {

                                               $realpath .= '/'.$relpath[count($relpath)-$i];

                        }

                       

}

else

{

                        // /root

                        $realpath = $storage.OCP\USER::getUser()."/files".cleanPath($path);

                       

}

 

//lockfile name

$lock = $apath.lockname($realpath);

 

if(@$safe=="false")

{

 

                        if (file_exists($lock))

                        {

                                               @unlink($lock);

                       

                                               echo $l->t("File not locked");

                        }

                        else

                        {

                                               @date_default_timezone_set('Europe/Berlin');

                       

                                               $h = fopen($lock, "w");

                                               fwrite($h,OCP\User::getDisplayName()." ".date(DATE_RFC822));

                                               fclose($h);

                       

                                               echo $l->t("File is locked");

                        }

}

else

{

                        if (file_exists($lock))

                        {

                                               echo $l->t("Status: locked");

                        }

                        else

                        {

                                               echo $l->t("Status: not locked");

                        }

}

 

 

function lockname($path)

{

                        //Replace all '/' with $ for a filename for the lock file

                        $ppath = str_replace("/","$",cleanPath($path))."$";

                       

                        $ppath = str_replace("Shared","",$ppath);

                        $ppath = str_replace(":","#",$ppath);

                       

                        //Remove double dollar char when exist

                        if ($ppath[0] == "$" and $ppath[1] == "$") $ppath = substr($ppath,1);

                       

                        return $ppath;

 

}

 

function cleanPath($path) {

   

        $path = rtrim($path, "/");

        return preg_replace('{(/)\1+}', "/", $path);

}

 

 

 

I’m looking forward for your feedback.

 

Kind regards,

 

Patrick Hoffmann

 


     

Geschäftsführer: Werner Magin, Winfried Schmuck | HRB 2704 Bad Kreuznach | Gesellschafter: Fritz Bittmann Holding GmbH | USt-ID: DE 811 202 181


BITO-Lagertechnik
Bittmann GmbH

Obertor 29
D-55590 Meisenheim
Telefon:
Telefax:
E-Mail:
Internet:
+49 (0) 6753 122 0
+49 (0) 6753 122 399
[hidden email]
www.bito.de

 
     

Dieses E-Mail ist nur für den Empfänger bestimmt, an den es gerichtet ist und kann vertrauliches bzw. unter das Berufsgeheimnis fallendes Material enthalten. Jegliche darin enthaltene Ansicht oder Meinungsäußerung ist die des Autors und stellt nicht notwendigerweise die Ansicht oder Meinung von BITO-Lagertechnik Bittmann GmbH dar.
Sind Sie nicht der Empfänger und haben diese E-Mail irrtümlich erhalten, sind jegliche Verwendung, Veröffentlichung, Weiterleitung, Abschrift oder jeglicher Druck dieser E-Mail strengstens untersagt.
Jede ausgehende E-Mail wird von uns mit höchster Sorgfalt auf Viren geprüft. Jedoch übernehmen weder BITO-Lagertechnik Bittmann GmbH noch der Absender (Patrick Hoffmann) die Haftung für Viren; es obliegt Ihrer Verantwortung, die E-Mail und deren Anhänge auf Viren zu prüfen.

This email is exclusively meant for the addressee and may contain confidential information or information which can be classified as professional secret. Any view or opinion stated in this email is that of the author and does not necessarily represent the view or the opinion of BITO-Lagertechnik Bittmann GmbH. If you are not the addressee and if this email has been transmitted to you by mistake, you may not make use of, publish, transmit, reproduce or print the information contained therein for whatever purpose. We take every reasonable care to check all out-bound emails for viruses. However, neither BITO-Lagertechnik Bittmann GmbH nor the sender (Patrick Hoffmann) can be held liable for the occurrence of viruses and any consequential damages. It is therefore the addressee's sole responsibility to check incoming emails and attachments for viruses.

Anhänge - 2: files_w2g.tar
files_w2g.zip
Versand am 21.02.2014 12:42 von Patrick Hoffmann

 



_______________________________________________
Devel mailing list
[hidden email]
http://mailman.owncloud.org/mailman/listinfo/devel

files_w2g.tar (30K) Download Attachment
files_w2g.zip (8K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: [app] Workin2gether - support request

Vincent Petry
Hi Patrick,

The file actions can currently only be added from the JS side, not PHP.

A similar case like yours is for shared files, which work like this.
1. File list is loaded
2. Event "fileActionsReady" is triggered (see
"apps/files_sharing/js/share.js")
3. Call to OC.Share.loadIcons (in "core/js/share.js") which load the
sharing information
4. Update to file share icons

You might want to do something similar in your case.

I'm not sure whether locking the files the way you do is a good idea.

Will you try and block the sync client from uploading by returning 403
for locked files ? I'm not sure what the sync client will do in such
cases, it will probably skip that file and retry later.

Cheers,

Vincent

_______________________________________________
Devel mailing list
[hidden email]
http://mailman.owncloud.org/mailman/listinfo/devel
Reply | Threaded
Open this post in threaded view
|

Re: [app] Workin2gether - support request

Hoffmann, Patrick
In reply to this post by Hoffmann, Patrick
Hi Vincent,

thanks I will look in the FileActionsReady trigger, sounds like what i was looking for, but that makes new questions, because I'm
not familiar with the apis.

Assumed, I add:

$('#fileList').on('fileActionsReady',function(){

});

in the JS file, how am I supposed to get each filename in the filelist?
Should I filter the fileList for the <tr> tags, or is there a better way, maybe with the OC object?
In the fileActionsReady should be a foreach, calling the workin function with the
correct filename parameter.

About the block, I disabled any access from the reverse proxy, so only port 449 is allowed, i only need to disable the row at the OC webpage.


Regards,

Patrick



BITO-Lagertechnik Bittmann GmbH

Obertor 29
55590 Meisenheim
Germany

Tel: +49 (0) 6753 122 0
Fax: +49 (0) 6753 122 399

E-Mail: [hidden email]
http://www.bito.de

Geschäftsführer: Werner Magin, Winfried Schmuck | HRB 2704 Bad Kreuznach | Gesellschafter: Fritz Bittmann Holding GmbH | USt-ID: DE 811 202 181


*************************************************************************************
Dieses E-Mail ist nur für den Empfänger bestimmt, an den es gerichtet ist und kann vertrauliches bzw. unter das Berufsgeheimnis fallendes Material enthalten. Jegliche darin enthaltene Ansicht oder Meinungsäußerung ist die des Autors und stellt nicht notwendigerweise die Ansicht oder Meinung von BITO-Lagertechnik Bittmann GmbH dar. Sind Sie nicht der Empfänger und haben diese E-Mail irrtümlich erhalten, sind jegliche Verwendung, Veröffentlichung, Weiterleitung, Abschrift oder jeglicher Druck dieser E-Mail strengstens untersagt. Jede ausgehende E-Mail wird von uns mit höchster Sorgfalt auf Viren geprüft. Jedoch übernehmen weder BITO-Lagertechnik Bittmann GmbH noch der Absender (Patrick Hoffmann) die Haftung für Viren; es obliegt Ihrer Verantwortung, die E-Mail und deren Anhänge auf Viren zu prüfen.

This email is exclusively meant for the addressee and may contain confidential information or information which can be classified as professional secret. Any view or opinion stated in this email is that of the author and does not necessarily represent the view or the opinion of BITO-Lagertechnik Bittmann GmbH. If you are not the addressee and if this email has been transmitted to you by mistake, you may not make use of, publish, transmit, reproduce or print the information contained therein for whatever purpose. We take every reasonable care to check all out-bound emails for viruses. However, neither BITO-Lagertechnik Bittmann GmbH nor the sender (Patrick Hoffmann) can be held liable for the occurrence of viruses and any consequential damages. It is therefore the addressee's sole responsibility to check incoming emails and attachments for viruses.
*************************************************************************************
Anhänge:
Versand am 24.02.2014 10:35 von Patrick Hoffmann

-----Ursprüngliche Nachricht-----
Von: [hidden email] [mailto:[hidden email]] Im Auftrag von Vincent Petry
Gesendet: Montag, 24. Februar 2014 10:05
An: List for Developers of ownCloud
Betreff: Re: [owncloud-devel] [app] Workin2gether - support request

Hi Patrick,

The file actions can currently only be added from the JS side, not PHP.

A similar case like yours is for shared files, which work like this.
1. File list is loaded
2. Event "fileActionsReady" is triggered (see
"apps/files_sharing/js/share.js")
3. Call to OC.Share.loadIcons (in "core/js/share.js") which load the sharing information 4. Update to file share icons

You might want to do something similar in your case.

I'm not sure whether locking the files the way you do is a good idea.

Will you try and block the sync client from uploading by returning 403 for locked files ? I'm not sure what the sync client will do in such cases, it will probably skip that file and retry later.

Cheers,

Vincent

_______________________________________________
Devel mailing list
[hidden email]
http://mailman.owncloud.org/mailman/listinfo/devel

_______________________________________________
Devel mailing list
[hidden email]
http://mailman.owncloud.org/mailman/listinfo/devel
Reply | Threaded
Open this post in threaded view
|

Re: [app] Workin2gether - support request

Vincent Petry
Hi Patrick,

You mean you are disabling access to single files through the reverse
proxy or are you forbidding sync client usage at all in your setup ?

To get the file list you currently need to iterate over the "tr" elements:

$('#fileList tr').each(function() {
        var $tr = $(this);
        // do something with the $tr
});

Currently there is no better way but I hope we can add utility functions
in the future.

If you want access to a single file, you can use:
   $tr = FileList.findFileEl('filename.txt');

It will give you the tr matching the file.

Hope this helps.

Cheers,

Vincent


On 02/24/2014 10:35 AM, Hoffmann, Patrick wrote:

> Hi Vincent,
>
> thanks I will look in the FileActionsReady trigger, sounds like what i was looking for, but that makes new questions, because I'm
> not familiar with the apis.
>
> Assumed, I add:
>
> $('#fileList').on('fileActionsReady',function(){
>
> });
>
> in the JS file, how am I supposed to get each filename in the filelist?
> Should I filter the fileList for the <tr> tags, or is there a better way, maybe with the OC object?
> In the fileActionsReady should be a foreach, calling the workin function with the
> correct filename parameter.
>
> About the block, I disabled any access from the reverse proxy, so only port 449 is allowed, i only need to disable the row at the OC webpage.
>
>
> Regards,
>
> Patrick
>
>
>
> BITO-Lagertechnik Bittmann GmbH
>
> Obertor 29
> 55590 Meisenheim
> Germany
>
> Tel: +49 (0) 6753 122 0
> Fax: +49 (0) 6753 122 399
>
> E-Mail: [hidden email]
> http://www.bito.de
>
> Geschäftsführer: Werner Magin, Winfried Schmuck | HRB 2704 Bad Kreuznach | Gesellschafter: Fritz Bittmann Holding GmbH | USt-ID: DE 811 202 181
>
>
> *************************************************************************************
> Dieses E-Mail ist nur für den Empfänger bestimmt, an den es gerichtet ist und kann vertrauliches bzw. unter das Berufsgeheimnis fallendes Material enthalten. Jegliche darin enthaltene Ansicht oder Meinungsäußerung ist die des Autors und stellt nicht notwendigerweise die Ansicht oder Meinung von BITO-Lagertechnik Bittmann GmbH dar. Sind Sie nicht der Empfänger und haben diese E-Mail irrtümlich erhalten, sind jegliche Verwendung, Veröffentlichung, Weiterleitung, Abschrift oder jeglicher Druck dieser E-Mail strengstens untersagt. Jede ausgehende E-Mail wird von uns mit höchster Sorgfalt auf Viren geprüft. Jedoch übernehmen weder BITO-Lagertechnik Bittmann GmbH noch der Absender (Patrick Hoffmann) die Haftung für Viren; es obliegt Ihrer Verantwortung, die E-Mail und deren Anhänge auf Viren zu prüfen.
>
> This email is exclusively meant for the addressee and may contain confidential information or information which can be classified as professional secret. Any view or opinion stated in this email is that of the author and does not necessarily represent the view or the opinion of BITO-Lagertechnik Bittmann GmbH. If you are not the addressee and if this email has been transmitted to you by mistake, you may not make use of, publish, transmit, reproduce or print the information contained therein for whatever purpose. We take every reasonable care to check all out-bound emails for viruses. However, neither BITO-Lagertechnik Bittmann GmbH nor the sender (Patrick Hoffmann) can be held liable for the occurrence of viruses and any consequential damages. It is therefore the addressee's sole responsibility to check incoming emails and attachments for viruses.
> *************************************************************************************
> Anhänge:
> Versand am 24.02.2014 10:35 von Patrick Hoffmann
>
> -----Ursprüngliche Nachricht-----
> Von: [hidden email] [mailto:[hidden email]] Im Auftrag von Vincent Petry
> Gesendet: Montag, 24. Februar 2014 10:05
> An: List for Developers of ownCloud
> Betreff: Re: [owncloud-devel] [app] Workin2gether - support request
>
> Hi Patrick,
>
> The file actions can currently only be added from the JS side, not PHP.
>
> A similar case like yours is for shared files, which work like this.
> 1. File list is loaded
> 2. Event "fileActionsReady" is triggered (see
> "apps/files_sharing/js/share.js")
> 3. Call to OC.Share.loadIcons (in "core/js/share.js") which load the sharing information 4. Update to file share icons
>
> You might want to do something similar in your case.
>
> I'm not sure whether locking the files the way you do is a good idea.
>
> Will you try and block the sync client from uploading by returning 403 for locked files ? I'm not sure what the sync client will do in such cases, it will probably skip that file and retry later.
>
> Cheers,
>
> Vincent
>
> _______________________________________________
> Devel mailing list
> [hidden email]
> http://mailman.owncloud.org/mailman/listinfo/devel
>
> _______________________________________________
> Devel mailing list
> [hidden email]
> http://mailman.owncloud.org/mailman/listinfo/devel
>

_______________________________________________
Devel mailing list
[hidden email]
http://mailman.owncloud.org/mailman/listinfo/devel
Reply | Threaded
Open this post in threaded view
|

Re: [app] Workin2gether - support request

Hoffmann, Patrick
In reply to this post by Hoffmann, Patrick
Hi Vincent,

sync client is fully disabled. Only the webpage is accessible.
When there is no better method to get all filenames, i will try to get it working with
.each for filelist.
Thanks!

regards

Patrick




BITO-Lagertechnik Bittmann GmbH

Obertor 29
55590 Meisenheim
Germany

Tel: +49 (0) 6753 122 0
Fax: +49 (0) 6753 122 399

E-Mail: [hidden email]
http://www.bito.de

Geschäftsführer: Werner Magin, Winfried Schmuck | HRB 2704 Bad Kreuznach | Gesellschafter: Fritz Bittmann Holding GmbH | USt-ID: DE 811 202 181


*************************************************************************************
Dieses E-Mail ist nur für den Empfänger bestimmt, an den es gerichtet ist und kann vertrauliches bzw. unter das Berufsgeheimnis fallendes Material enthalten. Jegliche darin enthaltene Ansicht oder Meinungsäußerung ist die des Autors und stellt nicht notwendigerweise die Ansicht oder Meinung von BITO-Lagertechnik Bittmann GmbH dar. Sind Sie nicht der Empfänger und haben diese E-Mail irrtümlich erhalten, sind jegliche Verwendung, Veröffentlichung, Weiterleitung, Abschrift oder jeglicher Druck dieser E-Mail strengstens untersagt. Jede ausgehende E-Mail wird von uns mit höchster Sorgfalt auf Viren geprüft. Jedoch übernehmen weder BITO-Lagertechnik Bittmann GmbH noch der Absender (Patrick Hoffmann) die Haftung für Viren; es obliegt Ihrer Verantwortung, die E-Mail und deren Anhänge auf Viren zu prüfen.

This email is exclusively meant for the addressee and may contain confidential information or information which can be classified as professional secret. Any view or opinion stated in this email is that of the author and does not necessarily represent the view or the opinion of BITO-Lagertechnik Bittmann GmbH. If you are not the addressee and if this email has been transmitted to you by mistake, you may not make use of, publish, transmit, reproduce or print the information contained therein for whatever purpose. We take every reasonable care to check all out-bound emails for viruses. However, neither BITO-Lagertechnik Bittmann GmbH nor the sender (Patrick Hoffmann) can be held liable for the occurrence of viruses and any consequential damages. It is therefore the addressee's sole responsibility to check incoming emails and attachments for viruses.
*************************************************************************************
Anhänge:
Versand am 24.02.2014 10:45 von Patrick Hoffmann

-----Ursprüngliche Nachricht-----
Von: [hidden email] [mailto:[hidden email]] Im Auftrag von Vincent Petry
Gesendet: Montag, 24. Februar 2014 10:40
An: List for Developers of ownCloud
Betreff: Re: [owncloud-devel] [app] Workin2gether - support request

Hi Patrick,

You mean you are disabling access to single files through the reverse proxy or are you forbidding sync client usage at all in your setup ?

To get the file list you currently need to iterate over the "tr" elements:

$('#fileList tr').each(function() {
        var $tr = $(this);
        // do something with the $tr
});

Currently there is no better way but I hope we can add utility functions in the future.

If you want access to a single file, you can use:
   $tr = FileList.findFileEl('filename.txt');

It will give you the tr matching the file.

Hope this helps.

Cheers,

Vincent


On 02/24/2014 10:35 AM, Hoffmann, Patrick wrote:

> Hi Vincent,
>
> thanks I will look in the FileActionsReady trigger, sounds like what i
> was looking for, but that makes new questions, because I'm not familiar with the apis.
>
> Assumed, I add:
>
> $('#fileList').on('fileActionsReady',function(){
>
> });
>
> in the JS file, how am I supposed to get each filename in the filelist?
> Should I filter the fileList for the <tr> tags, or is there a better way, maybe with the OC object?
> In the fileActionsReady should be a foreach, calling the workin
> function with the correct filename parameter.
>
> About the block, I disabled any access from the reverse proxy, so only port 449 is allowed, i only need to disable the row at the OC webpage.
>
>
> Regards,
>
> Patrick
>
>
>
> BITO-Lagertechnik Bittmann GmbH
>
> Obertor 29
> 55590 Meisenheim
> Germany
>
> Tel: +49 (0) 6753 122 0
> Fax: +49 (0) 6753 122 399
>
> E-Mail: [hidden email]
> http://www.bito.de
>
> Geschäftsführer: Werner Magin, Winfried Schmuck | HRB 2704 Bad
> Kreuznach | Gesellschafter: Fritz Bittmann Holding GmbH | USt-ID: DE
> 811 202 181
>
>
> **********************************************************************
> *************** Dieses E-Mail ist nur für den Empfänger bestimmt, an
> den es gerichtet ist und kann vertrauliches bzw. unter das Berufsgeheimnis fallendes Material enthalten. Jegliche darin enthaltene Ansicht oder Meinungsäußerung ist die des Autors und stellt nicht notwendigerweise die Ansicht oder Meinung von BITO-Lagertechnik Bittmann GmbH dar. Sind Sie nicht der Empfänger und haben diese E-Mail irrtümlich erhalten, sind jegliche Verwendung, Veröffentlichung, Weiterleitung, Abschrift oder jeglicher Druck dieser E-Mail strengstens untersagt. Jede ausgehende E-Mail wird von uns mit höchster Sorgfalt auf Viren geprüft. Jedoch übernehmen weder BITO-Lagertechnik Bittmann GmbH noch der Absender (Patrick Hoffmann) die Haftung für Viren; es obliegt Ihrer Verantwortung, die E-Mail und deren Anhänge auf Viren zu prüfen.
>
> This email is exclusively meant for the addressee and may contain confidential information or information which can be classified as professional secret. Any view or opinion stated in this email is that of the author and does not necessarily represent the view or the opinion of BITO-Lagertechnik Bittmann GmbH. If you are not the addressee and if this email has been transmitted to you by mistake, you may not make use of, publish, transmit, reproduce or print the information contained therein for whatever purpose. We take every reasonable care to check all out-bound emails for viruses. However, neither BITO-Lagertechnik Bittmann GmbH nor the sender (Patrick Hoffmann) can be held liable for the occurrence of viruses and any consequential damages. It is therefore the addressee's sole responsibility to check incoming emails and attachments for viruses.
> **********************************************************************
> ***************
> Anhänge:
> Versand am 24.02.2014 10:35 von Patrick Hoffmann
>
> -----Ursprüngliche Nachricht-----
> Von: [hidden email] [mailto:[hidden email]] Im
> Auftrag von Vincent Petry
> Gesendet: Montag, 24. Februar 2014 10:05
> An: List for Developers of ownCloud
> Betreff: Re: [owncloud-devel] [app] Workin2gether - support request
>
> Hi Patrick,
>
> The file actions can currently only be added from the JS side, not PHP.
>
> A similar case like yours is for shared files, which work like this.
> 1. File list is loaded
> 2. Event "fileActionsReady" is triggered (see
> "apps/files_sharing/js/share.js")
> 3. Call to OC.Share.loadIcons (in "core/js/share.js") which load the
> sharing information 4. Update to file share icons
>
> You might want to do something similar in your case.
>
> I'm not sure whether locking the files the way you do is a good idea.
>
> Will you try and block the sync client from uploading by returning 403 for locked files ? I'm not sure what the sync client will do in such cases, it will probably skip that file and retry later.
>
> Cheers,
>
> Vincent
>
> _______________________________________________
> Devel mailing list
> [hidden email]
> http://mailman.owncloud.org/mailman/listinfo/devel
>
> _______________________________________________
> Devel mailing list
> [hidden email]
> http://mailman.owncloud.org/mailman/listinfo/devel
>

_______________________________________________
Devel mailing list
[hidden email]
http://mailman.owncloud.org/mailman/listinfo/devel

_______________________________________________
Devel mailing list
[hidden email]
http://mailman.owncloud.org/mailman/listinfo/devel
Reply | Threaded
Open this post in threaded view
|

Re: [app] Workin2gether - support request

Hoffmann, Patrick
In reply to this post by Hoffmann, Patrick

Hey folks,

 

I’m still working on a app, which allows to disable files in the cloud on the webpage.
I made some good progress and everything works as a charm atm.
But now i have a difficult problem.

I made the function disable_control:


function disable_control(filename)

{

                $('#fileList tr td.filename a.name span.fileactions').each(function() {

                               var val = $(this);

                               var m = $('#fileList tr td.date a.action');

 

                                   if(val.html().indexOf(lockedtext)!=-1||val.html().indexOf(lockstate)!=-1)

                                   {                         

                                                                              //m.css('display','none');

                                                                              val.find('a.action').filterAttr('data-action','Download').css('display','none');

                                                                              val.find('a.action').filterAttr('data-action','Share').css('display','none');

                                    }

                });

}

The function gets the filename of a locked file. Now i want to remove any fileactions, but the file lock fileaction.

Download and Share are working, like they should.

 

lockedtext is the translated text. Like „Status: file is locked“ and lockstate is „file is locked“.

But i have a problem with the delete-icon. I don’t know how i should get the delete-icon only for the file which is equal to filename parameter.

You see the comment line in the if condition, it disables every delete-icon.

 

Do you know a smooth solution to determinate the correct file?

 

Greets,

 

Patrick

 


     

Geschäftsführer: Werner Magin, Winfried Schmuck | HRB 2704 Bad Kreuznach | Gesellschafter: Fritz Bittmann Holding GmbH | USt-ID: DE 811 202 181


BITO-Lagertechnik
Bittmann GmbH

Obertor 29
D-55590 Meisenheim
Telefon:
Telefax:
E-Mail:
Internet:
+49 (0) 6753 122 0
+49 (0) 6753 122 399
[hidden email]
www.bito.de

 
     

Dieses E-Mail ist nur für den Empfänger bestimmt, an den es gerichtet ist und kann vertrauliches bzw. unter das Berufsgeheimnis fallendes Material enthalten. Jegliche darin enthaltene Ansicht oder Meinungsäußerung ist die des Autors und stellt nicht notwendigerweise die Ansicht oder Meinung von BITO-Lagertechnik Bittmann GmbH dar.
Sind Sie nicht der Empfänger und haben diese E-Mail irrtümlich erhalten, sind jegliche Verwendung, Veröffentlichung, Weiterleitung, Abschrift oder jeglicher Druck dieser E-Mail strengstens untersagt.
Jede ausgehende E-Mail wird von uns mit höchster Sorgfalt auf Viren geprüft. Jedoch übernehmen weder BITO-Lagertechnik Bittmann GmbH noch der Absender (Patrick Hoffmann) die Haftung für Viren; es obliegt Ihrer Verantwortung, die E-Mail und deren Anhänge auf Viren zu prüfen.

This email is exclusively meant for the addressee and may contain confidential information or information which can be classified as professional secret. Any view or opinion stated in this email is that of the author and does not necessarily represent the view or the opinion of BITO-Lagertechnik Bittmann GmbH. If you are not the addressee and if this email has been transmitted to you by mistake, you may not make use of, publish, transmit, reproduce or print the information contained therein for whatever purpose. We take every reasonable care to check all out-bound emails for viruses. However, neither BITO-Lagertechnik Bittmann GmbH nor the sender (Patrick Hoffmann) can be held liable for the occurrence of viruses and any consequential damages. It is therefore the addressee's sole responsibility to check incoming emails and attachments for viruses.

Anhänge - :
Versand am 03.03.2014 09:36 von Patrick Hoffmann

 



_______________________________________________
Devel mailing list
[hidden email]
http://mailman.owncloud.org/mailman/listinfo/devel
Reply | Threaded
Open this post in threaded view
|

Re: [app] Workin2gether - support request

Vincent Petry
Hi Patrick,


 >But i have a problem with the delete-icon. I don’t know how i should
get the delete-icon only for the file which is equal to filename parameter.

Can you clarify ? I don't understand the question.

To get a specific file's tr, use FileList.findFileEl(fileName).

To disable all file actions except the locked one, you could make a more
complex jQuery:
$('#fileList a.action[data-action!='LockedActionName']').addClass('hidden');

Cheers,

Vincent

_______________________________________________
Devel mailing list
[hidden email]
http://mailman.owncloud.org/mailman/listinfo/devel
Reply | Threaded
Open this post in threaded view
|

Re: [app] Workin2gether - support request

Hoffmann, Patrick
In reply to this post by Hoffmann, Patrick
Hi Vincent,

i just want to disable the a.action.delete.delete-icon, for 'filename'.
Your snippet is useful, but the delete-icon isn't a fileaction, it is inside tr.date.

I check for each line in the filelist, if this file is locked, disable the actions for this line.
The line you wrote would disable it for all lines or am i wrong?
I have to determinate that the current line is locked and then disable the a.action.delete.delete-icon for only this
line.

I uploaded it for you: http://imgbox.com/dmSPdXKA
You see the red marked area. This 'X' should be hidden.





function disable_control(filename)
{
                $('#fileList tr td.filename a.name span.fileactions').each(function() {
                               var val = $(this);
                               var m = $('#fileList tr td.date a.action');

                                   if(val.html().indexOf(lockedtext)!=-1||val.html().indexOf(lockstate)!=-1)
                                   {
                                                                              //m.css('display','none');
                                                                              val.find('a.action').filterAttr('data-action','Download').css('display','none');
                                                                              val.find('a.action').filterAttr('data-action','Share').css('display','none');
                                    }
                });
}


Greets,

Patrick



BITO-Lagertechnik Bittmann GmbH

Obertor 29
55590 Meisenheim
Germany

Tel: +49 (0) 6753 122 0
Fax: +49 (0) 6753 122 399

E-Mail: [hidden email]
http://www.bito.de

Gesch?ftsf?hrer: Werner Magin, Winfried Schmuck | HRB 2704 Bad Kreuznach | Gesellschafter: Fritz Bittmann Holding GmbH | USt-ID: DE 811 202 181


*************************************************************************************
Dieses E-Mail ist nur f?r den Empf?nger bestimmt, an den es gerichtet ist und kann vertrauliches bzw. unter das Berufsgeheimnis fallendes Material enthalten. Jegliche darin enthaltene Ansicht oder Meinungs?u?erung ist die des Autors und stellt nicht notwendigerweise die Ansicht oder Meinung von BITO-Lagertechnik Bittmann GmbH dar. Sind Sie nicht der Empf?nger und haben diese E-Mail irrt?mlich erhalten, sind jegliche Verwendung, Ver?ffentlichung, Weiterleitung, Abschrift oder jeglicher Druck dieser E-Mail strengstens untersagt. Jede ausgehende E-Mail wird von uns mit h?chster Sorgfalt auf Viren gepr?ft. Jedoch ?bernehmen weder BITO-Lagertechnik Bittmann GmbH noch der Absender (Patrick Hoffmann) die Haftung f?r Viren; es obliegt Ihrer Verantwortung, die E-Mail und deren Anh?nge auf Viren zu pr?fen.

This email is exclusively meant for the addressee and may contain confidential information or information which can be classified as professional secret. Any view or opinion stated in this email is that of the author and does not necessarily represent the view or the opinion of BITO-Lagertechnik Bittmann GmbH. If you are not the addressee and if this email has been transmitted to you by mistake, you may not make use of, publish, transmit, reproduce or print the information contained therein for whatever purpose. We take every reasonable care to check all out-bound emails for viruses. However, neither BITO-Lagertechnik Bittmann GmbH nor the sender (Patrick Hoffmann) can be held liable for the occurrence of viruses and any consequential damages. It is therefore the addressee's sole responsibility to check incoming emails and attachments for viruses.
*************************************************************************************
Anh?nge:
Versand am 03.03.2014 10:34 von Patrick Hoffmann

_______________________________________________
Devel mailing list
[hidden email]
http://mailman.owncloud.org/mailman/listinfo/devel

_______________________________________________
Devel mailing list
[hidden email]
http://mailman.owncloud.org/mailman/listinfo/devel
Reply | Threaded
Open this post in threaded view
|

Re: [app] Workin2gether - support request

Vincent Petry
Hi Patrick,

Yes sorry, that would disable the action for all files.
I meant to do it for a single row:
$tr.find('a.action[data-action!='LockedActionName'], ').addClass('hidden');

Note that the delete button also has the ".action" class so it should
also be hidden by that one.
If not then maybe some CSS rule is preventing its hiding.

Another idea would be to use a pure CSS approach: when a file is locked,
set a class "locked" on the tr element and create CSS rules like this:
tr.locked .action{
     display: none;
}
tr.locked .action[data-action=LockedActionName] {
      display: block; /* because that one needs to stay visible */
}

but I can't guarantee the CSS approach will work, I haven't tried it,
just guessing :-)

Cheers,

Vincent


On 03/03/2014 10:34 AM, Hoffmann, Patrick wrote:

> Hi Vincent,
>
> i just want to disable the a.action.delete.delete-icon, for 'filename'.
> Your snippet is useful, but the delete-icon isn't a fileaction, it is inside tr.date.
>
> I check for each line in the filelist, if this file is locked, disable the actions for this line.
> The line you wrote would disable it for all lines or am i wrong?
> I have to determinate that the current line is locked and then disable the a.action.delete.delete-icon for only this
> line.
>
> I uploaded it for you: http://imgbox.com/dmSPdXKA
> You see the red marked area. This 'X' should be hidden.
>
>
>
>
>
> function disable_control(filename)
> {
>                  $('#fileList tr td.filename a.name span.fileactions').each(function() {
>                                 var val = $(this);
>                                 var m = $('#fileList tr td.date a.action');
>
>                                     if(val.html().indexOf(lockedtext)!=-1||val.html().indexOf(lockstate)!=-1)
>                                     {
>                                                                                //m.css('display','none');
>                                                                                val.find('a.action').filterAttr('data-action','Download').css('display','none');
>                                                                                val.find('a.action').filterAttr('data-action','Share').css('display','none');
>                                      }
>                  });
> }
>
>
> Greets,
>
> Patrick
>
>
>
> BITO-Lagertechnik Bittmann GmbH
>
> Obertor 29
> 55590 Meisenheim
> Germany
>
> Tel: +49 (0) 6753 122 0
> Fax: +49 (0) 6753 122 399
>
> E-Mail: [hidden email]
> http://www.bito.de
>
> Gesch?ftsf?hrer: Werner Magin, Winfried Schmuck | HRB 2704 Bad Kreuznach | Gesellschafter: Fritz Bittmann Holding GmbH | USt-ID: DE 811 202 181
>
>
> *************************************************************************************
> Dieses E-Mail ist nur f?r den Empf?nger bestimmt, an den es gerichtet ist und kann vertrauliches bzw. unter das Berufsgeheimnis fallendes Material enthalten. Jegliche darin enthaltene Ansicht oder Meinungs?u?erung ist die des Autors und stellt nicht notwendigerweise die Ansicht oder Meinung von BITO-Lagertechnik Bittmann GmbH dar. Sind Sie nicht der Empf?nger und haben diese E-Mail irrt?mlich erhalten, sind jegliche Verwendung, Ver?ffentlichung, Weiterleitung, Abschrift oder jeglicher Druck dieser E-Mail strengstens untersagt. Jede ausgehende E-Mail wird von uns mit h?chster Sorgfalt auf Viren gepr?ft. Jedoch ?bernehmen weder BITO-Lagertechnik Bittmann GmbH noch der Absender (Patrick Hoffmann) die Haftung f?r Viren; es obliegt Ihrer Verantwortung, die E-Mail und deren Anh?nge auf Viren zu pr?fen.
>
> This email is exclusively meant for the addressee and may contain confidential information or information which can be classified as professional secret. Any view or opinion stated in this email is that of the author and does not necessarily represent the view or the opinion of BITO-Lagertechnik Bittmann GmbH. If you are not the addressee and if this email has been transmitted to you by mistake, you may not make use of, publish, transmit, reproduce or print the information contained therein for whatever purpose. We take every reasonable care to check all out-bound emails for viruses. However, neither BITO-Lagertechnik Bittmann GmbH nor the sender (Patrick Hoffmann) can be held liable for the occurrence of viruses and any consequential damages. It is therefore the addressee's sole responsibility to check incoming emails and attachments for viruses.
> *************************************************************************************
> Anh?nge:
> Versand am 03.03.2014 10:34 von Patrick Hoffmann
>
> _______________________________________________
> Devel mailing list
> [hidden email]
> http://mailman.owncloud.org/mailman/listinfo/devel
>
> _______________________________________________
> Devel mailing list
> [hidden email]
> http://mailman.owncloud.org/mailman/listinfo/devel

_______________________________________________
Devel mailing list
[hidden email]
http://mailman.owncloud.org/mailman/listinfo/devel
Reply | Threaded
Open this post in threaded view
|

Re: [app] Workin2gether - support request

Hoffmann, Patrick
Hi Vincent,

The css suggestions seems really smart. I'm going to try it tomorrow.

Greets



BITO-Lagertechnik Bittmann GmbH

Obertor 29
55590 Meisenheim
Germany

Tel: +49 (0) 6753 122 0
Fax: +49 (0) 6753 122 399

E-Mail: [hidden email]
http://www.bito.de

Gesch?ftsf?hrer: Werner Magin, Winfried Schmuck | HRB 2704 Bad Kreuznach | Gesellschafter: Fritz Bittmann Holding GmbH | USt-ID: DE 811 202 181


*************************************************************************************
Dieses E-Mail ist nur f?r den Empf?nger bestimmt, an den es gerichtet ist und kann vertrauliches bzw. unter das Berufsgeheimnis fallendes Material enthalten. Jegliche darin enthaltene Ansicht oder Meinungs?u?erung ist die des Autors und stellt nicht notwendigerweise die Ansicht oder Meinung von BITO-Lagertechnik Bittmann GmbH dar. Sind Sie nicht der Empf?nger und haben diese E-Mail irrt?mlich erhalten, sind jegliche Verwendung, Ver?ffentlichung, Weiterleitung, Abschrift oder jeglicher Druck dieser E-Mail strengstens untersagt. Jede ausgehende E-Mail wird von uns mit h?chster Sorgfalt auf Viren gepr?ft. Jedoch ?bernehmen weder BITO-Lagertechnik Bittmann GmbH noch der Absender (Patrick Hoffmann) die Haftung f?r Viren; es obliegt Ihrer Verantwortung, die E-Mail und deren Anh?nge auf Viren zu pr?fen.

This email is exclusively meant for the addressee and may contain confidential information or information which can be classified as professional secret. Any view or opinion stated in this email is that of the author and does not necessarily represent the view or the opinion of BITO-Lagertechnik Bittmann GmbH. If you are not the addressee and if this email has been transmitted to you by mistake, you may not make use of, publish, transmit, reproduce or print the information contained therein for whatever purpose. We take every reasonable care to check all out-bound emails for viruses. However, neither BITO-Lagertechnik Bittmann GmbH nor the sender (Patrick Hoffmann) can be held liable for the occurrence of viruses and any consequential damages. It is therefore the addressee's sole responsibility to check incoming emails and attachments for viruses.
*************************************************************************************
Anh?nge:
Versand am 03.03.2014 14:42 von Patrick Hoffmann

Von meinem iPhone gesendet

> Am 03.03.2014 um 14:33 schrieb "Vincent Petry" <[hidden email]>:
>
> Hi Patrick,
>
> Yes sorry, that would disable the action for all files.
> I meant to do it for a single row:
> $tr.find('a.action[data-action!='LockedActionName'], ').addClass('hidden');
>
> Note that the delete button also has the ".action" class so it should also be hidden by that one.
> If not then maybe some CSS rule is preventing its hiding.
>
> Another idea would be to use a pure CSS approach: when a file is locked, set a class "locked" on the tr element and create CSS rules like this:
> tr.locked .action{
>    display: none;
> }
> tr.locked .action[data-action=LockedActionName] {
>     display: block; /* because that one needs to stay visible */
> }
>
> but I can't guarantee the CSS approach will work, I haven't tried it, just guessing :-)
>
> Cheers,
>
> Vincent
>
>
>> On 03/03/2014 10:34 AM, Hoffmann, Patrick wrote:
>> Hi Vincent,
>>
>> i just want to disable the a.action.delete.delete-icon, for 'filename'.
>> Your snippet is useful, but the delete-icon isn't a fileaction, it is inside tr.date.
>>
>> I check for each line in the filelist, if this file is locked, disable the actions for this line.
>> The line you wrote would disable it for all lines or am i wrong?
>> I have to determinate that the current line is locked and then disable the a.action.delete.delete-icon for only this
>> line.
>>
>> I uploaded it for you: http://imgbox.com/dmSPdXKA
>> You see the red marked area. This 'X' should be hidden.
>>
>>
>>
>>
>>
>> function disable_control(filename)
>> {
>>                 $('#fileList tr td.filename a.name span.fileactions').each(function() {
>>                                var val = $(this);
>>                                var m = $('#fileList tr td.date a.action');
>>
>>                                    if(val.html().indexOf(lockedtext)!=-1||val.html().indexOf(lockstate)!=-1)
>>                                    {
>>                                                                               //m.css('display','none');
>>                                                                               val.find('a.action').filterAttr('data-action','Download').css('display','none');
>>                                                                               val.find('a.action').filterAttr('data-action','Share').css('display','none');
>>                                     }
>>                 });
>> }
>>
>>
>> Greets,
>>
>> Patrick
>>
>>
>>
>> BITO-Lagertechnik Bittmann GmbH
>>
>> Obertor 29
>> 55590 Meisenheim
>> Germany
>>
>> Tel: +49 (0) 6753 122 0
>> Fax: +49 (0) 6753 122 399
>>
>> E-Mail: [hidden email]
>> http://www.bito.de
>>
>> Gesch?ftsf?hrer: Werner Magin, Winfried Schmuck | HRB 2704 Bad Kreuznach | Gesellschafter: Fritz Bittmann Holding GmbH | USt-ID: DE 811 202 181
>>
>>
>> *************************************************************************************
>> Dieses E-Mail ist nur f?r den Empf?nger bestimmt, an den es gerichtet ist und kann vertrauliches bzw. unter das Berufsgeheimnis fallendes Material enthalten. Jegliche darin enthaltene Ansicht oder Meinungs?u?erung ist die des Autors und stellt nicht notwendigerweise die Ansicht oder Meinung von BITO-Lagertechnik Bittmann GmbH dar. Sind Sie nicht der Empf?nger und haben diese E-Mail irrt?mlich erhalten, sind jegliche Verwendung, Ver?ffentlichung, Weiterleitung, Abschrift oder jeglicher Druck dieser E-Mail strengstens untersagt. Jede ausgehende E-Mail wird von uns mit h?chster Sorgfalt auf Viren gepr?ft. Jedoch ?bernehmen weder BITO-Lagertechnik Bittmann GmbH noch der Absender (Patrick Hoffmann) die Haftung f?r Viren; es obliegt Ihrer Verantwortung, die E-Mail und deren Anh?nge auf Viren zu pr?fen.
>>
>> This email is exclusively meant for the addressee and may contain confidential information or information which can be classified as professional secret. Any view or opinion stated in this email is that of the author and does not necessarily represent the view or the opinion of BITO-Lagertechnik Bittmann GmbH. If you are not the addressee and if this email has been transmitted to you by mistake, you may not make use of, publish, transmit, reproduce or print the information contained therein for whatever purpose. We take every reasonable care to check all out-bound emails for viruses. However, neither BITO-Lagertechnik Bittmann GmbH nor the sender (Patrick Hoffmann) can be held liable for the occurrence of viruses and any consequential damages. It is therefore the addressee's sole responsibility to check incoming emails and attachments for viruses.
>> *************************************************************************************
>> Anh?nge:
>> Versand am 03.03.2014 10:34 von Patrick Hoffmann
>>
>> _______________________________________________
>> Devel mailing list
>> [hidden email]
>> http://mailman.owncloud.org/mailman/listinfo/devel
>>
>> _______________________________________________
>> Devel mailing list
>> [hidden email]
>> http://mailman.owncloud.org/mailman/listinfo/devel
>
> _______________________________________________
> Devel mailing list
> [hidden email]
> http://mailman.owncloud.org/mailman/listinfo/devel

_______________________________________________
Devel mailing list
[hidden email]
http://mailman.owncloud.org/mailman/listinfo/devel
Reply | Threaded
Open this post in threaded view
|

Re: [app] Workin2gether - support request

Hoffmann, Patrick
In reply to this post by Hoffmann, Patrick
Hi Vincent,

Hi Vincent,

just wanted to let you know that my app is now working :-)

But now the cleanup progress starts and some things are really messy coded.

So I could need some tipps, because I recognized that you are really fit with jQuery and OC.

Here you can see the current state: http://imgbox.com/ZFjqBuyh . It locks all other fileactions and
marks the line in a color. But i will add more options later.

If you have some ideas to shorten the code please feel free to answer.

Here is my filetree:
+apps
-+ajax
  - l10n.php (grab translation with ajax)
  - workin2gether.php (the core)
-+appinfo
 -app.php
 -info.xml
-+css
  -styles.css
-+img
  -pattern.png
  -w2g.svg
  -whoshare.png
-+js
  -workin2gether.js
-+l10n
  -<somelanguages>
-+lock (where the locks are stored)

Source: workin2gether.js

var text = "";
var lockedtext = "";
var lockstate = "";

$(document).ready(function(){

        text = translate("filelock");
        lockedtext = translate("File is locked");
        lockstate = translate("Status: locked");

    if (typeof FileActions !== 'undefined' && $('#dir').length>0) {


            FileActions.register('file',text,OC.PERMISSION_READ,function(){return OC.imagePath('files_w2g','w2g.svg')},function(filename){
                getState(filename,"false");
            });

            FileActions.register('dir',text,OC.PERMISSION_READ,function(){return OC.imagePath('files_w2g','w2g.svg')},function(filename){
                getState(filename,"false");
            });

                        $('#fileList').on('fileActionsReady',function(filename){
                                $('#fileList tr td.filename a.name span.nametext').each(function() {
                                        var $tr = $(this);
                                        getState($tr.html(),"true");
                                });
                        });
    }

});

function disable_control(filename)
{

        $('#fileList tr').each(function() {

                var $tr = $(this);

                var $_tr = $tr.html().replace(/^\s+|\s+$/g, '').replace('<span class="extension">','').replace('</span>','');

                    if($_tr.indexOf(lockedtext)!=-1||$_tr.indexOf(lockstate)!=-1)
                    {
                                if($_tr.indexOf(filename)!=-1)
                                        $tr.find('a.action[data-action!='+text+']').addClass('locked');
                                        $tr.find('a.name').addClass('statelock');
                                        $tr.find('td.filesize').addClass('statelock');
                                        $tr.find('td.date').addClass('statelock');

                        }
        });
}

function enable_control(filename)
{
        $('#fileList tr').each(function() {

                var $tr = $(this);

                var $_tr = $tr.html().replace(/^\s+|\s+$/g, '').replace('<span class="extension">','').replace('</span>','');

                    if($_tr.indexOf(lockedtext)==-1 && $_tr.indexOf(lockstate)==-1)
                    {
                                if($_tr.indexOf(filename)!=-1)
                                        $tr.find('a.action[data-action!='+text+']').removeClass('locked');
                                        $tr.find('a.name').removeClass('statelock');
                                        $tr.find('td.filesize').removeClass('statelock');
                                        $tr.find('td.date').removeClass('statelock');
                        }
        });
}

function translate(text)
{
        $.ajax({
        url: OC.filePath('files_w2g','ajax','l10n.php'),
        type: "post",
        data: { rawtext: text},
                async: false,
        success: function(data){text = data;},
    });
        return text;
}

function getState(filename,_safe)
{
        filename = filename.replace(/^\s+|\s+$/g, '').replace('<span class="extension">','').replace('</span>','');

    oc_dir = $('#dir').val();
        filename = filename.replace(/ /g, "%20");
        oc_path = oc_dir +'/'+filename;


        $.ajax({
        url: OC.filePath('files_w2g','ajax','workin2gether.php'),
        type: "post",
        data: { path: oc_path, safe: _safe},
        success: function(data){postmode(filename,data)},
    });

}

function postmode(filename,data)
{
                filename = filename.replace(/%20/g,' ');

                var html = '<img class="svg" src="'+OC.imagePath('files_w2g','w2g.svg')+'"></img> '+data;
                $('tr').filterAttr('data-file',filename).find('td.filename').find('a.name').find('span.fileactions').find("a.action").filterAttr('data-action',text).html(html);

                if(data==lockedtext||data==lockstate)
                        disable_control(filename);
                else
                        enable_control(filename);

}


Source: workin2gether.php
<?php

//Init translations
$l = \OCP\Util::getL10N('files_w2g');

//Requirements check
OCP\JSON::checkLoggedIn();
OCP\JSON::checkAppEnabled('files_w2g');


//Default path for lock files

$root = $_SERVER['DOCUMENT_ROOT'];

$apath = $root.OCP\Util::linkTo('files_w2g', 'lock')."/";

if(!@file_exists($root.OCP\Util::linkTo('files_w2g')."/lock"))
        @mkdir($root.OCP\Util::linkTo('files_w2g')."/lock", 0777, true);

$storage = "D:/";

//Vars
$path = stripslashes($_POST['path']) ;
@$safe = @$_POST['safe'];
$ppath = lockname($path);


if(cleanPath($path)=="/Shared"){ echo "Forbidden"; return 1; }

if(substr(cleanPath($path),0,7)=="/Shared")
{
        // /Shared/...
        $relpath = explode('/',substr(cleanPath($path),7,strlen($path)-7));
        $relative_path = '/'.$relpath[count($relpath)-1];

        $backcount = 0;
        $dbg = $relpath[count($relpath)-1-0];
        do
        {
                $query = OCP\DB::prepare("SELECT X.parent, X.id, X.uid_owner, Y.path FROM *PREFIX*share X INNER JOIN *PREFIX*filecache Y ON X.file_source = Y.fileid where X.share_with = ? and X.file_target = ? LIMIT 1");
                $result = $query->execute(array(OCP\USER::getUser(),'/'.$relpath[count($relpath)-1-$backcount]))->fetchAll();
                $backcount+=1;
        }while(count($result)<1 && $backcount<count($relpath));

        if ($backcount>0) $backcount-=1;




        $user = $result[0]['uid_owner'];
        $postpath = $result[0]['path'];
        //get the original share user name

        $old = ""; $new = "-";
        while ($new!="")
        {
                $old = $new;
                $query = OCP\DB::prepare("SELECT parent, uid_owner, id FROM *PREFIX*share where id = ? LIMIT 1");
                $result = $query->execute(array($result[0]['parent']))->fetchAll();
                $new = $result[0]['uid_owner'];
        }
        if($old!="-") $user = $old;


        $realpath = $storage.$user.'$'.$postpath;

        for($i=$backcount;$i>0;$i-=1)
        {
                $realpath .= '/'.$relpath[count($relpath)-$i];
        }



}
else $realpath = $storage.OCP\USER::getUser()."/files".cleanPath($path);

//lockfile name
$lock = $apath.lockname($realpath);

if (file_exists($lock))
{
        if(@$safe=="false")
        {
                @unlink($lock);
                echo $l->t("File not locked");
        }
        else echo $l->t("Status: locked");
}
else
{
        @date_default_timezone_set('Europe/Berlin');

        if(@$safe=="false")
        {
                $h = fopen($lock, "w");
                fwrite($h,OCP\User::getDisplayName()." ".date(DATE_RFC822)." ".$path);
                fclose($h);
                echo $l->t("File is locked");
        }
        else echo $l->t("Status: not locked");
}



function lockname($path)
{
        //Replace all '/' with $ for a filename for the lock file
        $ppath = str_replace("/","$",cleanPath($path))."$";

        $ppath = str_replace("Shared","",$ppath);
        $ppath = str_replace(":","#",$ppath);

        //Remove double dollar char when exist
        if ($ppath[0] == "$" and $ppath[1] == "$") $ppath = substr($ppath,1);

        return $ppath;

}

function cleanPath($path) {

        $path = rtrim($path, "/");
        $path = urldecode($path);
                return preg_replace('{(/)\1+}', "/", $path);
}


Source: l10n.php
<?php
$l = \OCP\Util::getL10N('files_w2g');
if($l->t($_POST['rawtext'])!="") echo $l->t($_POST['rawtext']); else echo $_POST['rawtext'];


Source: styles.css
#workin2gether p {
        float: left;
        padding-top: 0.8em;
        padding-left: 1.2em;
}

#workin2gether img  {
        float: left;
        width: 48px;
        height: 48px;
        background: transparent url('apps/files_w2g/img/pattern.png');
        border: 1px solid #D8D8D8;
        padding: 5px;
}
a.action.locked{
display:none !important;
}

a.name.statelock a.action{
color:#eee;
opacity:1 !important;
}
a.name.statelock a.action:hover, a.name.statelock span.extension{
color:#fff;
}

.statelock, .statelock span.modified{
background-color:#008887;
color:#fff !important;
}

Source: sample language file (de.php)
<?php
$TRANSLATIONS = array(
"File not locked" => "Datei nicht gesperrt",
"File is locked" => "Datei ist gesperrt",
"Status: locked" => "Status: gesperrt",
"Status: not locked" => "Status: nicht gesperrt",
"filelock" => "Dateisperre"
);

Example for Lockname:
D#$Patrick$files$_locked_folder$

Cheers,

Patrick


BITO-Lagertechnik Bittmann GmbH

Obertor 29
55590 Meisenheim
Germany

Tel: +49 (0) 6753 122 0
Fax: +49 (0) 6753 122 399

E-Mail: [hidden email]
http://www.bito.de

Gesch?ftsf?hrer: Werner Magin, Winfried Schmuck | HRB 2704 Bad Kreuznach | Gesellschafter: Fritz Bittmann Holding GmbH | USt-ID: DE 811 202 181


*************************************************************************************
Dieses E-Mail ist nur f?r den Empf?nger bestimmt, an den es gerichtet ist und kann vertrauliches bzw. unter das Berufsgeheimnis fallendes Material enthalten. Jegliche darin enthaltene Ansicht oder Meinungs?u?erung ist die des Autors und stellt nicht notwendigerweise die Ansicht oder Meinung von BITO-Lagertechnik Bittmann GmbH dar. Sind Sie nicht der Empf?nger und haben diese E-Mail irrt?mlich erhalten, sind jegliche Verwendung, Ver?ffentlichung, Weiterleitung, Abschrift oder jeglicher Druck dieser E-Mail strengstens untersagt. Jede ausgehende E-Mail wird von uns mit h?chster Sorgfalt auf Viren gepr?ft. Jedoch ?bernehmen weder BITO-Lagertechnik Bittmann GmbH noch der Absender (Patrick Hoffmann) die Haftung f?r Viren; es obliegt Ihrer Verantwortung, die E-Mail und deren Anh?nge auf Viren zu pr?fen.

This email is exclusively meant for the addressee and may contain confidential information or information which can be classified as professional secret. Any view or opinion stated in this email is that of the author and does not necessarily represent the view or the opinion of BITO-Lagertechnik Bittmann GmbH. If you are not the addressee and if this email has been transmitted to you by mistake, you may not make use of, publish, transmit, reproduce or print the information contained therein for whatever purpose. We take every reasonable care to check all out-bound emails for viruses. However, neither BITO-Lagertechnik Bittmann GmbH nor the sender (Patrick Hoffmann) can be held liable for the occurrence of viruses and any consequential damages. It is therefore the addressee's sole responsibility to check incoming emails and attachments for viruses.
*************************************************************************************
Anh?nge:
Versand am 04.03.2014 13:31 von Patrick Hoffmann

_______________________________________________
Devel mailing list
[hidden email]
http://mailman.owncloud.org/mailman/listinfo/devel

_______________________________________________
Devel mailing list
[hidden email]
http://mailman.owncloud.org/mailman/listinfo/devel
Reply | Threaded
Open this post in threaded view
|

Re: [app] Workin2gether - support request

Vincent Petry
Hi Patrick,

Glad to hear it's working.

I don't really have time right now to review your app in detail, sorry.

If it already works as intended then you might not need to worry too
much about cleaning up the code for your first version.

Good luck!

Vincent

On 03/04/2014 01:31 PM, Hoffmann, Patrick wrote:

> Hi Vincent,
>
> Hi Vincent,
>
> just wanted to let you know that my app is now working :-)
>
> But now the cleanup progress starts and some things are really messy coded.
>
> So I could need some tipps, because I recognized that you are really fit with jQuery and OC.
>
> Here you can see the current state: http://imgbox.com/ZFjqBuyh . It locks all other fileactions and
> marks the line in a color. But i will add more options later.
>
> If you have some ideas to shorten the code please feel free to answer.
>
> Here is my filetree:
> +apps
> -+ajax
>    - l10n.php (grab translation with ajax)
>    - workin2gether.php (the core)
> -+appinfo
>   -app.php
>   -info.xml
> -+css
>    -styles.css
> -+img
>    -pattern.png
>    -w2g.svg
>    -whoshare.png
> -+js
>    -workin2gether.js
> -+l10n
>    -<somelanguages>
> -+lock (where the locks are stored)
>
> Source: workin2gether.js
>
> var text = "";
> var lockedtext = "";
> var lockstate = "";
>
> $(document).ready(function(){
>
>          text = translate("filelock");
>          lockedtext = translate("File is locked");
>          lockstate = translate("Status: locked");
>
>      if (typeof FileActions !== 'undefined' && $('#dir').length>0) {
>
>
>              FileActions.register('file',text,OC.PERMISSION_READ,function(){return OC.imagePath('files_w2g','w2g.svg')},function(filename){
>                  getState(filename,"false");
>              });
>
>              FileActions.register('dir',text,OC.PERMISSION_READ,function(){return OC.imagePath('files_w2g','w2g.svg')},function(filename){
>                  getState(filename,"false");
>              });
>
>                          $('#fileList').on('fileActionsReady',function(filename){
>                                  $('#fileList tr td.filename a.name span.nametext').each(function() {
>                                          var $tr = $(this);
>                                          getState($tr.html(),"true");
>                                  });
>                          });
>      }
>
> });
>
> function disable_control(filename)
> {
>
>          $('#fileList tr').each(function() {
>
>                  var $tr = $(this);
>
>                  var $_tr = $tr.html().replace(/^\s+|\s+$/g, '').replace('<span class="extension">','').replace('</span>','');
>
>                      if($_tr.indexOf(lockedtext)!=-1||$_tr.indexOf(lockstate)!=-1)
>                      {
>                                  if($_tr.indexOf(filename)!=-1)
>                                          $tr.find('a.action[data-action!='+text+']').addClass('locked');
>                                          $tr.find('a.name').addClass('statelock');
>                                          $tr.find('td.filesize').addClass('statelock');
>                                          $tr.find('td.date').addClass('statelock');
>
>                          }
>          });
> }
>
> function enable_control(filename)
> {
>          $('#fileList tr').each(function() {
>
>                  var $tr = $(this);
>
>                  var $_tr = $tr.html().replace(/^\s+|\s+$/g, '').replace('<span class="extension">','').replace('</span>','');
>
>                      if($_tr.indexOf(lockedtext)==-1 && $_tr.indexOf(lockstate)==-1)
>                      {
>                                  if($_tr.indexOf(filename)!=-1)
>                                          $tr.find('a.action[data-action!='+text+']').removeClass('locked');
>                                          $tr.find('a.name').removeClass('statelock');
>                                          $tr.find('td.filesize').removeClass('statelock');
>                                          $tr.find('td.date').removeClass('statelock');
>                          }
>          });
> }
>
> function translate(text)
> {
>          $.ajax({
>          url: OC.filePath('files_w2g','ajax','l10n.php'),
>          type: "post",
>          data: { rawtext: text},
>                  async: false,
>          success: function(data){text = data;},
>      });
>          return text;
> }
>
> function getState(filename,_safe)
> {
>          filename = filename.replace(/^\s+|\s+$/g, '').replace('<span class="extension">','').replace('</span>','');
>
>      oc_dir = $('#dir').val();
>          filename = filename.replace(/ /g, "%20");
>          oc_path = oc_dir +'/'+filename;
>
>
>          $.ajax({
>          url: OC.filePath('files_w2g','ajax','workin2gether.php'),
>          type: "post",
>          data: { path: oc_path, safe: _safe},
>          success: function(data){postmode(filename,data)},
>      });
>
> }
>
> function postmode(filename,data)
> {
>                  filename = filename.replace(/%20/g,' ');
>
>                  var html = '<img class="svg" src="'+OC.imagePath('files_w2g','w2g.svg')+'"></img> '+data;
>                  $('tr').filterAttr('data-file',filename).find('td.filename').find('a.name').find('span.fileactions').find("a.action").filterAttr('data-action',text).html(html);
>
>                  if(data==lockedtext||data==lockstate)
>                          disable_control(filename);
>                  else
>                          enable_control(filename);
>
> }
>
>
> Source: workin2gether.php
> <?php
>
> //Init translations
> $l = \OCP\Util::getL10N('files_w2g');
>
> //Requirements check
> OCP\JSON::checkLoggedIn();
> OCP\JSON::checkAppEnabled('files_w2g');
>
>
> //Default path for lock files
>
> $root = $_SERVER['DOCUMENT_ROOT'];
>
> $apath = $root.OCP\Util::linkTo('files_w2g', 'lock')."/";
>
> if(!@file_exists($root.OCP\Util::linkTo('files_w2g')."/lock"))
>          @mkdir($root.OCP\Util::linkTo('files_w2g')."/lock", 0777, true);
>
> $storage = "D:/";
>
> //Vars
> $path = stripslashes($_POST['path']) ;
> @$safe = @$_POST['safe'];
> $ppath = lockname($path);
>
>
> if(cleanPath($path)=="/Shared"){ echo "Forbidden"; return 1; }
>
> if(substr(cleanPath($path),0,7)=="/Shared")
> {
>          // /Shared/...
>          $relpath = explode('/',substr(cleanPath($path),7,strlen($path)-7));
>          $relative_path = '/'.$relpath[count($relpath)-1];
>
>          $backcount = 0;
>          $dbg = $relpath[count($relpath)-1-0];
>          do
>          {
>                  $query = OCP\DB::prepare("SELECT X.parent, X.id, X.uid_owner, Y.path FROM *PREFIX*share X INNER JOIN *PREFIX*filecache Y ON X.file_source = Y.fileid where X.share_with = ? and X.file_target = ? LIMIT 1");
>                  $result = $query->execute(array(OCP\USER::getUser(),'/'.$relpath[count($relpath)-1-$backcount]))->fetchAll();
>                  $backcount+=1;
>          }while(count($result)<1 && $backcount<count($relpath));
>
>          if ($backcount>0) $backcount-=1;
>
>
>
>
>          $user = $result[0]['uid_owner'];
>          $postpath = $result[0]['path'];
>          //get the original share user name
>
>          $old = ""; $new = "-";
>          while ($new!="")
>          {
>                  $old = $new;
>                  $query = OCP\DB::prepare("SELECT parent, uid_owner, id FROM *PREFIX*share where id = ? LIMIT 1");
>                  $result = $query->execute(array($result[0]['parent']))->fetchAll();
>                  $new = $result[0]['uid_owner'];
>          }
>          if($old!="-") $user = $old;
>
>
>          $realpath = $storage.$user.'$'.$postpath;
>
>          for($i=$backcount;$i>0;$i-=1)
>          {
>                  $realpath .= '/'.$relpath[count($relpath)-$i];
>          }
>
>
>
> }
> else $realpath = $storage.OCP\USER::getUser()."/files".cleanPath($path);
>
> //lockfile name
> $lock = $apath.lockname($realpath);
>
> if (file_exists($lock))
> {
>          if(@$safe=="false")
>          {
>                  @unlink($lock);
>                  echo $l->t("File not locked");
>          }
>          else echo $l->t("Status: locked");
> }
> else
> {
>          @date_default_timezone_set('Europe/Berlin');
>
>          if(@$safe=="false")
>          {
>                  $h = fopen($lock, "w");
>                  fwrite($h,OCP\User::getDisplayName()." ".date(DATE_RFC822)." ".$path);
>                  fclose($h);
>                  echo $l->t("File is locked");
>          }
>          else echo $l->t("Status: not locked");
> }
>
>
>
> function lockname($path)
> {
>          //Replace all '/' with $ for a filename for the lock file
>          $ppath = str_replace("/","$",cleanPath($path))."$";
>
>          $ppath = str_replace("Shared","",$ppath);
>          $ppath = str_replace(":","#",$ppath);
>
>          //Remove double dollar char when exist
>          if ($ppath[0] == "$" and $ppath[1] == "$") $ppath = substr($ppath,1);
>
>          return $ppath;
>
> }
>
> function cleanPath($path) {
>
>          $path = rtrim($path, "/");
>          $path = urldecode($path);
>                  return preg_replace('{(/)\1+}', "/", $path);
> }
>
>
> Source: l10n.php
> <?php
> $l = \OCP\Util::getL10N('files_w2g');
> if($l->t($_POST['rawtext'])!="") echo $l->t($_POST['rawtext']); else echo $_POST['rawtext'];
>
>
> Source: styles.css
> #workin2gether p {
>          float: left;
>          padding-top: 0.8em;
>          padding-left: 1.2em;
> }
>
> #workin2gether img  {
>          float: left;
>          width: 48px;
>          height: 48px;
>          background: transparent url('apps/files_w2g/img/pattern.png');
>          border: 1px solid #D8D8D8;
>          padding: 5px;
> }
> a.action.locked{
> display:none !important;
> }
>
> a.name.statelock a.action{
> color:#eee;
> opacity:1 !important;
> }
> a.name.statelock a.action:hover, a.name.statelock span.extension{
> color:#fff;
> }
>
> .statelock, .statelock span.modified{
> background-color:#008887;
> color:#fff !important;
> }
>
> Source: sample language file (de.php)
> <?php
> $TRANSLATIONS = array(
> "File not locked" => "Datei nicht gesperrt",
> "File is locked" => "Datei ist gesperrt",
> "Status: locked" => "Status: gesperrt",
> "Status: not locked" => "Status: nicht gesperrt",
> "filelock" => "Dateisperre"
> );
>
> Example for Lockname:
> D#$Patrick$files$_locked_folder$
>
> Cheers,
>
> Patrick
>
>
> BITO-Lagertechnik Bittmann GmbH
>
> Obertor 29
> 55590 Meisenheim
> Germany
>
> Tel: +49 (0) 6753 122 0
> Fax: +49 (0) 6753 122 399
>
> E-Mail: [hidden email]
> http://www.bito.de
>
> Gesch?ftsf?hrer: Werner Magin, Winfried Schmuck | HRB 2704 Bad Kreuznach | Gesellschafter: Fritz Bittmann Holding GmbH | USt-ID: DE 811 202 181
>
>
> *************************************************************************************
> Dieses E-Mail ist nur f?r den Empf?nger bestimmt, an den es gerichtet ist und kann vertrauliches bzw. unter das Berufsgeheimnis fallendes Material enthalten. Jegliche darin enthaltene Ansicht oder Meinungs?u?erung ist die des Autors und stellt nicht notwendigerweise die Ansicht oder Meinung von BITO-Lagertechnik Bittmann GmbH dar. Sind Sie nicht der Empf?nger und haben diese E-Mail irrt?mlich erhalten, sind jegliche Verwendung, Ver?ffentlichung, Weiterleitung, Abschrift oder jeglicher Druck dieser E-Mail strengstens untersagt. Jede ausgehende E-Mail wird von uns mit h?chster Sorgfalt auf Viren gepr?ft. Jedoch ?bernehmen weder BITO-Lagertechnik Bittmann GmbH noch der Absender (Patrick Hoffmann) die Haftung f?r Viren; es obliegt Ihrer Verantwortung, die E-Mail und deren Anh?nge auf Viren zu pr?fen.
>
> This email is exclusively meant for the addressee and may contain confidential information or information which can be classified as professional secret. Any view or opinion stated in this email is that of the author and does not necessarily represent the view or the opinion of BITO-Lagertechnik Bittmann GmbH. If you are not the addressee and if this email has been transmitted to you by mistake, you may not make use of, publish, transmit, reproduce or print the information contained therein for whatever purpose. We take every reasonable care to check all out-bound emails for viruses. However, neither BITO-Lagertechnik Bittmann GmbH nor the sender (Patrick Hoffmann) can be held liable for the occurrence of viruses and any consequential damages. It is therefore the addressee's sole responsibility to check incoming emails and attachments for viruses.
> *************************************************************************************
> Anh?nge:
> Versand am 04.03.2014 13:31 von Patrick Hoffmann
>
> _______________________________________________
> Devel mailing list
> [hidden email]
> http://mailman.owncloud.org/mailman/listinfo/devel
>
> _______________________________________________
> Devel mailing list
> [hidden email]
> http://mailman.owncloud.org/mailman/listinfo/devel

_______________________________________________
Devel mailing list
[hidden email]
http://mailman.owncloud.org/mailman/listinfo/devel