Browse Source

first commit of materio personal notes module : just displaying the icon button for now

Bachir Soussi Chiadmi 6 years ago
parent
commit
bd1a1de792

+ 2 - 0
sites/all/modules/gui/materiobasemod/js/dist/materio_personalnotes.min.js

@@ -0,0 +1,2 @@
+
+(function($){MaterioPersonalNotes=function(){function init(){trace('MaterioPersonalNotes :: init');};init();};$(document).ready(function(){var materioflag=new MaterioPersonalNotes();});})(jQuery);

+ 29 - 0
sites/all/modules/gui/materiobasemod/js/materio_personalnotes.js

@@ -0,0 +1,29 @@
+// @codekit-prepend "gui.js"
+// @koala-prepend "gui.js"
+
+
+(function($) {
+
+MaterioPersonalNotes = function(){
+
+  /**
+  * init()
+  */
+  function init(){
+    trace('MaterioPersonalNotes :: init');
+
+  };
+
+
+
+
+  init();
+
+
+};
+
+$(document).ready(function() {
+  var materioflag = new MaterioPersonalNotes();
+});
+
+})(jQuery);

+ 23 - 0
sites/all/modules/gui/materiobasemod/materio_personalnotes.info

@@ -0,0 +1,23 @@
+name = Materio Personal Notes
+description = "Materio per user notes on node module"
+
+; Core version (required)
+core = 7.x
+
+; Package name (see http://drupal.org/node/542202 for a list of names)
+package = Materio
+
+; PHP version requirement (optional)
+; php = 5.2
+
+; Loadable code files
+; files[] = materio_ctools_automodal.module
+
+; Module dependencies
+dependencies[] = user
+
+; Configuration page
+; configure = admin/config/materiobasemod
+
+; For further information about configuration options, see
+; - http://drupal.org/node/542202

+ 119 - 0
sites/all/modules/gui/materiobasemod/materio_personalnotes.module

@@ -0,0 +1,119 @@
+<?php
+
+
+/**
+ * Implements hook_init().
+ */
+function materio_personalnotes_init() {
+  drupal_add_js(drupal_get_path('module', 'materio_personalnotes').'/js/materio_personalnotes.js');
+}
+
+
+/**
+ * Implements hook_permission().
+ */
+function materio_personalnotes_permission() {
+  $perms =  array(
+    'create own personal notes' =>  array(
+      'title' => t('Create own personal notes'),
+      'description' => t('Create own personal notes'),
+    ),
+  );
+
+  return $perms;
+}
+
+// function materio_personalnotes_menu(){
+//   $items = array();
+//
+//   $base = array(
+//     'type' => MENU_CALLBACK,
+//     'file' => 'materio_personalnotes.pages.inc',
+//   );
+//
+//   $items['materio_personalnotes/registerblock'] = $base+array(
+//     'title' => 'Materio base user ajax',
+//     'page callback' => 'materio_personalnotes_registerblock',
+//     // 'page arguments' => array(),
+//     'access callback' => TRUE,
+//   );
+//
+//   return $items;
+// }
+
+/**
+ * Implements hook_menu_alter().
+ */
+// function materio_personalnotes_menu_alter(&$items) {
+//   $items['user/%user']['access callback'] = 'user_access';
+//   $items['user/%user']['access arguments'] = array('view own user profile');
+// }
+
+/**
+ * Implements hook_entity_view().
+ *
+ * Note this is broken for taxonomy terms. @see http://drupal.org/node/1067120
+ */
+function materio_personalnotes_entity_view($entity, $type, $view_mode, $langcode) {
+  if($type == 'node'){
+    if(user_access('create own personal notes') && $view_mode != 'print'){
+
+      $entity->content['personalnotelink'] = materio_personalnotes_get_note_link($entity);
+
+      // drupal_add_css(drupal_get_path('module', 'flag') . '/theme/flag.css');
+      // drupal_add_js(drupal_get_path('module', 'flag') . '/theme/flag.js');
+
+    }
+  }
+}
+
+function materio_personalnotes_get_note_link($entity){
+
+  // if note alredy exists link to it
+
+  // else create one
+  #create new list
+  $link = array(
+    '#link' => '/node/add/note',
+    // get the content type from settings OR create the content type with module install
+    // TODO: add data (node nid) for pre-filled reference field of new note
+    '#attributes' => array(
+      'class' => array('personal-note-link', 'personal-note-create'),
+      'title' => t('create a note for @title.', array('@title'=>$entity->title)),
+      'nid' => $entity->nid,
+    ),
+    '#theme'=>'materio_personalnotes_note_link',
+  );
+
+  if(isset($link)){
+    dsm($link, 'link');
+    drupal_add_js(drupal_get_path('module', 'materio_personalnotes').'/js/dist/materio_personalnotes.min.js');
+    return $link;
+  }
+
+  return;
+}
+
+
+
+/**
+ * Implements hook_theme().
+ */
+function materio_personalnotes_theme($existing, $type, $theme, $path) {
+  return array(
+    'materio_personalnotes_note_link' => array(
+      'variables' => array('link' => NULL, 'attributes' => array()),
+    ),
+  );
+}
+
+function theme_materio_personalnotes_note_link($vars){
+  return l(
+    '<i class="fi-pencil"></i>', 
+    $vars['link'],
+    array(
+      'attributes' => $vars['attributes'],
+      'html' => true,
+    )
+  );
+}

+ 62 - 0
sites/all/modules/gui/materiobasemod/materio_personalnotes.pages.inc

@@ -0,0 +1,62 @@
+<?php
+
+
+// 
+// function materio_personalnotes_registerblock(){
+//   $return = array();
+//   $block = block_load('materio_personalnotes','user_createaccount');
+//   $return['block'] = drupal_render(_block_get_renderable_array(_block_render_blocks(array($block))));
+//   drupal_json_output($return);
+// }
+//
+// function materio_personalnotes_loginandregisterblock(){
+//   $return = array();
+//   $block = block_load('materio_personalnotes','user_register');
+//   $return['block'] = drupal_render(_block_get_renderable_array(_block_render_blocks(array($block))));
+//   drupal_json_output($return);
+// }
+//
+// function materio_personalnotes_register_submit(){
+//   $return = array();
+//   $return['POST'] = $_POST;
+//
+//   $form_state = array( "values"=>$_POST);
+//   drupal_form_submit($_POST['form_id'], $form_state);
+//
+//   // $return['form_state'] = $form_state;
+//
+//   $return['errors'] = form_get_errors();
+//   if($return['errors']){
+//     unset ($_SESSION['messages']['error']);
+//   }else{
+//     $messages = drupal_get_messages('status');
+//     // $return['messages'] = $messages;
+//     // drupal_set_message(t("Congratulations, you juste created your free materiO' account, welcome !"), 'status');
+//     foreach ($messages['status'] as $msg) {
+//       drupal_set_message($msg, 'status');
+//     }
+//   }
+//   // after registration user is automaticly logged in, thank's to login tobogan module
+//
+//   drupal_json_output($return);
+// }
+//
+// function materio_personalnotes_login_submit(){
+//   $return = array();
+//   $return['POST'] = $_POST;
+//
+//   $form_state = array("values"=>$_POST);
+//   drupal_form_submit($_POST['form_id'], $form_state);
+//
+//   $return['errors'] = form_get_errors();
+//   if($return['errors'])
+//     unset ($_SESSION['messages']['error']);
+//
+//   // if user-login form succed we retreive the user uid on $form_state, then we can effectively loggin the user
+//   if($uid = $form_state['uid'])
+//     user_login_submit(array(), $form_state);
+//
+//   drupal_json_output($return);
+// }
+//
+//

+ 20 - 12
sites/all/themes/gui/materiobasetheme/templates/node--materiau.tpl.php

@@ -8,6 +8,7 @@
     hide($content['links']);
     hide($content['print_links']);
     hide($content['flaglistslinks']);
+    hide($content['personalnotelink']);
     print render($content);
   ?>
 
@@ -51,24 +52,31 @@
   <nav class="nav">
 
     <?php if ($links = render($content['links'])): ?>
-    <section class="links">
-      <i class="fi-download"></i>
-      <?php print $links; ?>
-    </section>
+      <section class="links">
+        <i class="fi-download"></i>
+        <?php print $links; ?>
+      </section>
     <?php endif; ?>
 
     <?php if ($flags = render($content['flaglistslinks'])): ?>
-    <section class="flags">
-      <i class="fi-folder"></i>
-      <?php print $flags; ?>
-    </section>
+      <section class="flags">
+        <i class="fi-folder"></i>
+        <?php print $flags; ?>
+      </section>
+    <?php endif; ?>
+
+    <?php if ($notelink = render($content['personalnotelink'])): ?>
+      <?php //dsm($content['personalnotelink']); ?>
+      <section class="note">
+        <?php print $notelink; ?>
+      </section>
     <?php endif; ?>
 
     <?php if (FALSE && $print_links = render($content['print_links'])): ?>
-    <section class="print-links">
-      <i class="icon-file"></i>
-      <?php print $print_links; ?>
-    </section>
+      <section class="print-links">
+        <i class="icon-file"></i>
+        <?php print $print_links; ?>
+      </section>
     <?php endif; ?>
 
   </nav>