GitType.class.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. require_once(__DIR__.SLASH.'ReadmeType.class.php');
  3. class GitType extends ReadmeType{
  4. public static function manifest(){
  5. return array(
  6. 'uid' => 'git',
  7. 'label' => 'Dépot git',
  8. 'icon' => 'fab fa-git-square',
  9. 'color' => '#ffffff',
  10. 'background' => '#bd2c00',
  11. 'description' => 'Dépot git associé',
  12. 'fromExtension' => array('.git'),
  13. 'toExtension' => '.zip',
  14. 'default' => '',
  15. );
  16. }
  17. /* EDITION */
  18. public static function toHtml($resource,$sketch=null){
  19. $infos = self::manifest();
  20. $json = json_decode($resource->content,true);
  21. $url = '';
  22. $synchronise = false;
  23. if($json){
  24. $url = $json['url'];
  25. $synchronise = $json['synchronise'];
  26. }
  27. return array(
  28. 'html'=>'<input id="content" onblur="window[\'hackpoint_resource_git_save\']()" class="git-repository form-control" placeholder="http://domain.com/repository.git" value="'.$url.'"><label><input type="checkbox" data-type="checkbox" onclick="window[\'hackpoint_resource_git_save\']()" '.($synchronise?'checked="checked"':'').' id="git-synchronise"> Synchroniser sur hackpoint</label><div id="git-browser"></div>',
  29. 'javascript' => "
  30. window['hackpoint_resource_git_save'] = function(){
  31. if($('.hackpoint').hasClass('readonly')) return;
  32. var data = {};
  33. data.action = 'hackpoint_resource_save_content';
  34. data.id = $('#sketch-editor').attr('data-id');
  35. data.content = JSON.stringify({url:$('#content').val(),synchronise:$('#git-synchronise').prop('checked')});
  36. $('.sketch-preloader').show();
  37. $.action(data,function(r){
  38. setTimeout(function(){
  39. $('.sketch-preloader').fadeOut(200);
  40. },300);
  41. hackpoint_resource_git_explore();
  42. });
  43. }
  44. function hackpoint_resource_git_explore(){
  45. console.log('ee');
  46. var data = {};
  47. data.action = 'hackpoint_resource_git_explore';
  48. data.url = $('#content').val();
  49. data.id = $('#sketch-editor').attr('data-id');
  50. $('.sketch-preloader').show();
  51. $.action(data,function(r){
  52. setTimeout(function(){
  53. $('.sketch-preloader').fadeOut(200);
  54. },300);
  55. $('#git-browser').html(r.html);
  56. init_components();
  57. });
  58. }
  59. $(document).ready(hackpoint_resource_git_explore());
  60. "
  61. );
  62. }
  63. //Export vers un fichier brut
  64. public static function toFile($resource){
  65. $infos = self::manifest();
  66. return array(
  67. 'name'=> slugify($resource->label).'.'.$infos['toExtension'],
  68. 'content' => html_entity_decode($resource->content)
  69. );
  70. }
  71. }
  72. ?>