software-download.js 1.15 KB
modulejs.define('SoftwareDownload', ['jquery', 'NoosferoRoot'], function($, NoosferoRoot) {
  'use strict';

  var AJAX_URL = {
    get_download_template:
      NoosferoRoot.urlWithSubDirectory("/plugin/software_communities/get_block_template")
  };

  var $download_html_template;

  function getDownloadListTemplate() {
     $.get(AJAX_URL.get_download_template, { profile: noosfero.profile })
       .done(function(response) {
         console.log("asdasd");
         console.log(response);
        $download_html_template = response;
    }).fail(function() {
      alert( "error" );
    });
  }


  function SoftwareDownload() {
    getDownloadListTemplate();
  }


  SoftwareDownload.prototype.addNewDonwload = function() {
    var new_download = $($download_html_template);
    $("#droppable-list-downloads").append(new_download);
  }


  SoftwareDownload.prototype.deleteDownload = function(element) {
    var delete_download = $(element).parent().parent().parent().remove();
  }


  return {
    isCurrentPage: function() {
      return $('.download-block').length !== 0;
    },


    init: function() {
      window.softwareDownload = new SoftwareDownload();
    }
  }
});