Search:
Template:MindTouch > ToBeDeveloped > Task/To Do Lists > Template:TaskList3

Template:TaskList3

    Table of contents
    No headers
    /***
        USAGE:
    
        TaskList3()
    
            NOTES:
                * only 1 TaskList can be embedded per page
                * this template requires the DekiAPI script extension
                * this template requires the jQuery script extension
    ***/
    
     // + PARAMETERS
    var par = { 
        srcpath: ($0 ?? args.srcpath ..'/*'),
        showcomplete: String.tolower(String.trim($1 ?? args.showcomplete ?? 'true')),
        ownerstype: String.tolower(String.trim($2 ?? args.ownerstype ?? 'im_user')), /* all, im_user, im_user_or_manager, im_manager */
        ajax_action: String.tolower( __request.args.ajax_action ?? args.ajax_action ?? 'load')
       };
    if ((par.ajax_action=='load') || (par.ajax_action=='reload_tasklist3')) {
    
    
    var ownerstypes = { all: "All", im_user: "User ", im_user_or_manager: "Assingnee o Manager", im_manager: "Manager" };
    var next_ownerstype='all';
    if (par.ownerstype =='all') { let next_ownerstype = 'im_user'; }
    if (par.ownerstype =='im_user') { let next_ownerstype='im_user_or_manager'; }
    if (par.ownerstype =='im_user_or_manager') { let next_ownerstype='im_manager'; }
    if (par.ownerstype =='im_manager') { let next_ownerstype='all'; }
    
     // + CONSTANTS
    var N_COLS='9';
    var PG_STYLE= "background-color: green; width: [pgtext]; text-align: center; color: black;";
    var CTOR_TASK_EDIT = "when(@message.name == 'edit_view')  $('#[edit_col]').hide(); when(@message.name == 'default_view')  $('#[edit_col]').show();";
    var CTOR_TASK_NO_EDIT = "when(@message.name == 'edit_view')  $('#[edit_col]').show(); when(@message.name == 'default_view')  $('#[edit_col]').hide();";
    
    // + VARS
    var today;
    if (Date.IsValid(Date.Now))
        let today = Date.Format(Date.changetimezone(Date.now, user.timezone), "dd/MM/yyyy");
     else
        let today = Date.Format('01/08/2009', 'dd/MM/yyyy');
    
    var TTG = '';
    var API = '';
    var search_criteria = '';
    var tasks = [];
    var assigned_task_pages;
    var taskspage;
    var pgtext_style;
    var pctor;
    var show;
    var i;
    var script;
    var pg;
    var ctask;
    var pages;
    var class = "";
    var title;
    var any = 0;
    var current_page = 0;
    var actual_task_container = 0;
    var skip = 0;
    
    <div id='dipatcher' style='display: none'>
     // TaskList3Dispatcher{ index: __request.args.index, page_api: __request.args.page_api };
      var task_api = __request.args.page_api ?? args.page_api ?? '';
      var task_index = __request.args.index ?? args.index ?? '';
    
      if ((task_index!='') && (task_api!='')) 
       {
        let search_criteria = 'task_'..task_api..'_'..task_index;
        let pages = Wiki.GetSearch(search_criteria);
    
        if (#pages==0) {
          let pg = wiki.GetPage(Num.Int(task_api));
          let tasks = json.parse(pg.properties["tasks"].text ?? "") ?? [];
          let ctask = tasks[task_index];
          let script = 'location.href = "'..Site.Uri..'index.php?title='..pg.Path..'/'..Uri.Encode(ctask.title)..'&action=edit&template=TaskList3Details&index='..task_index..'&page_api='..task_api..'";';
          }
         else
         {
          if (#pages==1) {
              let script = 'location.href = "'..pages[0].uri..'";';
             }
           else
            {  let script = 'location.href = "'..Site.Uri..'/Special:Search?search='..search_criteria..'&type=fulltext";'; }
         } 
        <span id='dispatcher_script' script=(script) style='display: none'></span>
        let skip = 1;
       }
    
    </div>
    
    if (!skip) {
    <div id="deki-tasklist">
    
        // + INPUT FORM
        if (par.ajax_action=='load') { 
           TaskList3Form{ default_date: today, on_reload_func_name: "ToDoWireControls", task_form_id: "tl", parent_args: json.emit(par) }; 
         }
        
        // + VARS
        let search_criteria = '';
        let actual_task_container = Map.Contains(page.tags,'TaskContainer');
    
        if (par.srcpath == '/*')
          { 
           let search_criteria = 'type: wiki AND tag: "TaskContainer"'; 
           if (!actual_task_container) {
             let assigned_task_pages ..= [wiki.getpage(page.path)];
            }
          }
         else
          { 
            let taskspage = args.srcpath;
            let search_criteria = 'type: wiki AND tag: "TaskContainer" AND
                path: ' ..string.replace(par.srcpath, 'User:','User\\:')..' AND NOT (path:
                ' ..string.replace(taskspage, 'User:','User\\:')..')'; 
            if (wiki.pageexists(taskspage)) {  let assigned_task_pages ..= [wiki.getpage(taskspage)]; }
            if ((!actual_task_container) && (taskspage!=page.path)) {
              let assigned_task_pages ..= [wiki.getpage(page.path)];
             }
    
          }
        let assigned_task_pages ..= wiki.getsearch(search_criteria, 1000, 'title');
        let tasks = [];
    
        <div class='filesheader'>
         <div class='filesformlink'><span class='text'>
          web.link(uri.build(page.uri, _,{ownerstype: next_ownerstype, showcomplete: par.showcomplete }),"View tasks by: " .. ownerstypes[par.ownerstype] .. "   ");
          web.html(' | ');
          web.link(uri.build(page.uri, _,{ownerstype: par.ownerstype, showcomplete: (par.showcomplete=='true'?'false':'true') }),"View completed tasks: " .. (par.showcomplete=='true'?"YES":"NO") .. "   ");
         </span></div>
        </div>
    
        <table id="tltasklist" width="100%" class="table" cellspacing="0" cellpadding="0" border="0">
            <colgroup>
                <col />
                <col />
                <col width="50%" />
                <col />
                <col />
                <col />
                <col />
                <col />
                <col />
            </colgroup>
            <tr>
                <th>"Manager/s"</th>
                <th>"Assignee/s"</th>
                <th>"Task"</th>
                <th>"Start Date"</th>
                <th>"Due Date"</th>
                <th>"P"</th>
                <th>"Progress"</th>
                <th>"S"</th>
                <th>String.nbsp</th>
            </tr>
    
        foreach(var t in assigned_task_pages) {
            let i = __count;
            let tasks = json.parse(t.properties["tasks"].text ?? "") ?? [];
            let tasks = [ item .. { index: __index } foreach var item in tasks ];
            let invaliddates = [ item foreach var item in tasks where !date.isvalid(item.enddate) ];
            /* * * FALTA LA MISMA COMPROVACION PARA STARTDATE * *  * */
            let tasks = [ item foreach var item in tasks where date.isvalid(item.enddate) ];
    //        let tasks = list.sort(tasks, _, _, "date.compare($left.enddate, $right.enddate)") .. invaliddates;
            let tasks = list.orderby(tasks,["enddate descending","priority descending","title"]) .. invaliddates;
            let any = 0;
            let current_page = (t.path==page.path);
    
            if ((current_page) && (!any)) {
              <tr><td style='background-color: lightgray' colspan=(N_COLS)>
                <B>"Current Page"</B>
              </td></tr>
              let any = 1;
             }
    
            foreach(var entry in tasks) {
                let show = 'true';
                let class = "";
                if(entry.status=="D") {
                    let show = 'false';            
                }
                else
                  {
                    if(entry.status=="C") {
                        let class..= "completed ";
                        let show = par.showcomplete;
                       }
                    else if(date.isvalid(entry.enddate)&&date.isvalid(today)) {
                       if (entry.progress!='100%') {
                         if(date.issameday(today, entry.enddate)) let class ..= "due-today ";
                          else if (date.isafter(today, entry.enddate)) let class ..= "due-past ";
                        }
                    }
                   }
    
                if ((par.ownerstype != 'all') && (show == 'true' )) {
                  let show = 'false';
                  if (string.contains(string.tolower(entry.username),string.tolower(user.name)) && ( (par.ownerstype=="im_user") || (par.ownerstype == "im_user_or_manager")) )
                      { let show = 'true'; }
                  if (string.contains(string.tolower(entry.manager),string.tolower(user.name)) && ( (par.ownerstype=="im_manager") || (par.ownerstype == "im_user_or_manager")) )
                      { let show = 'true'; }
                 }
    
                if (show=='true') {
                    if (!any) {
                        <tr><td style='background-color: lightgray' colspan=(N_COLS)>
                          <B>web.link(t.uri,t.path);</B>
                        </td></tr>
                        let any = 1;
                    }
    
                    let title = "Created by" .. entry.author;
                    if (entry.progress== '') { let pgtext_style = String.Replace(PG_STYLE,"[pgtext]","0%"); }
                         else { let pgtext_style = String.Replace(PG_STYLE,"[pgtext]",entry.progress); }
                    <tr id=("task_row_"..i.."_"..__count) class=(class) title=(title)>
                        <td><span>String.Replace(entry.manager,'_',' ')</span></td>
                        <td><span>String.Replace(entry.username,'_',' ')</span></td>
                        <td><span>entry.title</span>String.nbsp;String.nbsp;<a href='#' class='texpand'  rel=(entry.index) page_api=(t.id)>"[...]"</a></td>
                        <td align="CENTER"><span>entry.startdate</span></td>
                        <td align="CENTER"><span>entry.enddate</span></td>
                        <td align="CENTER"><span>entry.priority</span></td>
                        <td align="CENTER"><div id="showbar" style="font-size:8pt;padding:2px;border:solid black 1px; width: 60px; text-align: left;">
                                        <div id="progress1" style=(pgtext_style)>(entry.progress)</div>
                                      </div>
                        </td>
                        <td align="CENTER"><span>entry.status</span></td>
                        let pctor = String.Replace(CTOR_TASK_EDIT,'[edit_col]',"edit_col_"..i.."_"..__count);
                        <td class="task-edit" id=("edit_col_"..i.."_"..__count) ctor=(pctor) align="CENTER" >
                            <a href="#" class='tedit' rel=(entry.index) row_index=("task_row_"..i.."_"..__count) page=(t.api) >String.nbsp</a>
                        </td>
                    </tr>
                }
            }
            if ((any) || (current_page)) {
                <tr id=("add_row_"..__count)>
                 <td colspan=(N_COLS) style='height: 30px'>
                     let pctor = String.Replace(CTOR_TASK_EDIT,'[edit_col]','add_button'..__count);
                     <a href="#" class='tedit' id=('add_button'..__count) rel='add_row' row_index=('add_row_'..__count) page=(t.api) ctor=(pctor)>"+ Add new task..."</a>
                     let pctor = String.Replace(CTOR_TASK_NO_EDIT,'[edit_col]','msg_adding'..__count);
                     <div id=('msg_adding'..__count) style='display: none' ctor=(pctor)><B>"Task Details:"</B></div>
                 </td>
                </tr>
            }
          }
        </table>
    </div>
    
    if (par.ajax_action=='load') { 
    
    if (!actual_task_container) {
     <div style='background-color: rgb(201,255,211);'>
      "Note:If you want these tasks to be managed globally add the tag 'Task Container'. After adding the tag it may take a while before the tasks appear."
     </div>
    }
    // global script code
    <script type="text/jem">"
    function ToDoWireControls() {
        Deki.$('#tltasklist a.tedit').bind('click', function() {
            tlEditTask({ index: Deki.$(this).attr('rel'), row_index: Deki.$(this).attr('row_index'), page: Deki.$(this).attr('page') }, function() {@message({ name: 'default_view' })}); 
            @message({ name: 'edit_view' }); 
            return false;
        });
    
        Deki.$('#tltasklist a.texpand').bind('click', function() {
            MindTouch.Deki.Reload(#dipatcher, { page_api: Deki.$(this).attr('page_api'), index: Deki.$(this).attr('rel') }, function() { eval(Deki.$('#dispatcher_script').attr('script')); });
            return false;
        });
    }
    ToDoWireControls();
    "</script>
    
    // styles
    <html>
        <head>
            <style type="text/css">"
    //--- Start TASKLIST styles ---
    #deki-tasklist {
    	margin: 0;
    	padding: 4px; 
    	width: 98%;
    }
    #deki-tasklist table {
    	width: 100%; 
    	margin: 0;
    }
    #deki-tasklist table td {
    	border-bottom: 1px solid #000;
    	padding: 4px 2px;
    }
    #deki-tasklist tr td.task-edit {
    	text-align: right;
    	padding-right: 8px;
    }
    #deki-tasklist tr.due-today td {
    	background-color: #ff0; 	
    }
    #deki-tasklist tr.completed td {
    	background-color: #fff;
    }
    #deki-tasklist tr.completed td span {
    	text-decoration: line-through;
    }
    #deki-tasklist tr.due-past td, 
    #deki-tasklist tr.due-past td.task-edit a {
    	color: #f00;	
    }
    #deki-tasklist table th {
    	font-size: 12px;
    	font-weight: bold;
    	text-align: left;
    	border-bottom: 2px solid #000;
    }
    
    #deki-tasklist div.task-submit {
    	float: right; 
    	padding-right: 0px;
    }
    #deki-tasklist div.task-submit input {
    	margin-right: 4px;
    }
    #deki-tasklist table tr td.task-edit a {
    	background: url(/skins/common/icons/silk/page_white_edit.png) no-repeat center left;
    	color: #000;
    	text-decoration: none;
    	padding: 3px 3px 3px 21px;
    	font-size: 11px;
    }
    
    TABLE.submitform td.label {
        border-bottom : #aaa 1px solid;
        text-aligin : right;
        padding-bottom : 6px;
        padding-left : 8px;
        padding-right: 8px;
        font-family: Verdana, Arial, Helvetica, sans-serif;
        white-space : nowrap;
        background : url(bg-tbl-header.gif) #d9d9d9 no-repeat;
        color : #4f6b72;
        font-size : 12px;
        border-top : #aaa 1px solid;
        font-weight: bold;
        border-right: #aaa 1px solid;
        padding-top: 6px;
    }
    
    //--- End TASKLIST styles ---
    "
            </style>
        </head>
    </html>
      }
     }
    
    }
    

    Files (0)

     

    Comments (0)

    You must login to post a comment.